Course map

Topic 161 / Core

OAuth 2.0 and OpenID Connect: single sign-on, identity federation

Chapter 10.2 · Identity and Access

What and why

Topic 160 manages identity for one application; many systems instead need to let a user authenticate somewhere else and prove that fact here, or let one login serve many applications. OAuth 2.0 is a delegated-authorization framework: it lets a user grant one application limited access to resources held by another, without sharing a password. OpenID Connect (OIDC) builds an authentication layer on top of OAuth: it adds the ID token, which proves who the user is. OAuth alone answers "what may this app access"; OIDC answers "who is this user" — conflating the two is a common and serious mistake. Together they enable single sign-on (one login session serving multiple applications) and identity federation (trusting another organization's identity provider instead of maintaining a separate account). Builds on: → 160 (identity lifecycle).

Diagram

Authorization code flow with PKCE — the default flow:

User          Client app          Authorization server          Resource server
 │                 │                       │                          │
 │  wants to log in│                       │                          │
 │────────────────►│  redirect w/ PKCE     │                          │
 │                 │──────────────────────►│                          │
 │  authenticates & consents (at the authorization server, not the client)
 │◄───────────────────────────────────────►│                          │
 │                 │  redirect w/ code      │                         │
 │                 │◄──────────────────────│                          │
 │                 │  exchange code+verifier for tokens                │
 │                 │──────────────────────►│                          │
 │                 │  access token (+ ID token if OIDC)                │
 │                 │◄──────────────────────│                          │
 │                 │  call with access token                           │
 │                 │─────────────────────────────────────────────────►│

How it works

  1. The client app redirects the user to the authorization server, sending a PKCE challenge (a one-time secret the client will later prove it holds).
  2. The user authenticates and consents at the authorization server, never by entering credentials into the client app itself — this is what makes delegation safe.
  3. The authorization server redirects back to the client with a short-lived authorization code.
  4. The client exchanges that code, plus the PKCE verifier, for tokens — directly with the authorization server, not through the user's browser.
  5. OAuth returns an access token (authorization — what the client may do). OIDC additionally returns an ID token (authentication — who the user is, as signed claims).
  6. Single sign-on reuses one authorization-server session across multiple client apps; federation points the authorization server at another organization's identity provider instead of a locally-managed one.

Practical example

(illustrative). A "log in with your work account" button on a third-party tool: the tool (client) redirects to the organization's identity provider (authorization server); the user authenticates there, never typing a password into the third-party tool; the tool receives an ID token proving identity and an access token scoped to only what it asked for — never the user's full account access.

When to use it

  • Use when: a third party needs delegated access without a shared password; a single login should serve several internal applications; identity should federate from an external organization's identity provider.
  • Avoid when: a single application with no SSO or federation need — plain session or token authentication (→ 159, 160) is simpler and has no redirect-flow surface to secure.
  • Failure scenarios: treating an OAuth access token as proof of identity — that is OIDC's ID token's job, and the access token was never designed to carry a verified identity claim; skipping PKCE and exposing the authorization code to interception.
  • Simpler alternative: direct username/password login (→ 160) for a single product with no delegation or federation requirement.

Practice

(Mechanism kind — trace the flow by hand, predict then verify; 20–30 min, no lab services). For a given scenario (a client app, an authorization server, a resource server), trace the authorization code + PKCE flow step by step from the diagram above. Before each arrow, predict what the message must contain and why; after tracing, verify by listing which step would fail if PKCE were skipped and the authorization code were intercepted. Done when the trace matches the diagram exactly and the PKCE failure is correctly identified.

Key takeaway

OAuth delegates authorization, OIDC adds authentication on top; together they give single sign-on and federation without password sharing. Done when you can: state, for a given token, whether it proves identity or proves access rights — and name which exchange produced it. Used next in → 162 (the tokens this flow issues), → 163 (claims feed authorization decisions); Project 3.

References

RFC 6749: The OAuth 2.0 Authorization Framework — see references.md. OpenID Connect Core 1.0 — see references.md.

Source directory

Search the guide