Options for using OAuth 2.0
Vanilla currently provides tailored OAuth 2.0 integrations with these third-party identity providers as ready-to-go addons:
- Facebook
- Twitter
- LinkedIn
- Google+
We also provide a generic OAuth2 addon that works with basic implementations, including support for the third-party service Auth0.
Because OAuth 2.0 is an SSO framework and not a narrowly defined protocol (see OAuth 2.0 Spec), custom services work is occassionally required to set up an OAuth solution tailored to your forum. Our generic OAuth2 addon is highly extensible to be able to render these services quickly and efficiently.
If you do not currently have an OAuth 2.0 identity provider, we strongly recommend using a third-party provider in place of creating a new one before launching your forum.
Vanilla supports the authorization code grant workflow. You will not be able to use the implicit grant flow without creating a custom plugin. To know more about the difference between these two methods for OAuth 2.0 please read this article.
Using the OAuth2 Addon in Vanilla
As with all our SSO solutions, OAuth2 accounts are mapped to existing forum accounts by email address, or a new account is created if no match is found. You may combine it with any other SSO connections.
A settings form in the dashboard allows you to define custom parameter names for:
- Client id
- Client secret
- Full path to the:
- authorization URI,
- registration URI,
- sign out URI,
- token endpoint, and
- profile endpoint
- Expected keys in the JSON response to the profile request
- Scope
Mapping User Profile Values
The Profile endpoint, or user-info endpoint is expected to return a JSON encoded array of the user's data. See this document for the expectations. The Profile URL field is required in the OAuth2 Addon. We do not support getting user data from an IDToken.
The OAuth2 workflow sends the user's profile data as a set of key/value pairs in a JSON object. If those key names do not correspond to Vanilla's you will need to map the key names in the OAuth2 Addon Settings form. For exemple, if your authentication provider sends the user's profile like this:
{
"address": "dave@email.com",
"pic": "https://cdn.aws.com/ourcdn/davesprofilepic.gif",
"name": "Dave",
"fullname": "Dave Johnson",
"id": 1828838378
}
You will need to configure the dashboard accordingly:
The OAuth2 plugin even supports multi-dimensional responses. If your authentication provider's user profile response looks like this:
{
"address": "dave@email.com",
"pictures": {
"preferred": "https://cdn.aws.com/ourcdn/davesprofilepic.gif"
},
"name": "Dave",
"fullname": "Dave Johnson",
"id": 1828838378
}
you can map it by using dot-notation:
Passing Roles over OAuth2
You can pass a user's role in the profile response. Unlike the values shown above, there is no user interface for mapping the key name for roles in the dashboard -- yet. For now, if you want to pass a user's role and have it applied as a role on the forum it must be passed as "Roles" (capital R, plural "Roles). The value can be a comma separated list of roles. In order for it to work it must correspond exactly with name of a role or roles configured on your forum.
{
"address": "dave@email.com",
"pic": "https://cdn.aws.com/ourcdn/davesprofilepic.gif",
"name": "Dave",
"fullname": "Dave Johnson",
"id": 1828838378,
"Roles": "Moderator, Chearleader"
}
will assign these two roles to this user.
"Allow this connection to issue API access tokens."
In order to allow Vanilla to access a user's profile data from your authentication provider you have a sent a short-lived access token to Vanilla. You can also use your access token to generate a Vanilla access token for the user so that you can make API calls on behalf of this user against Vanilla. Just toggle on "Allow this connection to issue API access tokens." Here is how it works:
After generating an access token on your Token endpoint (e.g. /oauth/token
) and passing it to Vanilla, use it to POST
to our api/v2/tokens/oauth
with your unique ClientID to receive an access token that you can now use to perform any actions that the user can.
A call to:
curl --location --request POST 'https://dev.vanilla.localhost/api/v2/tokens/oauth' \
--header 'Content-Type: text/plain' \
--data-raw '{
"clientID" : "402d75e6-82a7-4d84-a0b5-e5298e97cacc"
"oauthAccessToken" : "Ii6JWFSeGgxIkXk3UIU3HWCGejW6nUZn"
}'
Will return:
{
"accessToken": "va.kVH976QqVV9WgI_59HDSj2ffKUBuuLxT.SRsKXw.Ut_vRgN",
"dateExpires": "2020-07-11T20:04:25+00:00"
}
Take note of when this token expires and have a strategy to renew it. For more information, so the API v2 / tokens section in your dashboard.
"Make this connection your default signin method."
Checking the "Make this connection your default signin method." checkbox in the Settings form will make this the only way to log into your forum or create new users. This will mean that:
- When you click on the default "Sign In" button it will redirect you to your authentication provider to log in.
- The "Username and Password" or "Registration" forms on the forum will no longer be accessible to users.
- Users will not be able to edit their profiles on the forum.
- You will be able to redirect users to a configured end-point after they log out.
If you have created a user natively on the forum before setting OAuth2 as the default method for connecting and need to log in using the "Username and Password" form to log in you can always access it by typing `/entry/password` in the address bar of your browser. Also, when you try to connect over SSO, and the system detects that you have user with the same email address on the forum, you will be asked to enter the password you created when you created the user on the forum. If this becomes problematic, talk to your Customer Success Manager.
Logging out
You can configure a URL where you would like to redirect a user when he/she logs out of your forum, only if you have checked "Make this connection your default signin method." in the dashboard. This URL can be an end-point on your authentication provider that will then log them out of the "parent" system. If you choose to not log them out of the authentication provider and the user navigates back to the forum and clicks on "Sign In" he/she will be automatically logged into the forum without having to enter a username and password.
If you wish to redirect the user back to the forum after logging him/her out, append the Sign Out URL with (literally) ?Target={target}
and our system will URL encode the URL of the forum and pass it in the Sign Out request on your system as Target
.
For more log out use cases please read this article.
Troubleshooting your OAuth2 Setup
You might not be sure what data you are sending or how it is formatted. Ask your Customer Success Manager to turn on logging. Then you can click on the Event Log link in the left-hand menu to see the logs. Filter on "Event Name" sso_logging, scroll down to the bottom of the page to view the filtered logs in either JSON or XML format. Search for "RawProfile" to see what key/value pairs you are sending and compare them to "Profile", what they are being translated to. There will also be helpful error messages here as well.
Setting up your OAuth2 Provider
With most SSO providers, you will have two additional requirements:
- Your forum must be accessed over
https
by users. - Your forum must contact your Authorization Server using
https
. - Your Authorization Server will need to whitelist the redirect URI (e.g.
https://[forum-domain].com/entry/oauth2
) - Your Authorization Server MUST receive and return the state token in tact that is passed to it from the forum in the authorization request. This is an OAuth2 requirement and a security feature.
Seemless Connection from Your App to Vanilla
If you have users logged into your web application and you want to provide a link from your application to your Vanilla application without prompting them to login again, do the following:
- In the Vanilla Dashboard, under Settings>Addons>OAuth2, set the Prompt dropdown to either "Consent" or "none".
- In your application, the link you provide from your application to the Vanilla application should be "https://[your-vanilla-app]/entry/oauth2-redirect". This will automatically redirect users back to your application with the "consent" or "none" message telling your application that if the user is already logged in only stop them if they have not given consent to share data this Vanilla (a step that will happen only the first time they connect). If the user does not exist on Vanilla the user will be created and will be logged in.
Automating OAuth2 connections with Javascript
This section details how a developer on your team could use Javascript to automatically forward a user through the OAuth2 SSO process, creating a more seamless experience. It is not required for any service, nor is it generally recommended (it will generate significantly increased traffic against your identity provider). We do not provide this as a service.
The following instructions will determine if the user is currently signed into their authentication provider and, if the user is indeed signed in, automatically initiate a SSO login into Vanilla using that authentication provider.
Create a connection in Javascript
First, make a standard HTTPS GET request to the authentication provider’s authorize endpoint. If you’re using Auth0, this is usually something like https://[eauth-domain].com/authorize
. Use the following parameters:
response_type: code
client_id:ABCDEFG
(found in the provider’s application settings)redirect_uri: https://[forum-domain]/entry/oauth2
(required to initiate SSO on Vanilla’s side)scope: openid profile email
(can be configured in the OAuth2 settings page in Vanilla)
The result is a URL which, when visited by a user signed in on the authentication provider, will route the user back to Vanilla to begin SSO authentication. If the user already has an account, they can automatically connect or can automatically create a new account. They will be signed into Vanilla at the end of the request chain. The URL will look something like this: https://[auth-domain].com/authorize?response_type=code&client_idABCDEFG&redirect_uri=https%3A%2F%2Fc[forum-domain].com%2Fentry%2Foauth2&scope=openid+profile+email
Test the connection
- Sign in at
https://[auth-domain].com
(your actual SSO sign in page) - Visit
https://[forum-domain].com
. Make sure you are not logged in. Clear your cookies, if necessary. - Visit the “authorize” link described above.
- You should automatically arrive back at
https://[forum-domain].com
, but you should now be signed into Vanilla.
In Vanilla, this can be implemented as Javascript in your page via the Customize Theme feature or a Pocket. Contact support if you need clarification on these steps.