Lesson 9 of 14 · 15m
OAuth 2.0: The Grants That Survived
Authorization code + PKCE is the flow; implicit and password grants died of URL leaks and credential sharing.
The one flow that matters
Authorization code flow, start to finish. The client sends the browser to /authorize?response_type=code&client_id=...&redirect_uri=...&state=...&code_challenge=...&code_challenge_method=S256. The user authenticates at the authorization server and consents. The server redirects back to redirect_uri with ?code=...&state=.... The client POSTs code, redirect_uri, and code_verifier to /token and gets an access token (plus refresh token, plus ID token if OIDC). The code is single-use and expires in about a minute; the token exchange happens server-to-server or from a client that proved it started the request.
PKCE: the pin that made public clients safe
PKCE (RFC 7636, September 2015) was invented for mobile apps — public clients that can't keep a client_secret and whose redirect URIs are custom URL schemes any installed app can claim. The client generates a random code_verifier, sends code_challenge = SHA256(verifier) at authorize time, and proves possession by sending the verifier at token time. An attacker who intercepts the code — scheme hijack, malicious handler, proxy log — can't exchange it without the verifier.
OAuth 2.1 (the consolidation draft) makes PKCE mandatory for all clients, not just public ones — it also defends against auth-code injection on confidential clients. There is no modern reason to skip it.
The grants that died
Implicit — tokens delivered in the URL fragment (#access_token=...) because SPAs couldn't CORS the token endpoint in 2012. Fragments leak: browser history, Referer headers, proxy logs, and fragment-forwarding redirect chains. OAuth 2.1 removes it; auth-code+PKCE replaced it.
Resource Owner Password Credentials — the app collects the user's password itself and trades it for a token. It trained users to hand credentials to third parties, destroyed the MFA story, and made every client a phishing-shaped object. Also removed in 2.1.
Client credentials survives — for machine-to-machine, where there is no user and no redirect.
redirect_uri: an exact string, not a pattern
The authorization server must match redirect_uri as an exact string, per RFC 9700's guidance — no prefix matching, no wildcard subdomains, no query-string leniency. Every looseness is an open-redirect primitive: redirect_uri=https://app.example.com.evil.net, or a whitelisted URI hosting an ?next= open redirector, delivers the authorization code to the attacker's origin. This has been the single most-exploited OAuth misconfig in the wild — code theft converts to account takeover in one exchange.
state and nonce
state binds the authorization response to the browser that started it — the CSRF token of the OAuth world; without it, an attacker who can inject their own code into your callback logs you in as them — the login-CSRF swap where your activity lands in the attacker's account. Generate it server-side, store it against the pre-auth session, compare on the callback, use it once. nonce does the same job for the OIDC ID token specifically — replay protection on the identity itself.
The harder edge: PAR and sender-constraining
Pushed Authorization Requests (RFC 9126) move the authorize call off the front channel entirely — the client POSTs parameters to /par, gets back a request_uri, and the browser redirect carries only that reference. No parameters in the URL means nothing to log, tamper, or leak in referrers. Where the IdP offers it, it's free hardening. DPoP (RFC 9449) and mTLS (RFC 8705) go further and sender-constrain the token itself: the token is bound to a client-held key, so a stolen token is dead bytes to anyone without the private key — the refresh-token lesson's theft problem solved at the OAuth layer.
What to actually do
Authorization code + PKCE, for every client type. Exact-match redirect URIs enumerated in config. state required and one-time. Sender-constrain tokens where the IdP supports it — DPoP (RFC 9449) or mTLS (RFC 8705) make a stolen token useless to a thief who can't present the bound key. And read RFC 9700 once — it is the BCP that replaced folklore.
Keep reading
Related articles from the SudoSecurity blog.
A 257-Byte Password Is the Key: Inside the OpenSSH musl Bypass
CVE-2026-123158 lets an attacker log into a locked account on musl-based systems like Alpine by sending a password nobody set. The trigger is one number, 257, and the reason is a C library returning a single asterisk. I reproduced the exact boundary against musl 1.2.4 and read the fix.
Zero-Trust Access for Homelabbers: Teleport vs. Tailscale vs. WireGuard vs. Cloudflare Tunnel
Four tools solve four different problems that all get pitched as the same problem. Here's what each one does, where each one breaks, and the combination that covers a real homelab without paying an SSO tax you didn't see coming.
The SSO Tax: Why Self-Hosted Projects Are Gating Login Behind a Paywall
A growing list of open-core self-hosted projects, from Grafana to Planka, gate single sign-on behind an Enterprise tier. Here's which protocol actually gets paywalled, and what to check before you deploy.
Zero Trust Everything: The Complete Guide to Self-Hosting Teleport for Secure Infrastructure Access
SudoSecurity runs Teleport internally for everything — admin panel access, secure database connections, Kubernetes, and zero-trust philosophy across our entire team. This is the complete technical guide to installing, configuring, and running your own self-hosted Teleport cluster from scratch.