Proof Key for Code Exchange (PKCE) is an OAuth 2.0 security extension that mitigates authorization code interception attacks by having the client create and verify a cryptographically random key. In the PKCE-enhanced Authorization Code flow, the client generates a secret, one-time code verifier and a derived code challenge. It sends the challenge with the initial authorization request and later must present the matching verifier to exchange the received authorization code for an access token. This mechanism prevents a stolen authorization code from being used by a malicious actor.
Glossary
Proof Key for Code Exchange (PKCE)

What is Proof Key for Code Exchange (PKCE)?
Proof Key for Code Exchange (PKCE, pronounced 'pixie') is a critical security extension to the OAuth 2.0 Authorization Code flow, specifically designed to protect public clients like mobile and single-page applications from authorization code interception attacks.
PKCE is essential for public clients—applications that cannot securely store a client secret, such as native mobile apps and single-page applications (SPAs) executing in a user's browser. It is formally defined in RFC 7636 and is now a mandatory requirement for OAuth 2.0 public clients by best practice standards like OAuth 2.1. The protocol strengthens the security posture of AI agents and automated systems that must authenticate with external APIs without relying on a confidential client credential.
Key Features and Security Properties
Proof Key for Code Exchange (PKCE, pronounced 'pixie') is a critical extension to the OAuth 2.0 Authorization Code flow. It is designed to secure public clients—applications that cannot securely store a client secret, such as mobile apps and single-page applications (SPAs)—from authorization code interception attacks.
The Code Interception Attack
PKCE was created to mitigate a specific OAuth 2.0 vulnerability: the authorization code interception attack. In the standard Authorization Code flow, a malicious actor could potentially steal the short-lived authorization code as it is transmitted back to the client (e.g., via a malicious browser plugin or by logging the URI). If the attacker can intercept this code and use it before the legitimate client does, they can obtain an access token. PKCE makes this stolen code useless by cryptographically binding it to a secret only the legitimate client knows.
Code Verifier & Code Challenge
PKCE introduces two cryptographically linked values:
- Code Verifier: A high-entropy cryptographically random string created by the client. It is typically a 43-128 character string using characters
[A-Z] / [a-z] / [0-9] / "-" / "." / "_" / "~". - Code Challenge: A transformed version of the Code Verifier. The client sends this to the authorization server during the initial authorization request. The transformation is either a plain
S256(SHA-256 hash, Base64URL-encoded) orplain(no transformation).S256is mandatory for public clients in standards like OAuth 2.1. This pair creates a proof-of-possession mechanism for the authorization code.
The Two-Step Handshake
PKCE modifies the OAuth flow in two key steps:
- Authorization Request: The client generates a Code Verifier and derives a Code Challenge. It sends the Code Challenge (and the
code_challenge_method, e.g.,S256) to the authorization server along with the standard OAuth parameters. The server stores this challenge. - Token Request: When the client receives the authorization code, it makes the token request to the authorization server's token endpoint. This request must include the original Code Verifier. The server recalculates the Code Challenge from the provided verifier and compares it to the stored challenge. Only if they match is the authorization code considered valid, and an access token is issued.
Public Client Security
PKCE is fundamentally designed for public clients where the use of a static client secret is insecure. This includes:
- Native Mobile Applications: Code and resources can be decompiled, making embedded secrets insecure.
- Single-Page Applications (SPAs): All application code, including any client secret, is executed in the user's browser and is therefore publicly viewable.
- Desktop Applications: Similar to mobile apps, they cannot protect a secret from a determined user. For these clients, PKCE provides the missing proof-of-possession element that a client secret would provide for a confidential server-side application.
Mandatory in Modern Standards
Due to its critical security role, PKCE has evolved from a recommendation to a requirement in modern security profiles:
- OAuth 2.1: The in-progress revision of OAuth 2.0 makes PKCE mandatory for the Authorization Code flow for all clients, effectively deprecating the plain flow without PKCE.
- Financial-grade API (FAPI): This high-security profile mandates the use of PKCE with the
S256challenge method. - Major Identity Providers: Services like Auth0, Okta, Microsoft Identity Platform, and others strongly recommend or require PKCE for public client flows, and it is the default for their SDKs.
Relationship to Other Flows
PKCE is often discussed alongside other OAuth 2.0 extensions and best practices:
- Not a Replacement for Client Authentication: PKCE secures the code exchange but does not authenticate the client itself. For confidential clients, client authentication (e.g., client secret, private_key_jwt, mTLS) is still required at the token endpoint.
- Complementary to Refresh Tokens: PKCE protects the initial authorization code. If a refresh token is issued, it must also be protected, often by binding it to the client ID or using Refresh Token Rotation.
- Foundation for Advanced Flows: PKCE is a core component of newer, more secure patterns like the OAuth 2.0 Device Authorization Grant and is integral to BFF (Backend for Frontend) architectures that further isolate tokens from the browser.
Frequently Asked Questions
Proof Key for Code Exchange (PKCE, pronounced 'pixie') is a critical security extension to the OAuth 2.0 Authorization Code flow. These FAQs address its core mechanisms, use cases, and implementation details for developers building secure client-side and mobile applications.
Proof Key for Code Exchange (PKCE, RFC 7636) is a security extension to the OAuth 2.0 Authorization Code flow designed to prevent authorization code interception attacks, particularly in public clients like mobile and single-page applications (SPAs).
It works by having the client create a secret, the Code Verifier, and a derived transformation, the Code Challenge, before initiating the authorization request:
- The client generates a cryptographically random string called the
code_verifier. - It creates a
code_challengeby applying a transformation (S256 hash or plain) to the verifier. - The client sends this
code_challengeand the chosencode_challenge_methodto the authorization server during the initial authorization request. - After the user authenticates, the server returns an authorization code, binding it to the received challenge.
- When the client exchanges this code for an access token, it must present the original
code_verifier. - The authorization server recomputes the challenge from the verifier and only issues tokens if it matches the initially stored challenge. This proves the client exchanging the code is the same one that initiated the flow.
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
PKCE is a critical component within the broader OAuth 2.0 ecosystem. Understanding these related protocols and concepts is essential for implementing secure, modern authentication.
Authorization Code Flow
This is the primary OAuth 2.0 flow that PKCE enhances. It involves a two-step exchange where a short-lived authorization code is returned to the client and then exchanged server-side for an access token.
- Traditional Use: Designed for confidential clients (web servers with a backend) where the client secret can be stored securely.
- PKCE's Role: PKCE adds a layer of security to this flow for public clients (SPAs, mobile apps) that cannot keep a secret, protecting against authorization code interception attacks.
Client Authentication
This is the process by which an OAuth client proves its identity to the authorization server. PKCE provides an alternative mechanism for public clients that lack a traditional client secret.
- Methods: Client Secret, Private Key JWT, Mutual TLS.
- PKCE's Contribution: For public clients, the code verifier and code challenge serve as a form of proof-of-possession, binding the initial authorization request to the subsequent token request. This mitigates the risk of a stolen authorization code being used by a different client.
Bearer Token
The access token obtained via a PKCE-augmented flow is typically a Bearer Token, as defined in RFC 6750. Anyone in possession of this token (the "bearer") can use it to access associated resources.
- Security Implication: Because bearer tokens are so powerful, the security of the flow that issues them (like PKCE) is paramount.
- Usage: The token is included in the
AuthorizationHTTP header:Authorization: Bearer <token>. - PKCE's Role: PKCE ensures that the entity receiving the bearer token is the same one that initiated the authorization request.
OpenID Connect (OIDC)
OpenID Connect is an identity layer built on OAuth 2.0. It uses the same flows, including PKCE, but adds an ID Token (a JWT) to convey verifiable user authentication information.
- Primary Output: While OAuth gives you an access token for APIs, OIDC gives you an ID token for the user's identity.
- PKCE Usage: PKCE is a mandatory security requirement for OIDC Native Apps and Single Page Apps using the Authorization Code Flow. This is specified in the OIDC Core and OAuth 2.0 for Native Apps best practices documents.

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