-
Notifications
You must be signed in to change notification settings - Fork 33
Authenticate a user for the portal using Google and a constraint
The first thing to do with any social provider implementation is to make sure the OAuth client has been set up with the provider, and that the OAuth client has been set up with the correct callback URI.
Step 1 Set up an OAuth client with google apps
- Go to the Google Developer Console and create a new app
- Register a new OAuth client, lets call it WebApp 1 (Select "New Credentials -> OAuth Client ID")
- Select Web App
- Add the following URL (mnodified for your domain) to the "Authorized redirect URIs" section:
http://tib-hostname:TIB-PORT/auth/{PROFILE-ID}/gplus/callback
Save the client and take note of the secret and ID.
We created a new OAuth client in Google apps that has a registered call back URL for TIB, the callback is very important, as this is how Google will tell TIB about the user logging in, the callback URI is constructed as follows:
http://{TIB-HOST}:{TIB-PORT}/auth/{PROFILE-ID}/{PROVIDER-CODE}/callback
If you were to use twitter with a profile ID of 15, you would have a callback for twitter that look slike this:
http://{TIB-HOST}:{TIB-PORT}/auth/15/twitter/callback
Step 2 Create a profile object in profiles.json:
[{
"ActionType": "GenerateOrLoginDeveloperProfile",
"ID": "1",
"IdentityHandlerConfig": {
"DashboardCredential": "YOUR-DASHBOARD-USER-API-KEY"
},
"OrgID": "YOUR-ORG-ID",
"ProviderConfig": {
"CallbackBaseURL": "http://{TIB-HOST}:{TIB-PORT}",
"FailureRedirect": "http://{PORTAL-DOMAIN}:{PORTAL-PORT}/portal/login/",
"UseProviders": [{
"Name": "gplus",
"Key": "GOOGLE-OAUTH-CLIENT-KEY",
"Secret": "GOOGLE-OAUTH-CLIENT-SECRET"
}]
},
"ProviderConstraints": {
"Domain": "yourdomain.com",
"Group": ""
},
"ProviderName": "SocialProvider",
"ReturnURL": "http://{PORTAL-DOMAIN}:{PORTAL-PORT}/portal/sso/",
"Type": "redirect"
}]
This profile basically tells TIB to load a profile into memory with the ID of 1, that it should login or generate a developer profile via Google Plus, and it should only allow users from yourdomain.com
domain-based email accounts.
The Return URL here is important, and is only provided in the latest version of Tyk Dashboard, as it makes use of new API endpoints to generate the SSO tokens required to allow remote access.
If your portal is configured undder a differen root (e.g. /
, then replace the `/portal' component of the URLs with that of your actual portal.)
Step 3 - Make a request to your TIB endpoint in your browser
Now, start TIB by entering:
./tyk-auth-proxy
And then point your browser at:
http://{TIB-HOST}:{TIB-PORT}/auth/1/gplus
You will be asked to log into your account (make sure it is one that satisfies the constraints!), and once logged in, you should be redirected back via the TIB proxy to your portal, as a logged in user.
This user will be created with some user profile data, the user can edit and change their email address, but continue to log in with the same Google account (this data is stored seperately).