Single Sign-On

Add Single Sign-On (SSO) for all Identity Providers to your app with a single integration.

Introduction

Single Sign-On (SSO) is the most frequently asked for requirement by enterprise organizations looking to adopt new SaaS applications. SSO enables authentication via an organization’s Identity Provider (IdP), such as G Suite or Okta, as opposed to users or IT admins managing hundreds, if not thousands, of usernames and passwords. Facilitate greater security, easier account management, and accelerated application onboarding and adoption by adding SSO to your app.

The WorkOS SSO API is modeled to meet the OAuth 2.0 framework specification, abstracting away the underlying authentication handshakes between different IdPs. Check out the sequence of events below.

The WorkOS SSO API is authentication middleware and intentionally does not handle user database management for your application. This is by design, to minimize vendor lock-in for Developers.

Our SSO API is compatible with any Identity Provider and supports both the SAML and OpenID Connect protocols.

Request an Identity Provider

Don't see an Identity Provider you need? Contact us to request an Identity Provider!

What you’ll build

In this guide, we’ll take you from learning about Single Sign-On and POC-ing all the way through to authenticating your first user via the WorkOS SSO API.

Sign in to your Developer Dashboard account to see code examples pre-filled with your API keys and resource IDs.

This guide will show you how to:

Before getting started

To get the most out of this guide, you’ll need:

  • A Developer Dashboard account.
  • An IdP account from an Identity Provider that WorkOS supports. Reach out if you need help setting up an IdP instance for development.

API Object Definitions

ObjectDefinition
ConnectionA Connection represents the method by which a group of users (typically in a single organization) sign in to your application.
ProfileA Profile is an object that represents an authenticated user. The Profile object contains information relevant to a user in the form of normalized and raw attributes.

1
Add SSO to your app

Let’s start by building the SSO authentication workflow into your app.

1. Install the WorkOS SDK of your choice

WorkOS offers native SDKs in several popular programming languages. Choose a language below to see instructions in your application’s language.

  • Node.jsNode.js
  • RubyRuby
  • GoGo
  • PythonPython
  • PHPPHP
  • LaravelLaravel
  • .NET.NET
Request an SDK

Don't see an SDK you need? Contact us to request an SDK!

Install the SDK using the command below.

Install the WorkOS SDK

npm install @workos-inc/node
You can also download the workos-node source code from GitHub.

2. Set environment variables

As a best practice, your WorkOS API key should be kept secret and set as an environment variable on process start. The Project ID should also be set dynamically based on the release environment.

Environment Variables

WORKOS_API_KEY='{secretKey}'
WORKOS_PROJECT_ID='{projectID}'

3. Add a callback endpoint

Let’s first add the redirect endpoint which will handle the callback from WorkOS after a user has authenticated with their IdP. This endpoint should exchange the authorization code (valid for 10 minutes) returned by WorkOS with the authenticated user’s Profile.

The redirect URI must use HTTPS.

Callback Endpoint

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
const express = require('express');
const WorkOS = require('@workos-inc/node');

const app = express();

const workos = new WorkOS(process.env.WORKOS_API_KEY);
const projectID = process.env.WORKOS_PROJECT_ID;

app.get('/callback', async (req, res) => {
  const { code } = req.query;

  const profile = await workos.sso.getProfile({
    code,
    projectID,
  });

  // Use the information in `profile` for further business logic.

  res.redirect('/');
});

4. Add an endpoint to initiate SSO

The endpoint to initiate SSO via the WorkOS API is responsible for simply handing off the rest of the authentication workflow to WorkOS. There are a couple configuration options shown below.

You can use the optional state parameter to encode arbitrary information to help restore application state between redirects.

If you’re interested in custom-labeling the IdP sign-in screens, reach out to WorkOS support.
Using domainUsing providerUsing domain and provider

Use the domain parameter when authenticating a user by their domain.

Authentication Endpoint

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
const express = require('express');
const WorkOS = require('@workos-inc/node');

const app = express();

const workos = new WorkOS(process.env.WORKOS_API_KEY);
const projectID = process.env.WORKOS_PROJECT_ID;

app.get('/auth', (_req, res) => {
  const domain =  // ... The user's domain
  const redirectURI =  // ... The URI WorkOS should callback to post-authentication

  const authorizationURL = workos.sso.getAuthorizationURL({
    domain,
    redirectURI,
    projectID,
  });

  res.redirect(authorizationURL);
});

2
Configure a redirect URI

You should set a redirect URI (i.e. the callback endpoint from Add a callback endpoint) via the Developer Dashboard - be sure not to include wildcard subdomains or query parameters.

Multi-tenant apps will typically have a single redirect URI specified. You can set multiple redirect URIs for single tenant apps - just be sure to specify which redirect_uri to use in the WorkOS client call to fetch the authorization URL.

In the IdP-initiated authentication flow, the default redirect URI is used.

3
Create a new SSO Connection

An SSO Connection must be created for every domain, i.e. organization, that wants to authenticate via SSO. Connections can be created in the Connections Dashboard. Let’s create one for development in your Sandbox Project - get provider specific instructions by selecting which Identity Provider you want to connect to.

Add the WorkOS Admin Portal to your app to enable your users to create and configure SSO Connections themselves.
Identity Provider
  • AD FS SAML
  • Azure SAML
  • Google OAuth
  • Google SAML
  • Okta SAML
  • OneLogin SAML
  • VMWare SAML
Instructions

Connect to a Microsoft Active Directory Federation Services (AD FS) SAML server by reading through our integration guide below. It provides end-to-end instructions for creating your Connection in the WorkOS Developer Dashboard.

Connect to AD FS SAML

Our guide to creating a new Connection with AD FS SAML.

Once your Connection is successfully created and linked, it’s ready to start being used to authenticate users!

Go live checklist

Make sure you're ready to go live to production by going through this checklist.

Depending on your network architecture, you may need to allowlist incoming redirect traffic from api.workos.com

WorkOS currently cannot promise that redirect traffic will originate from a static set of IP addresses.

Next steps

Here are some suggestions for taking your app to the next level in enterprise readiness.

  • Integrate the WorkOS Admin Portal to enable your users to onboard and set up SSO themselves.
  • If you're interested in getting listed in IdP app marketplaces such as the Okta Integration Network or the Azure AD Marketplace, reach out to us, we're happy to help!
  • Integrate the WorkOS Directory Sync API for automatic user updating, provisioning, and deprovisioning.