Scalekit is your gateway to enterprise-readiness for B2B and SaaS applications. Built on OpenID and SAML standards, it provides seamless authentication, user management, and access control capabilities. Scalekit enables you to focus on core product development while we handle the complexities of enterprise authentication.
Scalekit's Node.js SDK requires Node.js version 18.x or later to run. To install or upgrade Node.js, refer to the official Node.js installation guide. To start setting up, go to your Node project's root directory and run following command:
npm install @scalekit-sdk/node
Other package managers like Yarn and pnpm are also supported.
yarn add @scalekit-sdk/node
pnpm add @scalekit-sdk/node
bun add @scalekit-sdk/node
Scalekit SDK establishes an enterprise-ready authentication server that can be set up for an application by providing API credentials (Currently, Early Access) during SDK initialization.
import { ScalekitClient } from '@scalekit-sdk/node';
const scalekit = new ScalekitClient(
process.env.SCALEKIT_ENV_URL,
process.env.SCALEKIT_CLIENT_ID,
process.env.SCALEKIT_CLIENT_SECRET
);
/**
* Import ScalekitClient as scalekit
* Create an Express app instance
*/
const redirectUri = `${process.env.HOST}/auth/callback`;
app.get("/auth/login", (req, res) => {
const authUrl = scalekit.getAuthorizationUrl(
redirectUri,
{
state: "state",
connectionId: "connection_id",
}
);
res.redirect(authUrl);
});
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 scalekit.getIdpInitiatedLoginClaims(idp_initiated_login as string);
// Get the authorization URL and redirect the user to the IdP login page
const url = scalekit.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);
});
Return Type: string
Returns the authorization URL and redirect the user to the IdP login page
https://auth.scalekit.com/authorize
?client_id=skc_1220XXXXX349527
&redirect_uri=https://yourapp.com/auth/callback
&provider=google
redirectUri
Type: string
The URL to redirect the user to after the user has logged in. For example, https://b2b-app.com/auth/callback
.
options
Type: object
Any one of the following identifiers can be used to generate the Authorization URL:
connectionId
- The connection ID to use for the login. For example,conn_1220XXXXX349527
.organizationId
- The organization ID to use for the login. For example,org_1220XXXXX349527
.loginHint
- The login hint to use for the login. For example,user@example.com
.
Read more about Authorization URL
Return Type: object
Returns an object containing user profile details (idToken
in JSON Web Token format) along with access token.
code
Type: string
The code sent to the redirect URL (/auth/callback
) in it's redirect query parameter.
redirectUri
Type: string
The URL to redirect the user to after the user has logged in. For example, https://b2b-app.com/auth/callback
.
Return Type: object
Returns the identifiers needed to generate the authorization URL when users login using their Identity Provider (IdP). (a.k.a. IdP initiated login)
idpInitiatedLoginToken
Type: string
(JSON Web Token format)
The value of idp_initiated_login
query parameter from the redirect URL.
For detailed information on each option and parameter, please refer to our API Reference 📚.
Scan through the examples for Express.js and Next.js.
# Clone Express.js example
git clone https://github.com/scalekit-inc/scalekit-express-example.git
# Clone Next.js example
git clone https://github.com/scalekit-inc/scalekit-nextjs-example.git
Thank you for considering contributing to the Scalekit SDK!
- Feel free to open an issue or submit a pull request.
- Become a stargazer of this repository.
- Write a blog post of what you built with Scalekit.
This project is licensed under the MIT License - see the LICENSE file for details.
Made with ❤️ by the Scalekit team