Understanding OAuth 2.0
Date: June 08, 2026
Overview
OAuth 2.0 is an authorization framework that allows a client (app) to obtain limited access (tokens) to a resource server on behalf of a resource owner (user). This is achieved using an authorization server to issue tokens.
Key Actors
- Resource Owner: The user.
- Client: The application requesting access.
- Authorization Server: Issues authorization grants and tokens.
- Resource Server: Hosts protected APIs and accepts access tokens.
Core Concepts
- Authorization Grant: A credential representing the resource owner’s permission (there are several grant types).
- Access Token: A short-lived credential the client presents to the resource server (usually a bearer token).
- Refresh Token: A long-lived token used to obtain new access tokens without user interaction.
Main Grant Types (Flows)
- Authorization Code (recommended for web & native apps): Involves a browser-based redirect to the auth server, yielding an authorization code, followed by a server-side token exchange. This is safe because tokens travel server-to-server. Use with PKCE for public clients.
- Authorization Code + PKCE: Adds a
code_challenge and code_verifier to prevent code interception. This is required for many clients under modern best practices.
- Client Credentials (machine-to-machine): The client authenticates with its own credentials to get tokens for its own resources (no user involved).
- Device Code: Used for devices without browsers or with limited input, where the user completes authorization on another device.
- Refresh Token Grant: Exchanges a refresh token for a new access token when the current access token expires.
Authorization Code Flow Diagram
sequenceDiagram
participant U as Resource Owner (User)
participant C as Client (App)
participant A as Authorization Server
participant R as Resource Server
U->>C: Access Application
C->>U: Redirect to Authorization Server
U->>A: Authenticate and Authorize
A-->>U: Redirect to Client with Auth Code
U->>C: Follow Redirect with Auth Code
C->>A: Exchange Auth Code for Access Token
A-->>C: Access Token (+ Refresh Token)
C->>R: Request Resource with Access Token
R-->>C: Protected Resource
Deprecated Flows
- Implicit: Tokens are returned in URL fragments.
- Resource Owner Password Credentials: The client collects the user’s password directly.
Both are discouraged and removed in OAuth 2.1 due to security risks.
Security Considerations & Best Practices
- Always use TLS.
- Prefer Authorization Code + PKCE for apps that cannot keep secrets.
- Use short-lived access tokens and rotate refresh tokens (or use sender-constrained tokens).
- Perform exact
redirect_uri matching and validate the state parameter to prevent CSRF.
- Never place bearer tokens in URLs (e.g., as a query string parameter).
Typical HTTP Examples
Authorization Request (Browser Redirect)
GET /authorize?response_type=code&client_id=...&redirect_uri=...&scope=...&state=...
Token Exchange (Server POST)
POST /token grant_type=authorization_code&code=...&redirect_uri=...
(The client authenticates) → Returns access_token, token_type, expires_in, and optionally refresh_token.
Implementation Resources
Use RFC 6749 for the protocol details, oauth.net for practical guidance and extensions (like PKCE, device flow, and OAuth 2.1 updates), and adhere to current security BCPs (Best Current Practices) when implementing.
Related Articles
References
- RFC 6749
- oauth.net
- Modern Security BCPs