OAuth 2.0 Flows and Token Types
Compare authorization code, implicit, client credentials, and device flows — and when to use each.
OAuth 2.0 Flows and Token Types is a free Cryptology Academy lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Cryptology Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
OAuth 2.0 Core Roles
OAuth 2.0 defines four roles. The Resource Owner is the user who owns data (e.g., their Google Drive files). The Client is the application requesting access. The Authorization Server issues access tokens (e.g., Google's OAuth server). The Resource Server hosts the protected data (e.g., Google Drive API). Understanding these roles clarifies each flow's purpose.
Authorization Code Flow
The authorization code flow is the correct flow for server-side web applications. The user authenticates at the authorization server, which redirects to the client with a short-lived authorization code. The client's server exchanges this code for tokens via a back-channel request. Tokens never pass through the browser, protecting them from browser history and referrer leakage.
Implicit Flow: Deprecated
The implicit flow was designed for browser-only JavaScript applications that could not securely store client secrets. Tokens were returned directly in the URL fragment, bypassing the back-channel. The implicit flow is deprecated in OAuth 2.1 because PKCE (RFC 7636) allows public clients to use the authorization code flow securely without a client secret.
Resource Owner Password Credentials
The ROPC flow allows clients to collect the user's username and password directly and exchange them for tokens. This was intended for highly trusted first-party clients but fundamentally defeats OAuth's purpose of preventing apps from seeing user credentials. It is deprecated in OAuth 2.1 and should not be used in any new application.
Client Credentials Flow
The client credentials flow is for machine-to-machine (M2M) authentication where no user is involved. The client authenticates directly to the authorization server using its client ID and secret, receiving an access token for its own use. Common use cases: background jobs, microservice-to-microservice communication, API gateways accessing backend services.
Device Authorization Flow
The device authorization flow (RFC 8628) enables OAuth on devices with limited input capabilities: smart TVs, game consoles, printers, and IoT devices. The device displays a short code and URL. The user visits the URL on a phone or computer to authorize. The device polls the authorization server until the user completes authorization.
Access Token Types
OAuth 2.0 defines two access token types. Opaque tokens are random strings that the resource server validates by calling the authorization server's introspection endpoint. JWT access tokens are self-contained: the resource server can validate them locally by verifying the signature, reducing introspection API calls but requiring key management.
Refresh Tokens and Rotation
Refresh tokens are long-lived credentials used to obtain new access tokens after the access token expires. Refresh token rotation (required in OAuth 2.1 for public clients) issues a new refresh token with each use and invalidates the old one. If a stolen refresh token is used, the legitimate client detects the invalidation, enabling detection of token theft.
Token Introspection
RFC 7662 defines the token introspection endpoint, which allows resource servers to query the authorization server about an opaque access token's current status (active/inactive), scope, subject, and expiry. Introspection enables real-time token revocation: once a token is revoked at the authorization server, introspection calls immediately return active: false.
Token Revocation
RFC 7009 defines the token revocation endpoint, allowing clients to notify the authorization server that a token (access or refresh) should be invalidated. This is used during logout or when a client detects suspicious activity. JWT access tokens cannot be fully revoked without a revocation list, because resource servers validate them locally without contacting the authorization server.
Scope-Based Authorization
OAuth 2.0 scopes define the specific permissions the client is requesting. The authorization server presents the requested scopes to the user for approval. Resource servers enforce scope requirements per endpoint. Principle of least privilege applies: clients should request only the minimum scopes needed, and resource servers should reject requests with insufficient scope.
OAuth 2.0 Flows Check
Which OAuth 2.0 flow is appropriate for a CLI tool or IoT device that needs to authenticate a user but has no browser or keyboard?
Lesson Recap: OAuth 2.0 Flows
Authorization code flow is correct for server-side apps. Implicit flow is deprecated (use PKCE instead). ROPC flow is deprecated (eliminates OAuth's purpose). Client credentials serves M2M. Device authorization handles input-limited devices. Access tokens are opaque or JWT. Refresh tokens should rotate. Introspection (RFC 7662) and revocation (RFC 7009) complete the token management picture.
Frequently asked questions
Is the “OAuth 2.0 Flows and Token Types” lesson free?
Yes — the full text of “OAuth 2.0 Flows and Token Types” is free to read here on the web, and the Cryptology Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Cryptology Academy course, upgrade to CoddyKit PRO.
What will I learn in “OAuth 2.0 Flows and Token Types”?
Compare authorization code, implicit, client credentials, and device flows — and when to use each. You practise Cryptology Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Cryptology Academy?
No prior experience is required. Cryptology Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “OAuth 2.0 Flows and Token Types” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Cryptology Academy lesson?
Yes. Every Cryptology Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- OAuth 2.0 Flows and Token Types
- PKCE: Securing Public Clients
- OpenID Connect Claims and ID Tokens
- OAuth Vulnerabilities and Attack Patterns