PKCE Generator
Generate code_verifier and code_challenge pairs for secure OAuth2 authorization flows
Usage in Authorization Request
Generate a pair first to see the example
Understanding PKCE
Why Proof Key for Code Exchange matters for OAuth2 security
What is PKCE?
PKCE (Proof Key for Code Exchange) is an extension to OAuth2 that prevents authorization code interception attacks. It is now recommended for all OAuth2 clients, including server-side applications.
How It Works
The client generates a random code_verifier and derives a code_challenge. The challenge is sent with the authorization request, and the verifier is sent when exchanging the code for tokens.
S256 vs Plain
S256 applies a SHA-256 hash to the verifier, providing protection even if the challenge is intercepted. The plain method sends the verifier as-is and should only be used when S256 is not supported.
PKCE in practice
How the pair is used
Generate a random code_verifier, derive code_challenge = base64url(SHA256(verifier)), and send only the challenge on the authorization request along with code_challenge_method=S256. Keep the verifier in your client.
When you exchange the authorization code for tokens, send the verifier. The server hashes it and compares against the challenge it stored. A match proves the party redeeming the code is the same one that started the flow — so a code intercepted from a redirect URL, a log, or browser history is useless on its own.
Requirements that are easy to violate
The verifier must be 43–128 characters from the unreserved set [A-Z] [a-z] [0-9] - . _ ~. Shorter than 43 is a spec violation and materially weakens the entropy. It must come from a cryptographically secure random source — Math.random() is not one.
Generate a fresh verifier for every authorization request. Reusing one across flows reintroduces exactly the replay problem PKCE exists to close, and makes the challenge predictable for anyone who saw a previous request.
S256 versus plain
The plain method sends the verifier unmodified as the challenge, which means anyone who observes the authorization request has the verifier. It provides no protection and exists only for clients that genuinely cannot compute SHA-256.
Always use S256. If your authorization server accepts plain, check whether it can be disabled — an attacker who can modify the authorization request may be able to downgrade the method and defeat the mechanism entirely.
Frequently asked questions
PKCE is the easy part
Verifier and challenge are ten lines. Token storage, silent refresh, and rotation are where SPA auth actually gets hard — our SDKs handle all three.
Free, unlimited users. No credit card required.