PKCE
Proof Key for Code Exchange (RFC 7636): the OAuth client sends a hash of a one-time secret when it starts a sign-in and the secret itself when it redeems the code, so a stolen authorization code is useless to anyone else.
In the authorization code flow, the code travels through the browser back to the client's redirect URI. Anything that can see that redirect, such as another app on the same device that registered the same custom URL scheme, can grab the code. RFC 7636 was written for exactly that attack on public clients, which have no client secret to prove who they are at the token endpoint.
PKCE adds a proof that only the client that started the flow can give:
- The client makes a
code_verifier: a random string of 43 to 128 characters. - It sends
code_challenge = BASE64URL(SHA256(code_verifier))andcode_challenge_method=S256with the authorization request. - It sends the
code_verifieritself with the token request. - The authorization server hashes the verifier, compares it with the stored challenge, and answers
invalid_granton a mismatch.
The code alone is no longer enough; the thief would also need the verifier, which never left the client.
Example
The pair from RFC 7636's own example:
code_verifier = dBjftJeZ4CVP-mB92K27uhbUJU1p1r_wW1gFWFOEjXk
code_challenge = E9Melhoa2OwvFrEMTJguCHaoeK1t8URWbuGJSstw-cM
GET /authorize?response_type=code&client_id=...&code_challenge=E9Melhoa2OwvFrEMTJguCHaoeK1t8URWbuGJSstw-cM&code_challenge_method=S256&state=...
POST /token grant_type=authorization_code&code=...&code_verifier=dBjftJeZ4CVP-mB92K27uhbUJU1p1r_wW1gFWFOEjXkCommon confusion
plainis not a lighter S256. Withplainthe challenge is the verifier, so anyone who sees the authorization request has the secret. OAuth 2.1 says a client capable of S256 "MUST useS256".- PKCE is not only for mobile apps. RFC 7636 was written for public clients, but OAuth 2.1 says clients "MUST use
code_challengeandcode_verifier" in the code flow, apart from exceptions in its security section, and authorization servers must support them. - PKCE is not
state.stateties the response to the browser session that started it; PKCE ties the code to the client that will redeem it. MCP clients should use both.
MCP goes one step further: since OAuth gives no other way to learn whether a server supports PKCE, an MCP client must refuse to continue when the authorization server's metadata has no code_challenge_methods_supported.
In L2M
Every OAuth connection to a remote MCP server uses S256 with a fresh verifier, and L2M refuses an authorization server whose metadata does not list S256. The verifier stays in the pending authorization on the API, keyed by a single-use state, and is sent only with the token request. L2M's own OIDC sign-in uses the same method, with state and nonce; its verifier is kept in a short-lived encrypted login cookie. With no client secret set, PKCE alone protects the code.