1. [Home](https://quorumauth.com/) /
2. [Learn](https://quorumauth.com/learn/) /
3. What is PKCE?

Learn · QuorumAuth

# What is PKCE?

> PKCE stops a stolen OAuth authorization code from being redeemed by anyone but the app that asked for it. How RFC 7636 works, step by step.

PKCE, Proof Key for Code Exchange, is an OAuth 2.0 extension that ties an authorization code to the client that requested it.

Updated October 24, 2026

Picture leaving your coat at a cloakroom. You keep a secret word, and the attendant writes on your ticket only a scrambled version of it that cannot be unscrambled. If someone steals the ticket, they still cannot collect your coat, because only you can say the word that scrambles into what is written.

On this page

1. How PKCE works
2. PKCE with and without
3. When to use PKCE
4. Pitfalls
5. How QuorumAuth handles PKCE

The authorization code flow with PKCE

1. 1 App → App Make verifier SHA-256 of it = challenge
2. 2 App → Authorization server Send the challenge
3. 3 Authorization server → Authorization server Store challenge
4. 4 Authorization server → App Code via redirect Interceptable here
5. 5 App → Authorization server Code and verifier
6. 6 Authorization server → Authorization server Hash verifier, compare
7. 7 Authorization server → App Tokens only on a match

The app creates a random code verifier and derives the challenge as the SHA-256 hash of it. It sends the challenge in the authorization request. The server stores the challenge with the code it issues and returns the code through a redirect, where it could be intercepted. The app sends the code with the original verifier. The server hashes the verifier, compares it with the stored challenge, and returns tokens only on a match.

The verifier never leaves the app, so a stolen code is useless to anyone else.

The OAuth 2.0 authorization code flow sends a short-lived code back to the client through a browser redirect. On a phone or a desktop app, that redirect can be intercepted by another app registered for the same URL scheme, or captured from logs. Without more protection, whoever holds the code can exchange it for tokens. PKCE, defined in RFC 7636, closes that gap with a simple idea: the client proves at the token step that it is the same client that started the flow.

## How PKCE works

PKCE adds two values to the authorization code flow.

1. **Create a verifier.** The client generates a random `code_verifier`, 43 to 128 characters from `A-Z a-z 0-9 - . _ ~`.
2. **Derive the challenge.** With the `S256` method: `code_challenge = BASE64URL(SHA256(code_verifier))`.
3. **Authorize.** The client sends the challenge, not the verifier, in the authorization request.
4. **Server stores the challenge** alongside the authorization code it issues.
5. **Exchange.** The client sends the code and the original `code_verifier` to the token endpoint.
6. **Verify.** The server hashes the verifier and compares it with the stored challenge. Only a match yields tokens.

An attacker who intercepts the code in step 4’s redirect does not have the verifier, which never left the client.

### What it looks like on the wire

The authorization request:

```
GET /authorize?response_type=code
  &client_id=my-app
  &redirect_uri=https%3A%2F%2Fapp.example.com%2Fcallback
  &scope=openid%20profile
  &state=af0ifjsldkj
  &code_challenge=E9Melhoa2OwvFrEMTJguCHaoeK1t8URWbuGJSstw-cM
  &code_challenge_method=S256
```

The token request:

```
POST /token HTTP/1.1
Content-Type: application/x-www-form-urlencoded

grant_type=authorization_code
&code=SplxlOBeZQQYbYS6WxSbIA
&redirect_uri=https%3A%2F%2Fapp.example.com%2Fcallback
&client_id=my-app
&code_verifier=dBjftJeZ4CVP-mB92K27uhbUJU1p1r_wW1gFWFOEjXk
```

The challenge and verifier above are the worked example from RFC 7636 appendix B.

Generating a pair in Python:

```
import base64, hashlib, secrets

verifier = base64.urlsafe_b64encode(secrets.token_bytes(32)).rstrip(b"=").decode()
challenge = base64.urlsafe_b64encode(
    hashlib.sha256(verifier.encode()).digest()
).rstrip(b"=").decode()
```

## PKCE with and without

| Threat | Code flow without PKCE | Code flow with PKCE (S256) |
| --- | --- | --- |
| Code intercepted by a malicious app on the device | Attacker redeems it | Refused: no verifier |
| Code leaked through logs or referrer headers | Attacker redeems it | Refused: no verifier |
| Code injected into another user’s session | Possible | Detected: verifier belongs to the original session |
| Public client with no secret | No client proof at all | Per-request proof |

## When to use PKCE

Always, for the authorization code flow. RFC 7636 introduced it for public clients: native apps, single-page apps, CLIs. The OAuth 2.0 Security Best Current Practice, RFC 9700, now recommends it for confidential clients as well, and the OAuth 2.1 draft makes it part of the core flow. If your identity provider exposes [OIDC discovery](https://quorumauth.com/learn/what-is-oidc-discovery/) metadata, look for `S256` in `code_challenge_methods_supported`.

PKCE protects the code. It does not decide what the resulting token may do; that is [delegated authorization](https://quorumauth.com/learn/what-is-delegated-authorization/).

## Pitfalls

- **Using `plain`.** It exists for clients that cannot compute SHA-256, which today means almost none. Servers should refuse it.
- **Weak verifiers.** A short or predictable verifier can be guessed. Use a cryptographic random generator.
- **Reusing a verifier.** Generate a fresh one per authorization request.
- **Allowing code replay.** Codes must be single-use, whatever PKCE says.
- **Loose redirect URI matching.** PKCE does not excuse prefix or wildcard matching. Compare redirect URIs exactly.
- **Skipping `state`.** PKCE helps against code injection, but keep `state` or the OIDC `nonce` for CSRF protection.

## How QuorumAuth handles PKCE

QuorumAuth’s hosted sign-in runs the authorization code flow with PKCE. In its tested behaviour:

- Only `S256` is accepted; an authorization request with any other challenge method is rejected.
- An authorization code can be exchanged once; replaying it is rejected.
- A wrong `code_verifier`, or a `redirect_uri` that differs from the one used at authorization, is rejected at the exchange step.
- A redirect off the product’s own pages is refused, and a code can be redeemed only through the product that obtained it.
- Authorization must happen on an organization’s own sign-in page; a request with no organization page, or through another organization’s page, is refused.
- When the organization requires a second factor, a hosted sign-in without it, or with a wrong authenticator code, is refused and issues no code.
- Each organization’s OpenID Provider advertises the authorization code flow with S256 PKCE and nothing else.
- Relying parties are declared with exact redirect URIs. A URI must be HTTPS on a named host, or HTTP on loopback; a native client may use its loopback address on any port.

## Frequently asked questions

Is PKCE only for mobile apps?

It was designed for public clients such as mobile and single-page apps, but current OAuth security guidance (RFC 9700) recommends it for every client using the authorization code flow.

What is the difference between S256 and plain?

With S256 the challenge is a SHA-256 hash of the verifier, so seeing the challenge does not reveal the verifier. With plain they are identical, which offers far less protection.

Does PKCE replace a client secret?

For public clients that cannot keep a secret, PKCE is the protection. Confidential clients should use both.

How long should the code\_verifier be?

RFC 7636 requires 43 to 128 characters from the unreserved URI character set. Generate it from at least 32 random bytes.

## Related reading

[Learn QuorumAuth What is OIDC discovery?OIDC discovery lets an app configure itself from one issuer URL. What /.well-known/openid-configuration contains, how clients use it, and what to check.Read](https://quorumauth.com/learn/what-is-oidc-discovery/) [Learn QuorumAuth What is delegated authorization?Delegated authorization lets one party act on behalf of another with fewer rights. How it differs from impersonation and how scope, audience and depth limit it.Read](https://quorumauth.com/learn/what-is-delegated-authorization/) [Learn QuorumAuth What is OAuth token exchange?OAuth 2.0 token exchange (RFC 8693) trades one token for another with a new audience or narrower scope. Delegation, impersonation, and examples.Read](https://quorumauth.com/learn/what-is-oauth-token-exchange/) [Learn QuorumAuth What is a JWKS?A JWKS publishes the public keys that verify an issuer's tokens. Learn the RFC 7517 format, how kid lookup and rotation work, and common mistakes.Read](https://quorumauth.com/learn/what-is-a-jwks/)

## Talk to sales about QuorumAuth.

QuorumAuth is sold through our sales team. The Build page shows the drop-in sign-in on your origin and how to reach sales about your stack.

[Go to Build and contact sales →](https://quorumauth.com/onboarding/)
