Understanding OAuth 2.0 and OAuth 2.1: A Guide to Secure Authorization in 2026
By Huzi
File #448 · 3 min read
Every time you tap "Log in with Google" and hand over no password, you are watching OAuth 2.0 do its job: delegating limited access to an app without sharing your credentials. Understanding the flow — not the buzzwords — is what separates implementations that hold from implementations that leak.
The quick answer: Build on the authorization code flow with PKCE — the draft OAuth 2.1 spec folds a decade of hard lessons into one standard and makes PKCE mandatory for every client. Match redirect URIs exactly, keep access tokens short-lived and server-side, and reach for a mature library before rolling your own.
Authentication is not authorization
Authentication proves who you are. Authorization decides what you may touch. OAuth handles the second; OpenID Connect adds the first on top by issuing an id_token. Most "login with X" buttons run both together, and conflating the two is where developers start going wrong.
A cast of four
The resource owner is you, the human with the data. The client is the app asking for access. The authorization server — Google's, for instance — issues the tokens. The resource server is the API actually holding your photos or files. Every flow below is just these four passing messages.
The authorization code flow, step by step
The workhorse of the modern web, and the only public flow worth building on:
- The client generates a random code_verifier and sends its SHA-256 hash — the code_challenge, method S256 — together with its client ID and requested scopes when redirecting your browser to the authorization server.
- You log in, ideally with a passkey, and approve a consent screen naming exactly what the app wants.
- The server redirects back with a one-time authorization code.
- The client redeems the code directly, presenting the original code_verifier. The server hashes it and compares it with the stored challenge; a match proves the same client that started the flow is the one finishing it.
That comparison is PKCE, and OAuth 2.1 makes it mandatory for every client, not just mobile apps. The old implicit flow, which leaked tokens through URLs and browser history, is dead — delete it wherever it lingers.
The moving parts, and what each is for:
| Piece | Why it exists |
|---|---|
| code_challenge (S256) | Binds the finish to the client that started the flow |
| Consent screen | Approval that names exactly what the app wants |
| One-time authorization code | Redeemed directly, then dead |
| state parameter | Blocks CSRF; the nonce guards the token in OIDC |
| Refresh-token rotation | Damage control when a token leaks |
The rules that keep it safe
- Register and match redirect_uri exactly; wildcards are how authorization codes get stolen.
- Always send the state parameter, or the login is open to CSRF — in OpenID Connect, the nonce guards the token.
- Keep access tokens short-lived, rotate refresh tokens on every use, and store tokens server-side; browser localStorage sits one XSS bug away from account takeover.
- Trust an email claim only when the provider has verified it.
Scopes ask the same question a visa form asks: this document, this trip, this date — nothing broader. We file exactly what the embassy asks for and nothing more at HTG Travels, which is what a well-scoped authorization should feel like.
Pro tip: Use a mature library — openid-client for Node, Authlib for Python — or a hosted identity provider. Rolling your own client is how every rule above gets broken in a single afternoon.
The whole protocol rests on consent being explicit, limited and revocable — Palestine is the starkest reminder of what happens when a people's consent is treated as decoration rather than foundation.
Delegation hands over the least authority needed — never the keys to everything. Travel paperwork works the same way: you authorise HTG Travels in writing to act on your visa file and flights; that limited authority is all we hold. Your passwords, like your trust, stay yours. One WhatsApp to +92 317 5054959 — the scope is yours to approve.




