Learn how to create and sign a JWT for Single Sign-On in Featurebase.
Written By Bruno from Featurebase
Last updated About 1 month ago
👨💻 You'll need to write custom code for the setup process. If you're uncomfortable with this, share this guide with a technical team member who can assist.
To create and sign a JWT for Single Sign-On:
Start by getting your private key from Dashboard → Settings → SSO → Get JWT Secret. Store it on your server and make sure not to share it with anyone!
On your server, generate a JWT token with your customer data using the example below.
Install required packages
Examplenpm install --save jsonwebtoken
Generate the JWT token
For safety, Single Sign-On tokens can't log in users who are admins of any Featurebase organization. These users will have to sign in by themselves.
Exampleconst jwt = require("jsonwebtoken");
const SSO_KEY = "JWT_SECRET";
function generateJWTToken(user) {
const userData = {
email: user.email,
name: user.name,
userId: user.id,
// Optional fields
profilePicture: "https://example.com/images/yourcustomer.png",
// Optional fields
customFields: {
title: "Product Manager",
plan: "Premium",
number: "123",
},
// Optional, uncomment if you are looking to use multilingual changelog
// locale: "en", // Will make sure the user receives the changelog email in the correct language
// Optional fields
companies: [
{
id: "987654321", // required
name: "Business Inc. 23", // required
monthlySpend: 500, // optional
createdAt: "2023-05-19T15:35:49.915Z", // optional
customFields: {
industry: "Fintech",
location: "Canada",
}, // optional
},
],
// role: "", // optional - used for user roles feature with enterprise plan
};
return jwt.sign(userData, SSO_KEY, {
algorithm: "HS256",
});
}
Make sure you replace JWT_SECRET
with the secret for your organization.
Now go to Dashboard → Settings → SSO and validate your JWT. This will tell you if you’ve done everything correctly.
That’s it! If you need help with setting this up feel free to reach out to us in the live chat.