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.

This guide shows you how to add social login functionality to your B2B SaaS application using Scalekit. You’ll learn how to enable users to authenticate with popular identity providers like Google, Microsoft, GitHub, and more through OAuth 2.0.

How Scalekit works

  1. Before implementing social login, ensure you have the necessary tools and access:

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

    npm install @scalekit-sdk/node

    You’re now ready to integrate social connections into your application! The next step covers how to use the SDK to authenticate users.

  2. To start the social login process, your application must redirect users to Scalekit’s authorization endpoint with the appropriate social provider details.

    Construct the authorization URL using these required parameters:

    ParameterDescription
    redirect_uriThe URL where Scalekit sends users after successful authentication. After users complete authentication with the social provider, Scalekit redirects them to this URI with a one-time authorization code. You’ll use this code in the next step to fetch user details.
    client_idYour application’s unique Scalekit identifier. This parameter is mandatory for all requests and uniquely identifies both your application and environment (staging, production).
    providerSpecifies which social provider to use. Set this to the unique code of your chosen provider (e.g., google, microsoft).
    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 attempt 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

    After users complete authentication, Scalekit redirects them to your redirect_uri with an authorization code. Handle this callback to complete the authentication process.

  3. After successful social authentication, Scalekit redirects users to your redirect_uri with a unique authorization code. Exchange this code for user profile details on your server side.

    Here’s how to convert the authorization 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

You’ve successfully implemented social login functionality in your application. Your users can now authenticate using their preferred social identity providers.