What is pkce
Last updated: April 1, 2026
Key Facts
- PKCE prevents authorization code interception attacks by adding an additional cryptographic verification step
- It generates a random code verifier that is hashed into a code challenge sent during authorization
- PKCE is especially important for public clients that cannot securely store client secrets
- The mechanism matches the code challenge with the code verifier when exchanging the authorization code for tokens
- PKCE is now recommended for all OAuth 2.0 applications, not just mobile apps, due to its security benefits
Understanding PKCE
PKCE, pronounced "pixie," stands for Proof Key for Public Exchange. It is an extension to the OAuth 2.0 authorization framework designed to secure the authorization code flow, particularly for mobile applications and single-page applications (SPAs). PKCE adds an extra layer of cryptographic verification that prevents attackers from intercepting authorization codes and exchanging them for access tokens, a vulnerability that existed in standard OAuth 2.0 flows.
The Problem PKCE Solves
In standard OAuth 2.0 flows, a user authorizes an application to access their data at a service provider. The authorization server issues an authorization code, which the application exchanges for an access token. However, in certain scenarios—particularly with mobile apps and SPAs—an attacker could intercept the authorization code before the legitimate application uses it. The attacker could then exchange the code for an access token, gaining unauthorized access. PKCE prevents this attack by requiring cryptographic proof that the application requesting the token is the same application that originally requested the authorization code.
How PKCE Works
PKCE operates through a carefully designed process. First, the application generates a random string called a code verifier. The application then creates a code challenge by hashing the code verifier using SHA-256 (or using the plain text in rare cases). During authorization, the application sends the code challenge to the authorization server. When the user grants authorization, the authorization server issues an authorization code. Later, when the application exchanges the authorization code for tokens, it must provide the original code verifier. The authorization server verifies that the code verifier hashes to the previously submitted code challenge, confirming the request's legitimacy.
PKCE Implementation and Standards
PKCE is defined in RFC 7636 and has become a standard security practice endorsed by major organizations including the OAuth Security Best Current Practice. Implementation is straightforward: applications generate cryptographically random verifiers (43-128 characters), create challenge strings, and include them in authorization requests. Authorization servers verify the hashes match when tokens are requested. Modern OAuth libraries and SDKs typically include PKCE support built-in, making implementation accessible to developers.
PKCE for Different Application Types
While originally developed for mobile applications, PKCE is now recommended for all OAuth 2.0 applications, including traditional web applications. SPAs benefit from PKCE protection since they run in browsers where authorization codes are visible. Native mobile apps, which cannot securely store client secrets, gain essential protection through PKCE. Even traditional server-side web applications with secure backend storage now use PKCE as a security best practice, as it provides defense-in-depth against various attack vectors.
Related Questions
How does PKCE prevent authorization code interception?
PKCE prevents interception by requiring the application to prove it owns the authorization code. The application generates a random code verifier, hashes it into a code challenge sent upfront, then proves possession by providing the original verifier when exchanging the code. An attacker cannot complete this cryptographic proof without the original verifier.
What is the difference between OAuth 2.0 and PKCE?
OAuth 2.0 is a framework for authorization that allows users to grant applications access to their data. PKCE is a security extension to OAuth 2.0 that adds cryptographic verification to prevent authorization code interception attacks. PKCE enhances OAuth 2.0 security without changing its fundamental purpose or flow.
When should PKCE be used in development?
PKCE should be used in all OAuth 2.0 authorization code flows, particularly for mobile apps, single-page applications, and any public clients. It is now considered a security best practice recommended by OAuth working groups and is required by some major platforms and services for authorization requests.
More What Is in Daily Life
Also in Daily Life
More "What Is" Questions
Trending on WhatAnswers
Browse by Topic
Browse by Question Type
Sources
- RFC 7636 - Proof Key for Public OAuth 2.0 Authorization Code ExchangePublic Domain
- Wikipedia - OAuthCC-BY-SA-4.0
- OAuth 2.0 Security Best PracticesTerms of Service