Skip to content
BENIBIX Learn

Proof Key for Code Exchange (PKCE)

Development🔑 AuthAuthorization

Also known as PKCE, Code Challenge, Code Verifier, OAuth PKCE

An extra check in OAuth. A stolen code does not work without the app's secret.

Think of it like

Think of it like a coat check. You keep half the ticket, so only you can get the coat back.

Example

Emma's phone app starts a login with a PKCE challenge. A bad app on the same phone grabs the code on its way back. It cannot swap it, because it never saw the secret.

Why it matters

Without it, any app that catches the code on its way back can turn it into a token.

Definition

PKCE is an extra step in the OAuth 2.0 code flow. Before the flow starts, the app makes a random secret and keeps it. It sends only a hash of that secret with the first request. To swap the code for an access token, it must show the secret itself. So a code stolen on its way back is useless to anyone else. Phone apps and apps that run in a browser must use it.

Example code

http
GET /authorize?response_type=code&client_id=shop-app&code_challenge=E9Melhoa2OwvFrEMTJguCHaoeK1t8URWbuGJSstw-cM&code_challenge_method=S256 HTTP/1.1
The challenge is the hash of a secret the app keeps. S256 says the hash is SHA-256.
PKCE adds the challenge in step 1 and the secret in step 4, the lit-up swap.

Common mistake

Thinking PKCE is only for phone apps. The 2025 advice says apps with a server should use it too.

Key takeaways

  1. 1
    Secret kept. The app makes it and keeps it.
  2. 2
    Hash sent first. Only the hash goes out.
  3. 3
    Proof at the swap. The code needs the secret.