19. Single Sign-On (SSO)

Big picture: Single Sign-On lets a user authenticate once with a trusted identity provider and access many applications without logging in again. SSO is how enterprises onboard thousands of employees to Slack, Jira, and internal tools β€” and how β€œSign in with Google” scales across products.

Lesson 17 covered authn/authz, JWT, and OAuth for one app. This lesson goes deep on SSO architecture β€” IdP vs SP, SAML vs OIDC, flows, session federation, and what to draw in an HLD.

Prerequisites: 17. Authentication & Authorization, 10. Caching (sessions), 06. HTTP & the Network Path
Read next: 20. How to do HLD β€” place IdP, gateway, and apps in your diagrams.


Learning goals

By the end of this lesson you will be able to:

  • Explain SSO vs logging into each app separately
  • Distinguish Identity Provider (IdP) from Service Provider (SP)
  • Compare SAML 2.0 vs OpenID Connect for enterprise SSO
  • Walk through SP-initiated and IdP-initiated login flows
  • Describe how apps get a local session after SSO
  • Cover logout, MFA, and common failure modes
  • Sketch a multi-app SSO architecture for interviews

SSO in one sentence

SSO = one login at an Identity Provider (IdP) establishes trust so multiple apps (SPs) accept that identity without another password prompt.

Without SSOWith SSO
User has password per appUser signs in once at IdP
IT resets 12 accounts when someone leavesDisable user at IdP β†’ apps lose access on next check
Inconsistent MFA policyCentral MFA at IdP

Everyday analogy: A building badge (IdP) gets you through the lobby once; each floor’s door reader (SP) trusts the badge system instead of issuing its own keycard per office.


Core roles

TermRoleExamples
IdPAuthenticates user; issues proof of identityOkta, Azure AD, Google Workspace, Auth0
SPApplication that trusts the IdPYour SaaS, internal HR portal, Jira
Assertion / tokenSigned proof: who the user is, when, for which appSAML assertion, OIDC ID token
FederationTrust relationship between IdP and SPMetadata exchange, client_id, certs

Interview phrase: "Users authenticate at the corporate IdP; our product is the SP β€” we validate the SAML assertion or OIDC ID token and then issue our own app session."


SAML vs OIDC β€” which protocol?

SAML 2.0OpenID Connect (OIDC)
Era / styleXML, enterprise standardJSON/JWT, modern web and mobile
Typical transportBrowser POST binding, redirectsOAuth 2.0 authorization code + ID token
Common inLegacy enterprise, some B2BNew SaaS, APIs, mobile
Interview default today"Enterprise still uses SAML""Greenfield SSO is usually OIDC"

Many companies run both: SAML for old vendors, OIDC for new apps.


SP-initiated SSO β€” user starts at your app

Most common: user hits app.company.com, gets redirected to login.

OIDC / OAuth-style SSO (modern)

StepSecurity note
Redirect to IdPstate parameter prevents CSRF on callback
Auth codeOne-time; exchanged server-side only
ID tokenVerify signature, aud, iss, exp
App sessionSP still creates its own cookie/JWT for the user

This extends the OAuth flow from lesson 17 β€” SSO is federation at org scale, not a different magic trick.

SAML 2.0 SP-initiated (conceptual)

SAML pieceMeaning
AuthnRequestSP asks IdP to authenticate user
AssertionXML signed statement about identity
ACSAssertion Consumer Service URL on SP
NameIDStable user identifier from IdP

IdP-initiated SSO β€” user starts at the portal

User logs into Okta dashboard (or similar), clicks an app tile.

Design note: SP must still validate every assertion β€” never trust unsigned payloads.


Reference architecture β€” enterprise multi-app SSO

ComponentResponsibility
IdPPassword, MFA, device trust, user lifecycle
SP appsMap federated identity β†’ local user_id, authz, business data
Session storeApp sessions after SSO; not the same as IdP session
User mapping DBidp_subject β†’ internal account; JIT provisioning optional

After SSO: local session and authorization

SSO proves who the user is at the IdP. Your app still needs:

1. Validate token or SAML assertion
2. Find or create local user record (JIT provisioning)
3. Issue app session or JWT with YOUR roles
4. Run authz on every request (lesson 17)
MistakeFix
Trust IdP groups blindly foreverRefresh group claims or sync on schedule
No local user rowMap sub / NameID to users.id
Skip authz because "they passed SSO"SSO = authn only

JIT provisioning: first SSO login auto-creates user from IdP claims β€” convenient; lock down which domains/apps can JIT.


Single Logout (SLO) β€” harder than SSO

Logging out of one app does not automatically log out of all apps unless you implement Single Logout.

