Skip to content
Scalekit Docs
Talk to an Engineer Dashboard

Add Modular SSO

Add enterprise SSO to an app that keeps its own login: set up Scalekit, send a user to their identity provider and read their profile at your callback.

This quickstart adds enterprise single sign-on (SSO) to an app that keeps its own users and sessions. By the end, a test user signs in through the SSO simulator and your app reads their profile at its callback URL. New to Modular SSO? Start with What is Modular SSO.

Your app signs users in with Auth0, Amazon Cognito, Firebase or Supabase? Follow that system’s guide instead; see Choose how to integrate. Want Scalekit to run the whole login? Use the Full Stack Auth quickstart.

See a walkthrough of the integrationPlay

Using a coding agent?

  • A Scalekit account. Use your development environment: it comes with a test organization and the SSO simulator.
  • A web app whose backend can run the Node.js, Python, Go or Java SDK.
  1. Switch the environment to Modular Auth mode

    Section titled “Switch the environment to Modular Auth mode”

    In the Scalekit dashboard, go to Settings > Authentication Mode, select Modular Auth and select Save. In this mode your app keeps its users and sessions, and Scalekit returns the verified user to your app.

  2. Install the SDK for your stack.

    npm install @scalekit-sdk/node

    Copy your API credentials from Developers > Settings > API Credentials into your .env file:

    .env
    SCALEKIT_ENVIRONMENT_URL=<your-environment-url> # Example: https://acme.scalekit.dev or https://auth.acme.com (if custom domain is set)
    SCALEKIT_CLIENT_ID=<app-client-id> # Example: skc_1234567890abcdef
    SCALEKIT_CLIENT_SECRET=<app-client-secret> # Example: test_abcdef1234567890
  3. Scalekit sends users back to your app only at URLs you register. Go to Authentication > Redirect URLs and add http://localhost:3000/auth/callback under Allowed callback URLs. In production, add your app’s own callback URL. See Register redirect URLs.

  4. Build an authorization URL with the SDK and redirect the user to it. The URL names your callback URL and the user’s organization. To try it now, use the ID of your test organization, under Organizations in the dashboard.

    authorization-url.js
    import { ScalekitClient } from '@scalekit-sdk/node';
    const scalekit = new ScalekitClient(
    '<SCALEKIT_ENVIRONMENT_URL>', // Your Scalekit environment URL
    '<SCALEKIT_CLIENT_ID>', // Unique identifier for your app
    '<SCALEKIT_CLIENT_SECRET>',
    );
    const options = {};
    // Send the user to their organization's SSO. To route by connection ID or by
    // the user's email domain instead, see /sso/guides/authorization-url/
    options['organizationId'] = 'org_15421144869927830';
    // redirect_uri: Your callback endpoint that receives the authorization code
    // Must match the URL registered in your Scalekit dashboard
    const redirectUrl = 'http://localhost:3000/auth/callback';
    const authorizationURL = scalekit.getAuthorizationUrl(redirectUrl, options);
    // Redirect user to this URL to begin SSO authentication

    Scalekit sends the user to their organization’s identity provider. Once they sign in there, Scalekit sends them to your callback URL with a one-time code.

  5. Read the user’s profile at your callback

    Section titled “Read the user’s profile at your callback”

    Add an endpoint at your callback URL. It receives a code, or an error and error_description if the login failed. Exchange the code for the user’s profile:

    Fetch user profile
    // Extract authentication parameters from the callback request
    const { code, error, error_description } = req.query;
    if (error) {
    // The login failed at Scalekit or at the identity provider
    return res.status(401).send('Sign-in failed');
    }
    // The same callback URL you passed to getAuthorizationUrl
    const redirectUri = 'http://localhost:3000/auth/callback';
    const result = await scalekit.authenticateWithCode(code, redirectUri);
    const userEmail = result.user.email;
    // Create a session for the authenticated user and grant appropriate access permissions

    To read the claims in the tokens yourself, validate them with the SDK:

    Validate tokens
    // Validate and decode the ID token from the authentication result
    const idTokenClaims = await scalekit.validateToken(result.idToken);
    // Validate and decode the access token
    const accessTokenClaims = await scalekit.validateToken(result.accessToken);
    {
    user: {
    email: 'john@example.com',
    familyName: 'Doe',
    givenName: 'John',
    username: 'john@example.com',
    id: 'conn_70087756662964366;dcc62570-6a5a-4819-b11b-d33d110c7716'
    },
    idToken: 'eyJhbGciOiJSU..bcLQ',
    accessToken: 'eyJhbGciO..',
    expiresIn: 899
    }

    user.id is the ID token’s sub: the connection ID and the user’s ID at the identity provider, joined by ;. The ID token’s oid claim is the user’s organization ID. See Normalized user profile for every field.

    Before you go to production, check a state value on each callback and find or create the user in your database. See Handle the callback and find the user.

    1. Open the authorization URL from step 4 with your test organization’s ID. The SSO simulator opens in place of a real identity provider.
    2. Leave User Login via SSO selected, enter a user name such as jane (the domain is example.com) and a first and last name, and select Simulate Login.

    Your callback receives a code, and the exchange returns a profile with the email and name you entered. If the callback receives an error instead, look it up in the SSO error reference. For more test cases, such as IdP-initiated login and error scenarios, see Test SSO.