Why it matters
Delegating access without sharing a password requires a protocol with several parties: the client, the authorisation server and the resource server. Each has a different trust level, and the tokens are scoped to a party and a purpose. Implementations fail when they conflate those purposes, for example by accepting an access token as an identity assertion, or by shipping a client secret in a mobile app that anyone can decompile.
Mental model
It is a coat check: you get a ticket for your coat, and the ticket is only good at that counter. The analogy breaks because OAuth has several kinds of ticket with different audiences, and presenting the wrong kind at the wrong counter is exactly how implementations get breached.
How it works
- 1Choose the flow by client type: authorisation code with proof key exchange for public clients, and never the implicit flow.
- 2Request the minimum scopes, and treat scope as the authorisation contract with the resource server.
- 3Validate the ID token signature, issuer, audience, expiry and nonce before trusting any claim.
- 4Keep access tokens opaque to the client, and send them only to the resource server they were issued for.
- 5Rotate refresh tokens on use and revoke the family when a reused token is detected.
- 6Validate redirect URIs exactly, and reject any that are not pre-registered.
Step 1 of 6
Choose the flow by client type: authorisation code with proof key exchange for public clients, and never the implicit flow.
Figure. The mechanism in this page's own steps. The figure adds sequence, not new claims.
What to notice. A step can be read alone, but the order is the mechanism. The control lets you stop on any one.
Text version
The page's steps: 1. Choose the flow by client type: authorisation code with proof key exchange for public cli… 2. Request the minimum scopes, and treat scope as the authorisation contract with the resour… 3. Validate the ID token signature, issuer, audience, expiry and nonce before trusting any c… 4. Keep access tokens opaque to the client, and send them only to the resource server they w… 5. Rotate refresh tokens on use and revoke the family when a reused token is detected. 6. Validate redirect URIs exactly, and reject any that are not pre-registered.
- Choose the flow by client type: authorisation code with proof key exchange for public clients, and never the implicit flow.
- Request the minimum scopes, and treat scope as the authorisation contract with the resource server.
- Validate the ID token signature, issuer, audience, expiry and nonce before trusting any claim.
- Keep access tokens opaque to the client, and send them only to the resource server they were issued for.
- Rotate refresh tokens on use and revoke the family when a reused token is detected.
- Validate redirect URIs exactly, and reject any that are not pre-registered.
Trade-offs
| Choice | Good for | Cost | Fails when |
|---|---|---|---|
| Authorisation code with proof key | Safe for public and confidential clients | More round trips and state handling | The client cannot open a browser |
| Client credentials | Machine-to-machine access | No user context | The action must be attributed to a person |
| Short access token | Limited exposure | More refresh traffic | The client cannot store a refresh token securely |
| Long-lived token | Fewer moving parts | A stolen token is usable for a long time | The token is held in a browser or device |
Good for
Safe for public and confidential clients
Cost
More round trips and state handling
Fails when
The client cannot open a browser
- The client cannot open a browser
- The action must be attributed to a person
- The client cannot store a refresh token securely
- The token is held in a browser or device
Figure. Each choice with what it buys, what it costs, and the case where it loses.
What to notice. The fourth column is the decision: if the losing case describes your situation, the choice is wrong.
Text version
Four trade-offs: Authorisation code with proof key is good for Safe for public and confidential clients, costs More round trips and state handling, and fails when The client cannot open a browser. Client credentials is good for Machine-to-machine access, costs No user context, and fails when The action must be attributed to a person. Short access token is good for Limited exposure, costs More refresh traffic, and fails when The client cannot store a refresh token securely. Long-lived token is good for Fewer moving parts, costs A stolen token is usable for a long time, and fails when The token is held in a browser or device
Failure modes
- Access token used as identity. A token minted for an API is accepted as proof of who the user is. Debug: list every place identity is read and confirm it comes from an ID token or a userinfo call.
- Missing state or nonce. An attacker can inject a code or replay a token into the callback. Debug: assert the authorisation request includes state and nonce and that both are verified.
- Open redirect URI. A wildcard redirect sends codes to an attacker-controlled host. Debug: diff registered redirect URIs against exact matches and fail on any pattern.
In production
Monitor token issuance, refresh failures and reuse detection, and alert on a spike in reuse, which usually means a token was stolen. Keep the signing keys rotated with an overlap so validation never fails during a rollover.
Common misconceptions
People think: OAuth is a login protocol.
Actually: OAuth delegates access; identity comes from OpenID Connect and the ID token.
People think: A client secret makes a mobile app confidential.
Actually: Anything shipped to a device can be extracted, which is why public clients rely on proof key exchange instead of a secret.
Interview angle
Separate the two tokens by audience and purpose, pick the flow from the client type, and list the validation checks. Mention refresh rotation and exact redirect matching. A login button described as OAuth is not an answer.
Sources
- RFC 6749, The OAuth 2.0 Authorization Framework — grant types, tokens and client types.
- OpenID Connect Core 1.0 — ID token validation and the identity layer.
- RFC 7636, PKCE — proof key for code exchange in public clients.