Markdown

PKCE

PKCE is the Acronym for Proof Key for Code Exchange

An extension to the OAuth 2.0 authorization code flow, defined in IETF RFC 7636 and pronounced pixy. It prevents an attacker who intercepts an authorization code from exchanging it for tokens. Originally designed for mobile apps that cannot keep a client secret, The OAuth 2.1 draft makes PKCE mandatory for the authorization code grant, including server-side web apps.

How PKCE Works

  • Code Verifier: The client generates a high-entropy random string and keeps it private.
  • Code Challenge: The client sends a SHA-256 hash of the verifier with the authorization request.
  • Token Exchange: When redeeming the code, the client sends the original verifier, and the server checks that it hashes to the challenge.
  • Result: An intercepted code is useless without the verifier.

Where PKCE Is Required

  • Single-Page Applications: Browser apps cannot store secrets securely.
  • Native and Mobile Apps: Custom URL schemes can be hijacked by malicious apps.
  • OIDC Logins: Identity providers increasingly require PKCE for every authorization code request.

Challenge Methods

MethodDescriptionRecommendation
S256SHA-256 hash of the verifierUse this
plainVerifier sent unhashedProhibited by the OAuth 2.1 draft

Articles Tagged PKCE

View Additional Articles Tagged PKCE