Scalekit is an Enterprise Authentication Platform purpose built for B2B applications. This Node.js SDK helps implement Enterprise Capabilities like Single Sign-on via SAML or OIDC in your Node.js applications within a few hours.
- Sign up for a Scalekit account.
- Get your
env_url
,client_id
andclient_secret
from the Scalekit dashboard.
Install Scalekit SDK using your preferred package manager.
npm install @scalekit-sdk/node
#or
yarn add @scalekit-sdk/node
#or
pnpm add @scalekit-sdk/node
Initialize the Scalekit client using the appropriate credentials. Refer code sample below.
import { ScalekitClient } from "@scalekit-sdk/node";
const scalekitClient = new ScalekitClient(
process.env.SCALEKIT_ENV_URL!,
process.env.SCALEKIT_CLIENT_ID!,
process.env.SCALEKIT_CLIENT_SECRET!
);
// Use the sc object to interact with the Scalekit API
const authUrl = scalekitClient.getAuthorizationUrl("https://acme-corp.com/redirect-uri", {
state: "state",
connectionId: "connection_id",
});
Below is a simple code sample that showcases how to implement Single Sign-on using Scalekit SDK
import express from "express";
import { ScalekitClient } from "@scalekit-sdk/node";
const app = express();
const sc = new ScalekitClient(
process.env.SCALEKIT_ENV_URL!,
process.env.SCALEKIT_CLIENT_ID!,
process.env.SCALEKIT_CLIENT_SECRET!
);
const redirectUri = `${process.env.HOST}/auth/callback`;
// Get the authorization URL and redirect the user to the IdP login page
app.get("/auth/login", (req, res) => {
const authUrl = scalekitClient.getAuthorizationUrl(
redirectUri,
{
state: "state",
connectionId: "connection_id",
}
);
res.redirect(authUrl);
});
// Handle the callback from Scalekit
app.get("/auth/callback", async (req, res) => {
const { code, error, error_description, idp_initiated_login } = req.query;
// Handle error
if (error) {
return res.status(400).json({ error, error_description });
}
// Handle IdP initiated login
if (idp_initiated_login) {
// Get the claims from the IdP initiated login
const {
connection_id,
organization_id,
login_hint,
relay_state
} = await scalekitClient.getIdpInitiatedLoginClaims(idp_initiated_login as string);
// Get the authorization URL and redirect the user to the IdP login page
const url = scalekitClient.getAuthorizationUrl(
redirectUri,
{
connectionId: connection_id,
organizationId: organization_id,
loginHint: login_hint,
...(relay_state && { state: relay_state }),
}
)
return res.redirect(url);
}
const authResp = await scalekitClient.authenticateWithCode(code, redirectUri);
res.cookie("access_token", authResp.accessToken);
return res.json(authResp.accessToken);
});
app.listen(3000, () => {
console.log("Server is running on port 3000");
});
Fully functional sample applications written using some popular web application frameworks and Scalekit SDK. Feel free to clone the repo and run them locally.
Refer to our API reference docs for detailed information about all our API endpoints and their usage.
- Quickstart Guide to implement Single Sign-on in your application: SSO Quickstart Guide
- Understand Single Sign-on basics: SSO Basics
This project is licensed under the MIT license. See the LICENSE file for more information.