liveBook · Manning

Proof Key for Code Exchange

As explained in Spring Security in Action, Second Edition

Proof key for code exchange is an OAuth extension that binds an authorization-code exchange to a client-generated secret to mitigate code interception.

Proof Key for Code Exchange (PKCE, pronounced “pixy”) strengthens the OAuth authorization code flow when an attacker might steal client credentials or an authorization code. It binds the token request to the same client that initiated user authentication. section 13.3.2

Apply PKCE across two authorization-code steps:

  • Generate a random value called the verifier. section 13.3.2
  • Hash the verifier to produce the challenge, then send the challenge with the user-login request. section 13.3.2
  • Send the verifier when requesting the access token; the authorization server compares it with the stored challenge. section 13.3.2
  • Reject the exchange when the verifier does not match, preventing a stolen authorization code alone from producing an access token. section 13.3.2
verifier = random();
challenge = hash(verifier);

A compact pseudocode listing captures the essential relationship: the client sends the hash-derived challenge first and the verifier later. section 13.3.2

How Spring Security in Action, Second Edition covers it

How deep it goes
Explains verifier generation, challenge hashing, request placement, and authorization-server comparison without framework implementation details.
Examples
Uses random verifier and hash-derived challenge pseudocode, plus the two PKCE message steps.
What it assumes
Assumes familiarity with the authorization code grant type and its authorization and token-request steps.
What you can do after
Apply it by generating a verifier, sending its challenge during login, and presenting the verifier during token exchange.
How it connects
Connects OAuth, the authorization code grant type, authorization servers, authorization codes, and access tokens.

Also explained in

Compare how 5 books explain Proof Key for Code Exchange →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Spring Security in Action, Second Edition. The section links point to the parts of the book it draws on.