When creating SaaS applications for enterprises, it becomes vital to include Single Sign-On (SSO) functionality. OneLogin enables enterprises to establish secure employee access for the applications they use.
This tutorial explains how to integrate SSO login in your SaaS application through React and Node.js. By the end of this guide, you will understand how to authenticate enterprise users through OneLogin by providing a simple login process.
Without SSO, enterprise users need to remember different login credentials to access their daily apps like Outlook, Asana, Confluence and your app as well. Implementing SSO can streamline this process by allowing users to access multiple applications with a single set of credentials, thereby enhancing security and reducing user frustration.
SSO eliminates credential entry by allowing users to launch multiple applications from one unified sign-in experience. Hence, enterprises prefer applications that support SSO. It results in better security and streams the process of managing user access permissions. The tutorial demonstrates how to establish SSO functionality in Node.js + React applications through OneLogin authentication.
By the end of this guide, you'll learn how to:
Let’s dive in!
You can follow along with the code in this GitHub repository. Check the README.md file for setup instructions to run it on your local machine.
When enterprise users log into your app, the process is a bit different. Instead of entering a username and password directly, they click "Continue with SSO" and are redirected to OneLogin for authentication. This ensures a secure login process before they access your app.
Our sample app consists of two main parts-- backend (built with Node.js) and frontend (built with React.js). Here are the problems in our current approach:
Instead of dealing with these challenges manually, there’s a better way to handle authentication seamlessly. Let’s explore how!
Scalekit simplifies the authentication process by handling all the complexity for you. Instead of dealing directly with OneLogin, your app redirects enterprise users to Scalekit. Once they log in successfully, Scalekit sends back their profile details to your app.
Here’s how it looks:
All the API interactions are scoped between your app and Scalekit. It reduces many security risks, and it’s way easier to ship SSO. Perhaps in hours!
To integrate Scalekit for authentication, you’ll need to install the Scalekit SDK and set up your environment variables.
🛠️ Install Scalekit SDK:
If you're using the example app, the backend's package.json already lists Scalekit as a dependency.
Run:
This installs all dependencies for both the frontend and backend.
Set Up API credentials
Instantiate Scalekit SDK using API credentials. Follow these steps to get them from Scalekit app:
Update the .env template:
🛠️ Set up environment variables:
You can find these values on the Scalekit dashboard. Let’s use “Test Organization” for now as it is pre-configured, just to test our connection.
Scalekit manages the authentication flow for OneLogin, making SSO simpler. Here's how it works:
Now, let's implement the authorization URL and handle successful callbacks.
In your backend/routes/index.ts, the /login route generates a special authorization URL using the Scalekit SDK. This URL redirects users to OneLogin (or another Identity Provider) to handle authentication.
To create a destination URL, you need to pass the redirect URI and a couple of options to Scalekit’s getAuthorizationUrl() method.
Any ONE of connectionId, organizationId or loginHint must be passed in order to initiate Single Sign-on. These are available once you create an organization from Scalekit Dashboard. These resemble your customers. For ease of testing for developers, you can use a default “Test Organization”.
Note that the redirect URI you will pass should be registered in the Scalekit Dashboard > API Config.
For demonstration purposes, the example app takes these details as part of environment variables. In real-time, these identifiers will be used at the runtime based on your app’s business use-case.
While connectionId and organizationId are the identifiers that Scalekit gives to your app at the runtime, a user can give his/her email address, for instance john@example.org. We will later see React frontend sending these details to the backend.
💡 Pro tip: If you test with @example.com or @example.org emails, Scalekit will use an IdP Simulator instead of a real OneLogin setup. This helps simulate SSO authentication during development.
Once a user successfully logs in, Scalekit sends a callback request to your app with an authorization code. Your app then exchanges this code for user profile details.
This is a simplified version of the actual implementation in backend/routes/index.ts.
Your app can now securely store the user profile details. This example uses browser session storage which may not be ideal for all production scenarios.
Now that our /login endpoint is ready to redirect users for authentication, let’s update the React UI to initiate the login process.
Go to frontend/src/components/Login.jsx
Make a call to the /login endpoint and redirect the user by changing window.location.href at runtime.
Once SSO is complete, the example app displays the user profile details. See frontend/src/pages/Dashboard.jsx on how it renders this information.
Before adding OneLogin to your app, you need to configure Scalekit properly. Follow these steps:
Check Scalekit’s documentation for configuring OneLogin for SSO. With these steps completed, enterprise users will be able to authenticate through OneLogin and access your application securely.
Your application is all set up to handle SSO authentication with OneLogin.
Now, it’s time to connect Scalekit with OneLogin for your enterprise customer. This step is typically handled by an IT administrator, who configures the connection by entering specific details into OneLogin.
You’ve successfully implemented SSO with OneLogin in your React and Node.js app using Scalekit. Your application successfully identifies enterprise users, handles authentication, and securely logs them in—all in just a few seconds.
Scalekit provides separate environments for testing and production. So you can test your integration safely before rolling it out. Once everything works as expected, you can switch to production from Workspace > Environment in the top navigation menu.
💡 Pro tip: Notice idp_initiated_login in the example code? Read this guide to allow enterprise users to log in to your app directly from the OneLogin applications list.
Even with a correct setup, SSO authentication can fail due to misconfigurations or permission issues. Below are some common SSO errors, their causes, and how to fix them.
Single Sign On (SSO) and Identity Access Management (IAM) solution OneLogin provides users with secure multi-application access through a single login authentication.
Authentication through SAML (Security Assertion Markup Language) is one of the protocols supported by OneLogin alongside OAuth, OpenID Connect and alternative protocols.
When users authenticate a single time against OneLogin they can instantly access multiple applications without additional logins using SSO.
IAM features SSO as one of its main functions. The Identity and Access Management solution contains SSO as well as multi-factor authentication (MFA) and user access controls.
Yes, the IdP tag can be given to OneLogin because it both authenticates users and enables safe application access.