Discourse v0.0.1 Discourse.SSO View Source
kDiscourse SSO.
Reference: https://meta.discourse.org/t/official-single-sign-on-for-discourse-sso/13045
Link to this section Summary
Functions
Sign the nonce and user data
Creates a signed url to redirect users to
Verify the passed sso nonce and signature
Link to this section Functions
sign(id, email, nonce, opts \\ []) View Source
Sign the nonce and user data.
The following user data is required:
id
, the id of the user in your system.email
, the email of the user. (Assumed to be verified.)nonce
, the nonce given at the start of the request.
Secret
The secret
set for Discourse is taken from the application configurations,
but can also be supplied as option.
The passed secret
takes priority over the configured one.
Options
The following extra user data can be given:
username
, the user's [preferred] username.name
, the user's [real] name.
Flags (boolean)
admin
, set the user as admin.avatar_force_update
, force avatar update.locale_force_update
, force locale update.moderator
, set the user as moderator.require_activation
, require email verification.suppress_welcome_message
, suppress Discourse welcome message.
Example
iex> SSO.sign(323211321, "bob@example.com", "cb68251eefb5211e58c00ff1395f0c0b")
%{
sig: "4ba1737d622155848ddb9a22f6ccb61801cb1ad40544aef5304caa300655f6b2",
sso: "bm9uY2U9Y2I2ODI1MWVlZmI1MjExZTU4YzAwZmYxMzk1ZjBjMGImZW1haWw9Ym9iJTQwZXhhbXBsZS5jb20mZXh0ZXJuYWxfaWQ9MzIzMjExMzIx"
}
sign_url(id, email, nonce, opts \\ []) View Source
Creates a signed url to redirect users to.
The following user data is required:
id
, the id of the user in your system.email
, the email of the user. (Assumed to be verified.)nonce
, the nonce given at the start of the request.
For more options see: sign/4
.
URL
The url
set for Discourse is taken from the application configurations,
but can also be supplied as option.
The passed url
takes priority over the configured one.
Example
iex> SSO.sign_url(323211321, "bob@example.com", "cb68251eefb5211e58c00ff1395f0c0b")
"http://discuss.example.com?sig=4ba1737d622155848ddb9a22f6ccb61801cb1ad40544aef5304caa300655f6b2&sso=bm9uY2U9Y2I2ODI1MWVlZmI1MjExZTU4YzAwZmYxMzk1ZjBjMGImZW1haWw9Ym9iJTQwZXhhbXBsZS5jb20mZXh0ZXJuYWxfaWQ9MzIzMjExMzIx"
validate(sso, sig, opts \\ []) View Source
Verify the passed sso nonce and signature.
The secret
set for Discourse is taken from the application configurations,
but can also be supplied as option.
The passed secret
takes priority over the configured one.
Example
iex> SSO.validate("bm9uY2U9Y2I2ODI1MWVlZmI1MjExZTU4YzAwZmYxMzk1ZjBjMGI=\n", "2828aa29899722b35a2f191d34ef9b3ce695e0e6eeec47deb46d588d70c7cb56")
{:ok, "cb68251eefb5211e58c00ff1395f0c0b"}