Skip to main content
Say Alan just shipped a calendar app for phones. The basic user flow is simple: sign in, pick a date, and add events. Behind the scenes, the app must prove to a remote calendar server that it has the right to act on the user’s behalf. The common solution is OAuth — specifically the current recommended guidance: OAuth 2.1. An OAuth interaction looks like this: the user signs in with an authorization server, which returns an authorization code (a one-time ticket). The app takes that code back to the authorization server and exchanges it for an access token. The app then attaches the access token to requests so the calendar server knows who is asking. Example request using a Bearer access token:
A diagram titled "How the App Proves Access" showing an Authorization Server and an OAuth token mediating between Alan's mobile app (left) and a Calendar Server (right).

Binding the response to the request

Before the client uses the authorization code, the app must ensure the code actually came from the expected authorization server and from the same flow it started. Common checks include:
  • Verifying the state parameter returned with the authorization response matches the original state the app sent.
  • Ensuring the redirect_uri used in the response is an exact character-for-character match with the registered redirect URI.
  • Validating the issuer (iss) claim inside tokens (for example, the ID token) against the authorization server’s metadata, instead of trusting an iss query parameter handed in the browser redirect.
Do not trust arbitrary query parameters in redirects — use token claims or authorization-server metadata as the source of truth.

Client identification and registration

When the authorization server asks “who is this app?”, the app must identify itself. There are two common approaches:
  • Dynamic client registration: the client POSTs metadata (name, callback URL, etc.) and receives a client_id and client_secret in response.
  • Metadata URL: the client provides a URL where the authorization server fetches a client metadata document (for example, https://calendar.example.com/app.json) describing the client.
When the authorization server issues credentials, treat each issuer separately. If Alan’s app talks to two authorization servers, it should keep separate credential sets — one per issuer.
A diagram titled "One Set per Issuer" showing two authentication servers (Auth Server A and Auth Server B) on either side of a mobile app labeled "Alan's App" with a calendar UI. Each server is connected to the app with distinct key/token labels, illustrating separate credential sets per issuer.
Your client_secret is effectively a password for the app. If the same secret is shared across issuers, either issuer could impersonate the client at the other issuer — never reuse secrets across independent authorization servers.

Token audience and minimal privileges

Access tokens include an aud (audience) claim that identifies the intended resource server:
Only the audience in the token should accept and honor it. Tokens also encode what the client is allowed to do (scopes) and how long the token is valid. Example token fields:
Follow the principle of least privilege: give tokens as little power and lifetime as necessary. The most useful protections are summarized below.
Never include access tokens in URLs or query strings (for example https://calendar.example.com/events?token=...). Put them in Authorization headers instead.

Refresh tokens and rotation

When an access token expires, the app uses a refresh token to get a new access token. Because refresh tokens are longer-lived and powerful, they should be stored securely on the device and rotated: issue a new refresh token on each refresh and invalidate the previous one. Rotation reduces the usefulness of a stolen refresh token.

Preventing code interception with PKCE

An attacker on the device could try to intercept the authorization code before the legitimate app redeems it. PKCE (pronounced “pixie”) defends against that attack:
  • The client generates a random code_verifier before starting the authorization request.
  • The client derives a code_challenge from the verifier and includes it in the initial request.
  • When the code is exchanged at the token endpoint, the client must present the original code_verifier. The authorization server matches it to the earlier code_challenge.
PKCE binds the authorization code to the client that started the flow and is required for every client.
PKCE prevents code interception by binding the authorization code to the app that started the flow via a code_challenge / code_verifier pair.
An illustration titled "Protecting the Code" shows Alan's Phone with a legitimate app and a malicious app. A token tag labeled "Sp1x10BeZQ" links the phone to an Authorization Server on the right.

Redirect URI exact matching

The redirect URI returned by the authorization server must match the value registered for the client exactly, character-for-character:
Subtle differences (trailing slashes, different schemes, or different hostnames) can open security holes.

Deprecated and removed flows

Because of credential exposure risks, certain older flows are no longer recommended or are removed from best practice: Use the authorization code flow with PKCE (OAuth 2.1 guidance) instead.

Roots vs. the real enforcement boundary

When clients are autonomous (for example, an agent driven by an LLM), they cannot predict every future request. The protocol allows the client to present a Roots list that indicates the paths and hosts it intends to access (for example /alan/calendars, /alan/photos, api.example.com). Roots are useful as intent and for UX, but they are not the hard enforcement mechanism.
A stylized infographic titled "Roots and the Real Boundary" showing a phone labeled "Alan's Agent" on the left, a central "Roots List" with entries like /alan/calendars, /alan/photos and api.example.com, and a "Calendar Server" on the right. A key-like token badge appears above, linking the components.
The true enforcement boundary is the token itself: the aud and scope claims determine what the agent may actually access. If the token says aud: calendar.example.com and scope: read:calendar, then attempts to access a photo server or perform writes outside the token’s scopes will fail.
Later sections will detail the specification’s warnings about name-based attacks and other adversarial techniques. For implementation details and platform-specific guidance, consult the authorization server’s documentation and the OAuth working group publications.

Watch Video