Articles on: Miscellaneous stuff

How to Manage Leanbe's Single Sign-On (SSO) Feature

Single Sign-On (SSO) is an identification method that allows users to access multiple applications and websites with just one set of login credentials.

Leanbe's Single Sign-On (SSO) feature streamlines the process of user identification, allowing your customers to upvote, comment, or create a feature request without needing to go through additional email verification steps.
By integrating SSO, Leanbe communicates with your server to determine if a user is already registered, and if so, automatically identifies them.

The tutorial will show how to execute the SSO method with Leanbe.

Steps to implement the SSO method with Leanbe



Provide a URL for Leanbe to redirect users to, where they can either log in or sign up. If the user is already logged in, simply redirect them back to the provided redirect URL as can be seen from point 2.

Leanbe will send a request to your provided URL, appending a `redirectUrl` parameter.

For example, if your URL is `https://example.com/sso`, Leanbe will call `https://example.com/sso?redirectUrl=https://app.leanbe.ai/backend/api/v1/sso/fallback/productSlug/`.

To implement SSO, you'll need to:

Create a JSON Web Token (JWT) containing the user's `email` and `name`.
Sign the JWT with Leanbe's provided `SSO Token` to ensure the request originates from your server.
Make an HTTP GET request to the `redirectUrl` with the created token attached.



An example of the request can be found below:

HTTP GET


https://app.leanbe.ai/backend/api/v1/sso/fallback/productSlug/eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c




Leanbe will validate the request, and if everything checks out, the user will be granted access to upvote, comment, or create a feature request without any need to login to the Leanbe system again.


Below you can find a code example for Node.js:

import jwt from 'jsonwebtoken';

const leanbeSSOToken = 'LeanbeSSOToken'; // From Products -> SSO -> SSO Token
const user = {
  email: 'joe@gmail.com',
  name: 'Joe Doe',
};

const generatedJwtToken = jwt.sign(user, leanbeSSOToken, { algorithm: 'HS256' });


For other programming languages, you can use an equivalent JWT library to create and sign the token with Leanbe's SSO Token.

Here are some examples of popular languages:

Python



import jwt;


leanbe_sso_token = 'LeanbeSSOToken'  # From Products -> SSO -> SSO Token
user = {
    'email': 'joe@gmail.com',
    'name': 'Joe Doe',
}

generated_jwt_token = jwt.encode(user, leanbe_sso_token, algorithm='HS256')


Ruby


require 'jwt'

leanbe_sso_token = 'LeanbeSSOToken'  # From Products -> SSO -> SSO Token
user = {
    'email': 'joe@gmail.com',
    'name': 'Joe Doe',
}

generated_jwt_token = JWT.encode(user, leanbe_sso_token, 'HS256')


PHP


<?php

require 'vendor/autoload.php';

use \Firebase\JWT\JWT;

$leanbe_sso_token = 'LeanbeSSOToken'; // From Products -> SSO -> SSO Token
$user = [
'email' => 'joe@gmail.com',
'name' => 'Joe Doe',
];
$generated_jwt_token = JWT::encode($user, $leanbe_sso_token, 'HS256');




By following these examples, you can implement Leanbe's SSO feature in your preferred programming language. Once the JWT token is generated, signed, and sent to the `redirectUrl` provided by Leanbe, your users will be able to seamlessly interact with your platform, making it easier for them to upvote, comment, and submit feature requests.

That's it! Those were the steps on how to manage Leanbe's SSO feature.

Updated on: 17/05/2023

Was this article helpful?

Share your feedback

Cancel

Thank you!