Skip to content
AdminKit

PKCE (Proof Key for Code Exchange)

What is PKCE (Proof Key for Code Exchange)?

PKCE (Proof Key for Code Exchange), defined in RFC 7636, stops a stolen OAuth authorization code from being redeemed by anyone but the client that requested it -- mandatory for every client in OAuth 2.1. AdminKit's MCP server hardening checklist covers implementing the OAuth 2.1 flow PKCE belongs to.

By AdminKit team, Netbase JSC · Updated

PKCE (Proof Key for Code Exchange), defined in RFC 7636 — also tracked on its IETF Datatracker page — is an extension to the OAuth 2.0 authorization code flow that stops a stolen authorization code from being redeemed by anyone other than the client that requested it. OWASP’s OAuth 2.0 Cheat Sheet names this the same way: PKCE “is the technique used to mitigate against the threat of authorization code interception attack.” Before starting the flow, a client generates a random code_verifier and sends a derived code_challenge (its SHA-256 hash, base64url-encoded) in the initial authorization request; when it later exchanges the authorization code for a token, it must present the original code_verifier, and the authorization server only issues a token if hashing that verifier reproduces the earlier code_challenge. The authorization code itself is often exposed somewhere a client doesn’t fully control — a mobile OS’s shared redirect handling, a browser history entry, a proxy log — so without PKCE, anyone who intercepts that code could redeem it for a token before the legitimate client does; PKCE closes that gap because the code_verifier never travels alongside the code it’s redeemed with. PKCE was originally meant for public clients that can’t hold a client secret, such as mobile and single-page apps, but OAuth 2.1 makes it mandatory for every client, confidential or not, and the MCP authorization specification — itself built on OAuth 2.1 — requires it for the same reason. oauth.net’s PKCE page likewise recommends PKCE “for all OAuth clients — not just public clients,” noting that it also prevents authorization code injection and CSRF attacks. An authorization server advertises which code_challenge_method values it accepts — almost always S256, since the plain fallback offers little protection — in its OAuth 2.0 Authorization Server Metadata document.

AdminKit groups pKCE (Proof Key for Code Exchange) under its AI agents & MCP cluster — browse the AdminKit glossary index for other related terms.

Frequently asked questions

What attack does PKCE prevent?

A stolen OAuth authorization code being redeemed by anyone other than the client that originally requested it.

How does PKCE work?

A client generates a random code_verifier, sends a derived code_challenge in the initial authorization request, then must present the original code_verifier when exchanging the code for a token; the server only issues a token if hashing that verifier reproduces the earlier challenge.

Is PKCE mandatory in OAuth 2.1?

Yes -- for every client, confidential or not, beyond its original scope of just public clients that can't hold a secret.

Which RFC defines PKCE?

RFC 7636.