Single Sign-On (SSO)
Seamlessly authenticate and identify your customers.
Single sign-on helps you to seamlessly authenticate your users via their existing accounts on your application. This provides an endearing experience for your users by eliminating the need to log in to leave feedback.
In this guide, we'll give you a detailed guide on how you can authenticate and identify your existing customers on UserVitals.

A quick overview of how it works

Enable SSO to connect with existing user accounts in your app
Store your private key on your server and don't share it
    On your server, generate an SSO token for your authenticated user. Ideally, you want to do this on every page your SSO token is used.
    Setup a redirect URL with the JWT token and hyperlink it to your button or link.
    When the user visits the link, we will decode the token and authenticate the user.

Setup

1. Install a JWT library
Node.JS
Go
PHP
Python
Ruby
1
npm install --save jsonwebtoken
Copied!
1
go get github.com/dgrijalva/jwt-go
Copied!
1
composer require firebase/php-jwt
Copied!
1
pip install PyJWT
Copied!
1
sudo gem install jwt
Copied!
2. Generate a JWT token for your customer
Node.JS
Go
PHP
Python
Ruby
1
const jwt = require('jsonwebtoken');
2
3
const PRIVATE_KEY = 'Your Private Key';
4
5
function createJWT(user) {
6
const data = {
7
// User's email address (required)
8
email: user.email,
9
// User's display name (required)
10
name: user.name,
11
}
12
13
return jwt.sign(data, PRIVATE_KEY, { algorithm: 'HS256' });
14
}
Copied!
1
import (
2
"github.com/dgrijalva/jwt-go"
3
)
4
5
const PrivateKey = 'Your Private Key';
6
7
func createJWT(user map[string]interface{}) (string, error) {
8
token := jwt.NewWithClaims(jwt.SigningMethodHS256, jwt.MapClaims{
9
"email": user["email"],
10
"name": user["name"],
11
})
12
return token.SignedString([]byte(PrivateKey));
13
}
Copied!
1
use \Firebase\JWT\JWT;
2
3
const PrivateKey = 'Your Private Key';
4
5
function createJWT($user) {
6
$userData = [
7
'email' => $user['email'],
8
'name' => $user['name'],
9
];
10
return JWT::encode($userData, PrivateKey, 'HS256');
11
}
Copied!
1
import jwt
2
3
private_key = 'Your Private Key'
4
5
def createJWT(user):
6
user_data = {
7
'email': user.email,
8
'name': user.name,
9
}
10
return jwt.encode(user_data, private_key, algorithm='HS256')
Copied!
1
require 'jwt'
2
3
PrivateKey = 'Your Private Key'
4
5
def createJWT(user)
6
userData = {
7
email: user.email,
8
name: user.name
9
}
10
11
JWT.encode(userData, PrivateKey, 'HS256')
12
end
Copied!
3. Setup a feedback portal URL
Include a UserVitals roadmap link directly in your application
When an SSO token has been generated for the user, redirect them back to UserVitals, or link this URL to a button to take the user to the feedback portal.
1
https://api.uservitalshq.com/sso?token=${ssoToken}&subdomain=${subdomain}&redirect=${portalUrl}
Copied!

Query Params to include

The token query param included in the URL should hold the generated SSO Token. (required)
The subdomain query param should hold your team's subdomain. (required)
The redirect query param holds the URL where the user needs to be sent back to after successful login. (optional)
Last modified 4mo ago