Proof Key for Code Exchange (PKCE) strengthens OAuth authorization code exchange for public clients such as mobile apps, web apps, and IoT devices. It addresses a practical risk: an attacker intercepts an authorization code and uses it to obtain an access token. section 13.1 section 13.6
PKCE adds a short proof-of-possession sequence to the authorization flow:
- The client creates an unpredictable random value called the code verifier. section 13.1
- The client hashes the verifier, commonly with SHA-256, to create the code challenge. section 13.1
- The client sends the challenge when redirecting the user for authentication. section 13.1
- When exchanging the authorization code for tokens, the client presents the original verifier. section 13.5
- The authorization server can reject an intercepted code because an attacker has the challenge or code, but not the verifier. section 13.1 section 13.5
A stolen authorization code
A mobile shopping app authenticates a user, who then receives an authorization code. Without PKCE, someone who intercepts that code might exchange it for access to the user's protected shopping resources. With PKCE, the interceptor also needs the client's unpredictable verifier, which was not exposed through the challenge. section 13.1 section 13.5




