# Proof Key for Code Exchange (PKCE)

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

**Field:** Software Development  
**Category:** Auth  
**Also known as:** PKCE, Code Challenge, Code Verifier, OAuth PKCE

## Think of it like

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

## 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

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.

## 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.

## Why it matters

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

## Common mistake

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

## Three principles

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

## Related terms

- [OAuth 2.0](https://learn.benibix.com/term/development/oauth)
- [Access Token](https://learn.benibix.com/term/development/access-token)
- [OpenID Connect (OIDC)](https://learn.benibix.com/term/development/openid-connect)
- [Authorization](https://learn.benibix.com/term/development/authorization)

![Four boxes: you in a browser, the client app, the authorization server and the API. Numbered arrows show the code flow. 1, the client sends the browser to the authorization server with a scope and a PKCE challenge. 2, you log in and approve. 3, the browser returns to the client with a short code. 4, lit up, the client swaps the code and its PKCE secret for an access token, server to server. 5, the client calls the API with the token.](https://learn.benibix.com/diagrams/dev-oauth-flow.svg)

---

Source: https://learn.benibix.com/term/development/pkce
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-19
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
