The Authorization Code flow is an OAuth 2.0 grant type where a client application exchanges an intermediate authorization code for a secure access token. This multi-step process begins when the application redirects the user to an authorization server to authenticate and grant consent. The server then returns a short-lived, single-use authorization code to the client via the user's browser. This code is not a credential itself but a reference that must be exchanged server-side, preventing direct exposure of the final token to the public client or end-user.
Glossary
Authorization Code Flow

What is Authorization Code Flow?
The Authorization Code flow is the primary OAuth 2.0 grant type for server-side applications, designed to securely obtain access tokens while keeping them confidential.
The client application subsequently sends this code, along with its own client credentials, directly to the authorization server's token endpoint via a secure back-channel request. In exchange, the server returns an access token and often a refresh token. This separation of the front-channel user redirection from the back-channel token exchange is the flow's core security mechanism, making it the standard for web applications with a server-side component capable of securely storing a client secret.
Key Features and Security Properties
The Authorization Code flow is the most secure and widely used OAuth 2.0 grant for server-side applications. Its design separates the user authentication and consent step from the actual token issuance, protecting sensitive credentials.
Two-Stage Token Exchange
The core security mechanism involves a two-stage handshake. First, the client receives a short-lived authorization code via the user's browser. Second, the server-side client exchanges this code for the access token and refresh token via a secure, back-channel request using its client secret. This prevents the access token from ever being exposed to the browser or end-user.
- Stage 1 (Front-Channel): User authenticates, grants consent, and an authorization code is returned via redirect.
- Stage 2 (Back-Channel): Client exchanges code + secret for tokens directly with the authorization server.
Confidential Client Requirement
This flow is explicitly designed for confidential clients—applications capable of securely storing a client secret. The secret is used to authenticate the client to the authorization server during the code-for-token exchange. This requirement distinguishes it from flows for public clients (like SPAs or mobile apps) and is fundamental to its security model.
- Examples: Traditional web applications with a server-side backend component (e.g., Python/Django, Java/Spring, Node.js).
- Security Implication: The client secret never leaves the protected server, preventing theft from a user's device.
Mitigation of Token Leakage
By keeping the access token off the front-channel (user's browser), the flow inherently protects against several common web threats. The authorization code itself has limited value without the client secret.
- Browser History/Logs: The access token is not written to browser history via URL parameters.
- Referrer Headers: The token is not leaked to other sites via the HTTP Referer header.
- Intermediate Proxies: The token is not visible to any proxies between the user and the client app, as it is transmitted server-to-server.
PKCE Extension for Public Clients
While designed for confidential clients, the flow can be secured for public clients (like mobile and single-page apps) using the Proof Key for Code Exchange (PKCE) extension. PKCE adds a cryptographically bound key to the flow, preventing authorization code interception attacks.
- Code Verifier: A high-entropy random string created by the client.
- Code Challenge: A transformed version (e.g., SHA256 hash) of the verifier, sent with the initial authorization request.
- Binding: The original verifier must be presented when exchanging the code for the token, proving the same client initiated the request.
Refresh Token Support
The Authorization Code flow is the primary OAuth 2.0 grant where refresh tokens are commonly issued. This allows applications to obtain new access tokens after the short-lived one expires without requiring the user to log in again, providing a seamless user experience while maintaining security.
- Long-Lived Sessions: Refresh tokens enable persistent sessions (e.g., "Keep me signed in").
- Reduced Credential Exposure: The user's password is not re-entered frequently.
- Revocability: Refresh tokens can be individually revoked by the authorization server if compromised.
Foundation for OpenID Connect
This flow forms the backbone of OpenID Connect, the identity layer on top of OAuth 2.0. When used with the openid scope, the authorization server returns both an access token and an ID token (a signed JWT containing user identity claims). This enables secure authentication and standardized user profile access in addition to authorization.
- Single Sign-On (SSO): Enables federated identity across multiple applications.
- Standardized Claims: Provides a consistent way to retrieve user information like email and name.
- Hybrid Flows: Can be combined with other response types (e.g.,
code id_token) for optimized performance.
Frequently Asked Questions
Essential questions and answers about the OAuth 2.0 Authorization Code Flow, the standard protocol for secure user authorization in server-side applications.
The Authorization Code Flow is the primary OAuth 2.0 grant type designed for server-side web applications where a client exchanges a short-lived authorization code for a long-lived access token and refresh token, keeping sensitive credentials off the client-side. The flow works in distinct phases: 1) The user is redirected to the authorization server to authenticate and consent. 2) The server redirects back with a one-time-use authorization code. 3) The server-side application exchanges this code, along with its client secret, for tokens via a secure back-channel request. This separation ensures the access token is never exposed to the user's browser or the public client, providing a critical security layer for accessing user data on APIs like Google, GitHub, or enterprise systems.
Authorization Code Flow vs. Other OAuth 2.0 Grants
A feature and security comparison of the primary OAuth 2.0 grant types, highlighting the appropriate use cases for each in AI agent and backend system integrations.
| Feature / Characteristic | Authorization Code Flow | Client Credentials Flow | Resource Owner Password Credentials Flow | Implicit Flow (Deprecated) |
|---|---|---|---|---|
Primary Use Case | Server-side web applications where the client secret can be securely stored | Machine-to-machine (M2M) communication, service accounts, backend APIs | Migration of legacy applications (highly discouraged for new projects) | Single-page applications (SPAs) - Now replaced by Authorization Code Flow with PKCE |
User Authentication Required | ||||
Client Authentication Required | ||||
Access Token Exposure Location | Backend server only (never in user agent) | Backend server only | Backend server only | User's browser (public client) |
Issues Refresh Token | ||||
Recommended for AI Agents / Backend Services | ||||
Security Against Token Interception | High (token returned to backend via direct POST) | High (direct server-to-server) | Medium (depends on client security) | Low (token exposed in URL fragment) |
PKCE (Proof Key for Code Exchange) Support | Required for public clients, recommended for all | Not applicable | Not applicable | Not applicable |
OAuth 2.0 Security Best Practices Compliance | Full | Full | Partial (discouraged) | Low (deprecated) |
Typical Token Lifetime | Short (minutes to hours) | Short to medium (hours) | Short (minutes to hours) | Very short (minutes) |
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Related Terms
The Authorization Code Flow is a core component of the OAuth 2.0 framework. These related terms define the other actors, tokens, and security mechanisms that interact with this flow.
OAuth 2.0
OAuth 2.0 is the overarching authorization framework that defines the Authorization Code Flow. It is an industry-standard protocol that allows third-party applications to obtain limited access to a user's resources on an HTTP service without ever handling the user's credentials.
- Provides the architectural blueprint for all grant types (flows).
- Delegates user authentication to the service hosting the user account.
- Separates the role of the client from the resource owner.
Access Token
An Access Token is the credential obtained by the client application at the end of the Authorization Code Flow. It is a string (often a JWT) that represents the authorization granted to the client.
- Bearer Token: The most common type, where possession of the token grants access.
- Contains scopes defining the permissions granted.
- Has a limited lifetime, requiring refresh or re-authentication.
- Presented to the Resource Server to access protected APIs.
Authorization Server
The Authorization Server is the central OAuth 2.0 component that orchestrates the Authorization Code Flow. It authenticates the user, obtains consent, and issues tokens.
Key responsibilities:
- Hosts the
/authorizeand/tokenendpoints. - Validates the client's identity (Client Authentication).
- Issues Access Tokens and Refresh Tokens.
- May provide a Token Introspection endpoint for resource servers to validate tokens.
Proof Key for Code Exchange (PKCE)
PKCE (pronounced 'pixie') is a critical security extension to the Authorization Code Flow, designed to protect public clients (like mobile and single-page apps) from authorization code interception attacks.
Mechanism:
- Client creates a cryptographically random code verifier.
- Derives a code challenge and sends it with the initial authorization request.
- Later, when exchanging the code for a token, the client must present the original code verifier.
- The authorization server verifies the challenge matches the verifier.
- RFC 7636 defines the standard.
Scope
A Scope is a mechanism in OAuth 2.0 that limits an application's access to a user's account. During the Authorization Code Flow, the client requests specific scopes, and the user consents to them.
- Represented as a space-separated list of strings (e.g.,
read:contacts write:calendar). - Defines the permissions embedded in the resulting Access Token.
- Enables the principle of least privilege by granting only the access needed.
- Resource servers must validate that the token's scopes permit the requested action.
OpenID Connect (OIDC)
OpenID Connect is an identity layer built on top of the OAuth 2.0 Authorization Code Flow. It adds authentication semantics, allowing the client to verify the user's identity.
Extends the flow by:
- Returning an ID Token (a signed JWT) alongside the Access Token.
- The ID Token contains claims about the authenticated user (e.g.,
sub,email). - Standardizes userinfo endpoints to fetch profile data.
- Transforms OAuth from pure authorization into a full federated identity protocol.

About the author
Prasad Kumkar
CEO & MD, Inference Systems
Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.
His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us