ApproachBehavior
App-only logoutClear SP cookie; IdP session may still be alive
IdP logoutUser signs out of portal; other apps may still have SP sessions until TTL
SAML SLO / OIDC end_sessionCoordinate logout β€” fragile, often partial in real deployments

Interview phrase: "We clear our app session and recommend IdP logout for full sign-out; true global SLO is optional and protocol-dependent."


MFA, device trust, and conditional access

Modern IdPs layer policy before issuing assertions:

Login attempt β†’ password OK β†’ MFA push β†’ device compliant? β†’ issue token
PolicyExample
MFARequired for all users or admin roles
Conditional accessBlock login from unknown country
Session lifetimeRe-auth after 8 hours at IdP

SPs inherit trust in the assertion timestamp β€” design short app session TTL if IdP allows long-lived sessions.


B2B SSO vs workforce SSO

WorkforceB2B / customer SSO
WhoEmployeesCustomer's employees
IdPYour company's OktaCustomer's IdP
SetupIT configures oncePer-tenant SAML/OIDC metadata
Multi-tenancyOften one IdPPer-tenant IdP connection

B2B pattern: Each enterprise customer brings their IdP; your SP supports multiple federation configs keyed by tenant_id or email domain.


SCIM β€” provisioning (awareness)

SSO handles login; SCIM (System for Cross-domain Identity Management) handles user create/update/delete from IdP to app.

HR offboards employee in Okta β†’ SCIM DELETE β†’ app disables account immediately

Without SCIM, SSO might still work while orphan accounts linger until manual cleanup.


Security checklist for SSO HLD

  • Validate signature on SAML assertions / JWT from IdP
  • Check audience, issuer, expiry, not-before
  • Use HTTPS everywhere; pin IdP metadata carefully
  • Store client_secret in secrets manager
  • state on OAuth/OIDC redirects
  • Rate limit callback endpoints
  • Map IdP identity to tenant in B2B SaaS
  • Audit log federated logins and admin role changes
  • Plan account linking if users can also use local passwords

Worked example β€” SaaS with Google + Okta SSO

Requirements:

  • Startups use email/password
  • Enterprise customers demand Okta SSO + SCIM
  • Same product, multi-tenant
Auth paths:
  - Local: email/password + your JWT
  - SSO: per-tenant Okta SAML or OIDC metadata

Flow:
  1. User enters email on login page
  2. Lookup tenant by domain β†’ redirect to correct IdP
  3. Callback validates assertion β†’ JIT user if needed
  4. Issue app JWT with tenant_id + roles from local DB

Data:
  tenants(id, sso_type, idp_metadata_url, ...)
  users(id, tenant_id, idp_subject, email, ...)

Narration: "Login routing is domain-based. Federation is per tenant. Authorization always uses our DB β€” IdP only supplies identity and optional group hints."


SSO vs "Sign in with Google" (consumer)

Consumer social loginEnterprise SSO
IdPGoogle / AppleCustomer-controlled IdP
TrustPublic identityContract + metadata exchange
UsersAnyone with Google accountAllowed domain / tenant only
ProtocolOIDC commonSAML + OIDC

Same building blocks β€” different trust and provisioning model.


Check your understanding

1. What is the difference between IdP and SP?

The IdP authenticates the user and issues a signed assertion or token. The SP is the application the user wants to use; it validates that proof and creates a local session. Your product is usually the SP.

2. Why does the SP still create its own session after SSO?

The IdP session proves identity at login time. The SP needs a local session for performance, authz with app-specific roles, and to avoid calling the IdP on every HTTP request.

3. SAML or OIDC for a new B2B SaaS in 2026?

OIDC is the default for new integrations (JSON, OAuth tooling, mobile-friendly). Offer SAML too if enterprise customers require it β€” many still do.

4. User passes SSO but should not see admin UI β€” whose job is that?

Authorization remains the SP's job. Map IdP groups to roles if helpful, but enforce authz in your app (lesson 17).


Common beginner mistakes

MistakeBetter
"We use SSO so we don't need authz"SSO = authn; authz stays in SP
Skip assertion validationVerify signature, audience, expiry
One global Okta for all B2B tenantsPer-tenant federation config
Confuse IdP access token with app JWTIssue your token after validation
No user mapping tableStable sub / NameID β†’ users.id
Assume logout everywhere worksDocument app vs IdP logout behavior

Recap

  • SSO = one IdP login β†’ many SP apps trust the same identity.
  • SAML = enterprise XML federation; OIDC = modern JWT/OAuth SSO.
  • SP-initiated = user starts at app; IdP-initiated = user starts at portal.
  • SP validates proof, maps user, issues local session, enforces authz.
  • B2B = per-customer IdP; SCIM = provisioning alongside SSO.
  • SLO is optional and often partial β€” plan session TTLs.

Previous: 18. Transactions & Isolation
Next: 20. How to do HLD