Skip to content
Scalekit Docs
Talk to an EngineerDashboard

Create client

Create the SDK client and run core auth helpers

Create a ScalekitClient with your environment URL, client ID, and client secret. All other clients hang off this instance.

Store credentials in environment variables. Never hard-code secrets. After you create the client, use Sessions to validate tokens or open a domain client such as Organizations or Users.

classScalekitClienthttps://github.com/scalekit-inc/scalekit-sdk-node/blob/main/src/scalekit.ts
#asyncvalidateAccessToken

Validates the access token and returns a boolean result.

paramtokenstring

The token to be validated.

paramoptionsTokenValidationOptions

Optional request settings.

returnsboolean

Returns true if the token is valid, false otherwise.

const isValid = await scalekit.validateAccessToken(accessToken);
classScalekitClienthttps://github.com/scalekit-inc/scalekit-sdk-node/blob/main/src/scalekit.ts
#asyncgenerateClientToken

Generates an M2M access token using the client credentials grant for the given clientId and clientSecret.

paramclientIdstring

The client ID to authenticate with

paramclientSecretstring

The client secret to authenticate with

returnsstring

The access token string

classScalekitClienthttps://github.com/scalekit-inc/scalekit-sdk-node/blob/main/src/scalekit.ts
#asyncauthenticateWithCode

Exchanges an authorization code for access tokens and user information.

paramcodestring

The authorization code received in the callback URL after.

paramredirectUristring

The same redirect URI used in getAuthorizationUrl().

paramoptionsAuthenticationOptions

Optional request settings.

returnsAuthenticationResponse

Tokens and user claims.

app.get('/auth/callback', async (req, res) => {
const { code } = req.query;
const result = await scalekit.authenticateWithCode(
code,
'https://yourapp.com/auth/callback'
);
req.session.accessToken = result.accessToken;
req.session.user = result.user;
res.redirect('/dashboard');
});
classScalekitClienthttps://github.com/scalekit-inc/scalekit-sdk-node/blob/main/src/scalekit.ts
#asyncgetIdpInitiatedLoginClaims

Extracts and validates claims from an IdP-initiated login token.

paramidpInitiatedLoginTokenstring

The token received in the ‘idp_initiated_login’ query.

paramoptionsTokenValidationOptions

Optional request settings.

returnsIdpInitiatedLoginClaims

The connection id.

app.get('/auth/callback', async (req, res) => {
const { idp_initiated_login } = req.query;
if (idp_initiated_login) {
const claims = await scalekit.getIdpInitiatedLoginClaims(idp_initiated_login);
const authUrl = scalekit.getAuthorizationUrl(
'https://yourapp.com/auth/callback',
{
connectionId: claims.connection_id,
organizationId: claims.organization_id,
loginHint: claims.login_hint,
...(claims.relay_state && { state: claims.relay_state })
}
);
return res.redirect(authUrl);
}
});
classScalekitClienthttps://github.com/scalekit-inc/scalekit-sdk-node/blob/main/src/scalekit.ts
#asyncrefreshAccessToken

Obtains a new access token using a refresh token.

paramrefreshTokenstring

The refresh token obtained from a previous authentication

returnsRefreshTokenResponse

Tokens and claims.

const result = await scalekit.refreshAccessToken(oldRefreshToken);
// Store the new tokens
await storeTokens(userId, {
accessToken: result.accessToken,
refreshToken: result.refreshToken
});