API & BACKEND ARCHITECTURE / SYSTEM CONCEPT BRIEF

SSO

Single sign-on (SSO) lets a user authenticate once with a central identity provider (IdP) and then access many applications without logging in again.

IntermediatePhase 02 / Topic 8 of 20RequirementsTrade-offsFailure modes
01

Overview

Single sign-on (SSO) lets a user authenticate once with a central identity provider (IdP) and then access many applications without logging in again. Each application (service provider) trusts the IdP's signed assertion about who the user is, instead of managing its own passwords.

Enterprise SSO typically uses SAML 2.0 (older, XML-based) or OpenID Connect (modern, JSON/JWT-based). SSO improves security (one place for MFA, password policy, and offboarding) and user experience, but makes the IdP a critical dependency: if it is down, nobody can log in.

A festival wristband

You show your ticket and ID once at the main gate and get a wristband. Every stage and food tent checks the wristband instead of your ID. If security cuts your wristband, you lose access to everything at once.

02

When to use it

  • Companies with many internal and SaaS applications.
  • B2B SaaS selling to enterprises (customers require SSO).
  • A product suite where users move between apps (Google Workspace).
  • Centralized offboarding: disable one account, lose access everywhere.
03

Where it shows up in interviews

Enterprise SaaS

Recognize it when: customers want to use their own identity provider.

  • Design SSO for a B2B SaaS product
  • Design multi-tenant login
Product suite login

Recognize it when: one account across several apps.

  • Design Google account login across Gmail, Drive, YouTube
04

Where it is used in real software

Okta, Microsoft Entra ID, Google Workspace

Common enterprise IdPs that federate login to thousands of SaaS apps using SAML and OIDC.

SCIM provisioning

Alongside SSO, SCIM automatically creates and deactivates user accounts in apps when HR changes happen.

The SSO tax

Many SaaS vendors put SSO only in expensive enterprise plans because it is a must-have for large customers.

05

Key terms

Identity provider (IdP)
Authenticates users and issues assertions or tokens.
Service provider (SP)
The application that relies on the IdP.
SAML assertion
A signed XML document stating who the user is and their attributes.
Federation
Trust between separate organizations' identity systems.
SCIM
Standard API for provisioning and deprovisioning users.
06

How it works, step by step

  1. 1
    User opens app A

    App A has no session and redirects to the IdP.

  2. 2
    IdP authenticates

    User logs in with password + MFA; the IdP creates its own session.

  3. 3
    IdP returns an assertion or token

    Signed SAML assertion or OIDC ID token posted back to app A.

  4. 4
    App A creates a local session

    After verifying the signature and audience.

  5. 5
    User opens app B

    App B redirects to the IdP, which already has a session and immediately returns a token: no login prompt.

07

SAML vs OIDC

Both achieve SSO

Step 1 / 4
AspectSAML 2.0OpenID Connect
FormatXML assertionsJSON / JWT
Typical useEnterprise web appsModern web, mobile, APIs
Mobile friendlyPoorGood
Built onIts own protocolOAuth 2.0

NOWAspect: Format | SAML 2.0: XML assertions | OpenID Connect: JSON / JWT

New products should prefer OIDC, but B2B SaaS usually must support SAML too because many enterprises still require it.

08

Implementation

import { Issuer, generators } from "openid-client"; const issuer = await Issuer.discover("https://idp.example.com"); // reads .well-known/openid-configurationconst client = new issuer.Client({  client_id: "crm-app",  client_secret: process.env.OIDC_SECRET!,  redirect_uris: ["https://crm.example.com/callback"],  response_types: ["code"],}); app.get("/login", (req, res) => {  const codeVerifier = generators.codeVerifier();  req.session.codeVerifier = codeVerifier;  res.redirect(client.authorizationUrl({    scope: "openid email profile",    code_challenge: generators.codeChallenge(codeVerifier),    code_challenge_method: "S256",  }));}); app.get("/callback", async (req, res) => {  const params = client.callbackParams(req);  const tokens = await client.callback("https://crm.example.com/callback", params, { code_verifier: req.session.codeVerifier });  const claims = tokens.claims(); // verified ID token: sub, email, name  req.session.userId = await users.upsertFromIdp(claims.sub, claims.email);  res.redirect("/");});
09

Complexity and performance

First loginFull IdP login

Password + MFA.

Later appsRedirect only

No prompt while IdP session is valid.

10

Trade-offs

Convenience vs blast radius

One compromised IdP account reaches every app; enforce strong MFA and anomaly detection at the IdP.

IdP availability

An IdP outage blocks logins everywhere; existing app sessions keep working, so reasonable session lifetimes matter.

11

Variants and related techniques

Multi-tenant SSO

Each customer configures its own IdP; the login page routes by email domain.

Single logout

Logging out of the IdP signals every app to end sessions; hard to make fully reliable.

12

Common mistakes

  • Not validating the assertion's audience and signature.

    Fix: Verify issuer, audience, signature, and expiry on every login.

  • Forgetting deprovisioning.

    Fix: Use SCIM or short sessions so removed employees lose access quickly.

13

Interview questions

How does SSO work under the hood?

The application redirects to the identity provider, which authenticates the user and returns a signed assertion or ID token. The app verifies it and creates a local session. Other apps repeat the redirect, but the IdP's existing session makes it silent.

How would you add enterprise SSO to a multi-tenant SaaS?

Store per-tenant IdP configuration (SAML metadata or OIDC issuer), route login by email domain, map IdP identities to tenant users, and support SCIM for provisioning.

14

Practice problems

ProblemDifficultyWhat it trains
Explain SSO between two apps and one IdPEasyRedirect flow.
Design per-tenant SSO for a B2B productHardConfiguration and mapping.