Chapter 4: Protocol Overview and Flows — The Actual Handshakes
This is Part 4 of a chapter-by-chapter walkthrough of my book OpenID: Modern Identity for Developers and Architects. In the previous chapter we installed the vocabulary — actors, claims, tokens, consent, the boundary of responsibility. Now we watch those concepts turn into actual protocol exchanges on the wire.
Chapter 4 is where many identity tutorials go off the rails. They show you "the flow" — singular — as if OpenID Connect only had one way to authenticate a user. In reality there are several flows, each designed for a different shape of client, and picking the wrong one is how production systems quietly ship vulnerabilities.
4.1 — The Actors, Named Again — This Time on the Wire
The triangle from Chapter 3 gains a fourth corner in practice: the End-User, the Relying Party (RP), the OpenID Provider (OP), and, lurking underneath the OP, the Authorization Server. In modern deployments the OP and the Authorization Server are usually the same service — but the distinction matters conceptually because OpenID Connect is specifically the authentication layer that OAuth 2.0 needed. The Authorization Server issues tokens; the OP adds identity on top.
Keeping these labels straight in your head makes the flows that follow much easier to read.
4.2 — Authorization Code Flow: The Default You Should Almost Always Use
The Authorization Code Flow is the workhorse of modern identity. It's what powers "Sign in with Google" on a web app, the login on your mobile app, and the auth handshake in a well-designed SPA. The shape is deceptively simple:
- RP redirects the user to the OP's authorization endpoint with
client_id,scope,redirect_uri, and astatevalue. - User authenticates at the OP and approves the consent screen.
- OP redirects the user back to the RP's
redirect_uriwith a short-lived authorization code and the originalstate. - RP validates
state, then exchanges the code at the OP's token endpoint over a backend-to-backend HTTPS call — invisible to the browser. - OP returns an ID Token, an Access Token, and optionally a Refresh Token.
- RP validates the ID Token's signature, issuer, audience, and expiry. User is logged in.
The beauty of this flow is that the dangerous artifact — the authorization code — is short-lived and the tokens never appear in a browser URL or the user's browser history. That single design choice closes whole classes of attack that plagued earlier flows.
state parameter isn't decoration. It's the only thing standing between your users and CSRF at the redirect step. Generate it randomly per request, store it in the user's server-side session, and reject any callback where the returned state doesn't match. Chapter 13 shows what happens when you don't.4.3 — PKCE: No Longer Optional
PKCE (pronounced "pixy" — Proof Key for Code Exchange, RFC 7636) was originally a patch for public clients that couldn't safely hold a client_secret. Current guidance treats it as mandatory for all clients, confidential ones included.
The mechanic is elegant. The client generates a random code_verifier, hashes it (SHA-256, base64url-encoded) into a code_challenge, and sends the challenge on the authorization request. When it later trades the authorization code for tokens, it must also present the original verifier. The OP hashes the verifier again and checks against the stored challenge. If an attacker steals the authorization code in transit, they still can't redeem it without the verifier — and the verifier never left the legitimate client.
S256 method, never plain.4.4 — Client Credentials: When There Is No User
Not every authentication is about a human. Service-to-service calls — a payment worker hitting an accounting API, a data pipeline pulling from a warehouse, a scheduled batch job — need their own identity, and OpenID Connect provides it through the Client Credentials Flow.
The client hits the token endpoint directly with its client_id and client_secret and grant_type=client_credentials. No browser, no consent screen, no user. The OP returns an Access Token — and importantly, no ID Token, because there is no user identity to assert.
This flow is only safe for confidential clients running in environments where a real secret can be protected. If your "service" is actually a mobile app or anything shipped to user devices, Client Credentials is the wrong answer.
4.5 — CIBA and Device Flow: When the Login Device and the Authenticating Device Are Different
Smart TVs, IoT devices, CLIs, and point-of-sale terminals don't have browsers — or at least don't have convenient ones. The Device Flow (RFC 8628) solves this by decoupling where login happens from where the authenticating user types their password. The device gets a short user code, displays it, and the user completes authentication on their phone or laptop while the original device polls the token endpoint.
CIBA (Client Initiated Backchannel Authentication) is the more sophisticated cousin: the RP kicks off authentication via a backchannel request, and the OP pushes the authentication challenge out to a pre-registered channel (an authenticator app, a push notification) where the user responds. Once the user approves, the OP calls back to the RP. CIBA is used heavily in high-assurance contexts like Open Banking, where the user is never on the same device that's initiating the action.
4.6 — Implicit and Hybrid: Deprecated on Purpose
The Implicit Flow returned tokens directly in the browser's redirect URL, which felt clever in 2012 and looks like a ticking time bomb today. Tokens in URLs leak into browser history, referrers, server logs, and analytics. The OAuth 2.0 Security Best Current Practice has formally deprecated it; modern libraries default to Authorization Code + PKCE instead.
The Hybrid Flow splits the difference — returning some tokens immediately from the authorization endpoint while also returning an authorization code to exchange later. It has niche uses, but the cost is real complexity and a larger attack surface. If you're starting a new project, use Authorization Code + PKCE and don't look back.
What Chapter 4 Sets Up
By the end of Chapter 4 you should be able to match a client type to a flow without thinking: server-side web app → Authorization Code + PKCE; SPA → Authorization Code + PKCE (same answer, different reasons); mobile app → Authorization Code + PKCE; service-to-service → Client Credentials; smart TV or CLI → Device Flow; high-assurance out-of-band → CIBA. If your answer to any of these is "Implicit," stop and re-read.
Next up — Chapter 5: Tokens in Depth. Now that we've seen the flows that move tokens around, we crack the tokens themselves open: ID Token claims, Access Tokens as bearer vs. proof-of-possession, Refresh Token hygiene, JWT structure (JWS and JWE), signature validation, and modern token binding via DPoP and mTLS. If Chapter 4 is about how tokens travel, Chapter 5 is about what they actually are.
Sho Shimoda
I share and organize what I’ve learned and experienced.Categories
Tags
Search Logs
Development & Technical Consulting
Working on a new product or exploring a technical idea? We help teams with system design, architecture reviews, requirements definition, proof-of-concept development, and full implementation. Whether you need a quick technical assessment or end-to-end support, feel free to reach out.
Contact Us