Skip to content

Getting started with social connections

Single sign-on (SSO) enhances B2B SaaS application security and user experience by enabling secure authentication through an organization’s identity provider (IdP). Some organizations use social identity providers like Google, Microsoft, GitHub, Salesforce etc.

Scalekit enables your users login to your application with any of the social identity providers through OAuth 2.0. This quickstart guide will show you how to add social login (e.g., login with Google) functionality to your application with just a few lines of code.

How Scalekit works

  1. Before diving in, make sure you have:

    • Access to your Scalekit account and API credentials.
    • Your app’s codebase for implementing and testing changes

    npm install @scalekit-sdk/node

    Now you’re ready to start integrating social connections into your app! Next, we’ll cover how to use the SDK to authenticate users.

  2. To start login with social connections, your app must redirect users to the Scalekit authorization URL with appropriate social connection provider details.

    Construct the authorization URL using the following query parameters:

    ParameterDetails
    redirect_uri
    Where Scalekit sends users after IdP authentication.
    Example: https://your-saas-app.com/auth/callback After the user is logged into the social provider, Scalekit redirects the user to this URI with one time authorization code. In the later section, we will explain how to use this unique code to fetch user details
    client_id
    Your app’s unique Scalekit identifier which is mandatory for all requests. This uniquely identifies both your app and the environment (staging, prod).
    provider
    Informs Scalekit which social provider to use. You can use provider as the request parameter with value being the unique code of the provider. For e.g., microsoft.
    Currently, we support the following providers: google, microsoft, github, gitlab, linkedin, salesforce
    Example authorization URL
    https://auth.scalekit.com/authorize?
    client_id=skc_122056050118122349527&
    redirect_uri=https://yourapp.com/auth/callback&
    provider=google

    Next, construct your authorization URL with these parameters and redirect users to this URL when they try to log in.

    import { Scalekit } from '@scalekit-sdk/node';
    // Initialize the SDK client
    const scalekit = new Scalekit('<SCALEKIT_ENVIRONMENT_URL>', '<SCALEKIT_CLIENT_ID>', '<SCALEKIT_CLIENT_SECRET>');
    const authorizationURL = scalekit.getAuthorizationUrl(redirectUri, {
    provider: 'google',
    state: state, // optional
    });
    // Redirect the user to this authorizationURL

    Finally, handle the callback at your redirect_uri to complete the authentication.

  3. After a successful SSO, Scalekit redirects the user to your redirect_uri with a unique code in the browser. Exchange the code for user profile details (on the serverside).

    Here’s how to turn that code into user data:

    const { code, state } = req.query;
    if (error) {
    // Handle errors
    }
    const res = await scalekit.authenticateWithCode(code, redirectUri);
    // res.user has the authenticated user's details
    const userEmail = res.user.email;
    // Next step: create a session for this user and allow access