How it works
- Generate a code verifier — a cryptographically random string, 43–128 characters, using only
[A-Z a-z 0-9 - . _ ~](base64url without padding). - Derive the code challenge — SHA-256 hash of the verifier, then base64url-encode the raw bytes (no padding).
- Send the challenge in the authorization URL as
code_challengewithcode_challenge_method=S256. - Send the verifier at token exchange time as
code_verifier.
code_challenge or sets code_challenge_method to anything other than S256.
Generating PKCE values
Security notes
- Store the verifier on your server or in session, never in a cookie or localStorage that is readable by third-party scripts.
- Do not reuse a verifier — generate a fresh one for every authorization request.
- The verifier is a secret until it is sent at token exchange. The challenge is safe to expose in the URL.