PKCE Code Verifier and Code Challenge Generator
Generate a code_verifier or paste your own, and get the S256 code_challenge for OAuth 2.0 PKCE (RFC 7636).
Verify a verifier and challenge
Paste the code_challenge your app or server has. It is compared with the S256 of the code_verifier above.
Authorization URL builder
Pick a provider preset, replace the YOUR_… placeholders, and copy a ready authorization URL and token request.
Bulk generate pairs
Runs entirely in your browser. Nothing you enter is sent or stored.
How to use
- Press Generate for a new random code_verifier, or paste one.
- The code_challenge is computed as BASE64URL(SHA-256(code_verifier)).
- Send code_challenge with code_challenge_method=S256 in the authorization request.
- Send the code_verifier in the token request.
PKCE (Proof Key for Code Exchange, RFC 7636) protects the OAuth 2.0 authorization code flow. It was designed for public clients such as mobile apps, desktop apps and single-page web apps, which cannot keep a client secret. Before redirecting the user, the client creates a one-time secret called the code_verifier and sends only its hash, the code_challenge. When it later exchanges the authorization code for tokens, it sends the original verifier and the server checks that the two match, so someone who intercepts the code alone cannot use it.
This generator takes 32 random bytes from the browser’s crypto.getRandomValues and encodes them as base64url without padding, which gives a 43-character verifier. The challenge is the SHA-256 of the verifier, again base64url-encoded without padding, and is always 43 characters long. Only the S256 method is offered: RFC 7636 also defines plain, but requires S256 whenever the client can compute SHA-256. Use it to debug a login integration, compare your library’s output, or build test requests by hand.
A pasted verifier is hashed as-is and is not checked against the RFC rules, so make sure yours has 43 to 128 characters from A–Z, a–z, 0–9, “-”, “.”, “_” and “~”. Create a new verifier for every authorization request. Both values are computed on this page with the Web Crypto API and are never sent anywhere.
Use cases & tips
Debugging an invalid_grant error
When the token endpoint answers invalid_grant or invalid_request after a login, the challenge your app sent often does not match the verifier it later submits. Paste the verifier from your logs of a test run into this page and compare the S256 challenge with what the authorization request carried. If they differ, the bug is in your code or library. The verifier dBjftJeZ4CVP-mB92K27uhbUJU1p1r_wW1gFWFOEjXk from the RFC is a handy known-good check for your own implementation.
Mistakes that produce a wrong challenge
Three slips cause most failures. First, using standard base64, which contains plus signs, slashes and trailing equals signs, instead of the URL-safe variant without padding. Second, hashing decoded bytes or a different string rather than the verifier text exactly as sent. Third, leaving out code_challenge_method, which makes many servers assume plain and compare the raw verifier with the hash. Trimming a stray newline from a copied value is also worth checking.
Building a request by hand
Before wiring a client library, you can test a provider with a browser and curl. Generate a pair here, open the authorization URL with response_type=code, your client_id, redirect_uri, code_challenge and code_challenge_method=S256, sign in, and copy the code from the redirect. Then post it to the token endpoint together with the matching code_verifier. Authorization codes are short lived, so have the token request ready before you start.
Handling the verifier in a real app
The challenge is safe to appear in URLs and logs, but the verifier is the secret that proves the same client finished the flow, so keep it out of logs and analytics. A single-page app can hold it in memory or session storage until the callback; a mobile app can keep it in a variable for the pending request. Make a fresh pair for each login attempt, and keep using the state parameter too, since it protects against a different kind of attack.
Frequently asked questions
What is PKCE?
Proof Key for Code Exchange (RFC 7636). The client sends a hashed code_challenge with the authorization request and the original code_verifier with the token request, so a stolen authorization code cannot be redeemed alone.
How is the code_challenge calculated?
With method S256: SHA-256 of the ASCII code_verifier, then base64url-encoded without padding. For the RFC 7636 example verifier dBjftJeZ4CVP-mB92K27uhbUJU1p1r_wW1gFWFOEjXk the result is E9Melhoa2OwvFrEMTJguCHaoeK1t8URWbuGJSstw-cM.
Why is the generated verifier 43 characters?
32 random bytes encoded as base64url without padding are 43 characters, the minimum length RFC 7636 allows (43 to 128 characters of A-Z, a-z, 0-9, -, ., _, ~).