If your customers already have user accounts in your application, then you can enable Single Sign-On (SSO) to automatically log in your customers to LoopedIn as well.
In order to implement SSO, we use JSON Web Tokens (JWT) to securely exchange user information. You will need to generate a JWT on your server, passing in the user credentials required in order to identify your customers.
User Flow
When SSO has been enabled, the following user flow is observed:
1. Unauthenticated users will be prompted to log in when they attempt to vote, comment or submit content
2. Upon clicking "Log in", they will be redirected to your website, where they can sign up or login
3. Your website will generate an SSO JWT, and return this to LoopedIn (note: when directing the user to your log in page, we provide a `returnURL` parameter, which should be used when returning the user back to LoopedIn)
4. LoopedIn will process the provided JWT, and identify the user
5. The user will now be authenticated and can vote, comment or submit content
SSO Setup
2. Create a page on your application to generate the SSO JWT (must be a JWT create using the HS256 algorithm)
3. Use your SSO Key to generate a valid SSO JWT
5. Click "Test URL" - this will make a call to the URL provided, and check for a valid response
6. If a valid response is received, then the "Enable SSO" toggle will become available for you to switch on
NodeJs Example
1. Install a JWT library, such as `jsonwebtoken`
npm install jsonwebtoken
2. Create SSO token and redirect to LoopedIn
-
const jwt = require('jsonwebtoken');
-
const ssoToken = 'YOUR_SSO_KEY';
-
const userData = {
-
email: user.email,
-
name: user.name
-
}
-
const userToken = jwt.sign(userData, ssoToken, {algorithm: 'HS256'});
-
const ssoRedirect = req.query.returnURL;
-
return res.redirect(`${ssoRedirect}?token=${userToken}`);
Note: when directing the user to your log in page, we provide a `returnURL` parameter, which should be used when returning the user back to LoopedIn, as seen above.