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 SSO | With SSO |
|---|---|
| User has password per app | User signs in once at IdP |
| IT resets 12 accounts when someone leaves | Disable user at IdP β apps lose access on next check |
| Inconsistent MFA policy | Central 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
| Term | Role | Examples |
|---|---|---|
| IdP | Authenticates user; issues proof of identity | Okta, Azure AD, Google Workspace, Auth0 |
| SP | Application that trusts the IdP | Your SaaS, internal HR portal, Jira |
| Assertion / token | Signed proof: who the user is, when, for which app | SAML assertion, OIDC ID token |
| Federation | Trust relationship between IdP and SP | Metadata 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.0 | OpenID Connect (OIDC) | |
|---|---|---|
| Era / style | XML, enterprise standard | JSON/JWT, modern web and mobile |
| Typical transport | Browser POST binding, redirects | OAuth 2.0 authorization code + ID token |
| Common in | Legacy enterprise, some B2B | New 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)
| Step | Security note |
|---|---|
| Redirect to IdP | state parameter prevents CSRF on callback |
| Auth code | One-time; exchanged server-side only |
| ID token | Verify signature, aud, iss, exp |
| App session | SP 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 piece | Meaning |
|---|---|
| AuthnRequest | SP asks IdP to authenticate user |
| Assertion | XML signed statement about identity |
| ACS | Assertion Consumer Service URL on SP |
| NameID | Stable 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
| Component | Responsibility |
|---|---|
| IdP | Password, MFA, device trust, user lifecycle |
| SP apps | Map federated identity β local user_id, authz, business data |
| Session store | App sessions after SSO; not the same as IdP session |
| User mapping DB | idp_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)
| Mistake | Fix |
|---|---|
| Trust IdP groups blindly forever | Refresh group claims or sync on schedule |
| No local user row | Map 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.
| Approach | Behavior |
|---|---|
| App-only logout | Clear SP cookie; IdP session may still be alive |
| IdP logout | User signs out of portal; other apps may still have SP sessions until TTL |
| SAML SLO / OIDC end_session | Coordinate 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
| Policy | Example |
|---|---|
| MFA | Required for all users or admin roles |
| Conditional access | Block login from unknown country |
| Session lifetime | Re-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
| Workforce | B2B / customer SSO | |
|---|---|---|
| Who | Employees | Customer's employees |
| IdP | Your company's Okta | Customer's IdP |
| Setup | IT configures once | Per-tenant SAML/OIDC metadata |
| Multi-tenancy | Often one IdP | Per-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
-
stateon 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 login | Enterprise SSO | |
|---|---|---|
| IdP | Google / Apple | Customer-controlled IdP |
| Trust | Public identity | Contract + metadata exchange |
| Users | Anyone with Google account | Allowed domain / tenant only |
| Protocol | OIDC common | SAML + 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
| Mistake | Better |
|---|---|
| "We use SSO so we don't need authz" | SSO = authn; authz stays in SP |
| Skip assertion validation | Verify signature, audience, expiry |
| One global Okta for all B2B tenants | Per-tenant federation config |
| Confuse IdP access token with app JWT | Issue your token after validation |
| No user mapping table | Stable sub / NameID β users.id |
| Assume logout everywhere works | Document 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