Proof Key for Code Exchange
Proof Key for Code Exchange (PKCE) is a security extension to the OAuth 2.0 authorization code flow that helps prevent attackers from stealing and misusing the temporary authorization code exchanged during login. It works by having the application create a secret value up front and later prove it holds that same secret when redeeming the code, so an intercepted code cannot be used by anyone else.
PKCE, defined in RFC 7636, is an extension to the OAuth 2.0 authorization code grant that mitigates authorization code injection and, per some sources, CSRF attacks against the flow. The client generates a high-entropy random value called the code verifier and derives a code challenge from it (typically via a transform such as S256); the code challenge is sent on the initial authorization request, and the original code verifier is sent when exchanging the authorization code for tokens at the token endpoint, allowing the authorization server to confirm the same client that initiated the request is redeeming the code. It was originally introduced to strengthen public clients that cannot securely store a client secret, though it is recommended for OAuth clients more broadly; note that PKCE is an authorization-flow protection and is not itself an authentication mechanism. Exact behavior, such as supported challenge methods, depends on the authorization server and deployment configuration.
Why it matters
The OAuth 2.0 authorization code flow relies on a short-lived authorization code that is returned to the client via a redirect and then exchanged at the token endpoint for tokens. If an attacker can intercept that authorization code, through a malicious app registered to the same redirect URI, a compromised inter-app communication channel on a mobile device, or logging and referrer leakage, they may attempt to redeem it for tokens. PKCE, defined in RFC 7636, closes this gap by binding the code to a secret that only the legitimate client possesses, so an intercepted code cannot be redeemed by another party. According to the OAuth community documentation, PKCE prevents authorization code injection and CSRF attacks in the authorization code flow.
PKCE was originally introduced to strengthen public clients, such as native mobile and single-page applications, that cannot securely store a client secret, and it remains especially important there. However, current guidance (per oauth.net) recommends PKCE for OAuth clients more broadly, not only public ones, because the authorization code injection threat is not unique to secret-less clients. Treating PKCE as a default protection for the authorization code grant rather than a niche public-client feature reflects where mainstream practice has moved.
It is worth being precise about scope: PKCE is an authorization-flow protection, not an authentication mechanism. It does not verify who the user is; it ensures that the entity redeeming the authorization code is the same one that initiated the request. Deployments that need user authentication still layer OpenID Connect on top of OAuth 2.0. Exact behavior, including which challenge transforms are supported, depends on the authorization server and deployment configuration.
Who it's relevant to
Inside PKCE
Common questions
Answers to the questions practitioners most commonly ask about PKCE.
