OAuth2 Flows in Practice (Auth Code + PKCE)
On this page
Choose the Right Flow
- Browser SPA: Authorization Code + PKCE
- Server-side web app: Authorization Code
- Service-to-service: Client Credentials
- Devices: Device Code (when needed)
Production Checklist
- Strict redirect URI allowlist (no wildcards).
- Use PKCE for public clients.
- Scope minimization (least privilege).
- Short-lived access tokens + refresh token rotation.
Logging You Actually Need
Log fields: - client_id - grant_type - user_id (if present) - scopes granted - redirect_uri (normalized) - decision (allow/deny) + reason - token_id / session_id hash
Failure Modes
- Redirect URI abuse: token leakage → strict allowlist + normalize.
- Over-scoped tokens: breach blast radius → per-client scopes.
- No rotation: stolen refresh token persists → rotate + detect reuse.
Operational Test
Verify redirect rules: - attempt auth with unregistered redirect_uri - expect hard failure (no partial success)