Codepackr / encoders / OAuth 2.0 PKCE Generator

OAuth 2.0 PKCE Generator

Generate high-entropy cryptographically secure OAuth 2.0 PKCE code verifiers and SHA-256 code challenges directly in browser memory.

Client-Side Execution & Privacy Guarantee

This utility executes 100% locally in your web browser. Your inputs, tokens, queries, and data payloads are never transmitted to any external server or backend.

Proof Key for Code Exchange (PKCE) protects public clients such as single-page apps and mobile apps from authorization-code interception. The client creates a high-entropy code verifier, derives a code challenge by hashing it with SHA-256, and sends the challenge with the authorization request. Later it proves possession by sending the original verifier when exchanging the code for tokens.

This generator produces a cryptographically random verifier of the recommended length and the corresponding S256 challenge, all inside the browser. Nothing is transmitted, so the verifier remains secret until you deliberately copy it into your application code or test harness.

Code verifier requirements

RFC 7636 requires the code verifier to be a high-entropy cryptographic random string between 43 and 128 characters, using the unreserved characters [A-Z] / [a-z] / [0-9] / "-" / "." / "_" / "~". The generator uses the browser’s crypto.getRandomValues to fill a byte array and then encodes it as Base64url, producing a 43-character verifier by default.

Shorter verifiers reduce the search space an attacker must try; longer ones offer no practical extra security once you exceed roughly 256 bits of entropy. The tool stays within the mandated range.

S256 code challenge derivation

The challenge is BASE64URL(SHA256(ASCII(verifier))). The generator performs the SHA-256 hash with the Web Crypto API and applies the same Base64url encoding used for JWTs, omitting padding. The resulting challenge is what you place in the code_challenge parameter together with code_challenge_method=S256.

Plain (unhashed) challenges are discouraged by the specification and are not offered here. S256 is the only method modern authorization servers should accept for public clients.

Using the values in an authorization flow

Send the challenge (not the verifier) in the initial authorization request. Store the verifier securely in memory or session storage until the redirect returns. When you call the token endpoint, include the original verifier as the code_verifier parameter. The authorization server recomputes the challenge and compares it; a match proves the same client that started the flow is finishing it.

Never log or persist the verifier beyond the lifetime of the authorization attempt. Once the token is obtained, discard the verifier.

When to use this tool

  • Building a public OAuth 2.0 client that must use PKCE
  • Testing an authorization server’s S256 challenge validation
  • Generating values for a manual curl or Postman authorization flow
  • Teaching the difference between verifier and challenge
  • Creating reproducible test vectors for unit tests (by copying a generated pair)

How to use the OAuth 2.0 PKCE Generator

  1. Click Generate. A fresh verifier and its S256 challenge appear.
  2. Copy the code verifier into your application’s temporary storage.
  3. Copy the code challenge into the authorization request as code_challenge.
  4. Set code_challenge_method to S256.
  5. After the user is redirected back, send the stored verifier as code_verifier to the token endpoint.
  6. Discard both values once tokens are received.
  7. Generate a new pair for every authorization attempt.

Worked examples

Typical 43-character pair

Input
(click Generate)
Output
Verifier: dBjftJeZ4CVP-mB92K27uhbUJU1p1r_wW1gFWFOEjXk\nChallenge: E9Melhoa2OwvFrEMTJguCHaoeK1t8URWbuGJSstw-cM

SHA-256 of the verifier, Base64url-encoded without padding. Both values are safe to paste into test requests.

Using the pair in a request

Input
code_challenge=E9Melhoa2OwvFrEMTJguCHaoeK1t8URWbuGJSstw-cM&code_challenge_method=S256
Output
Authorization URL fragment or query contains the challenge; later token request contains code_verifier=dBjftJeZ4CVP-mB92K27uhbUJU1p1r_wW1gFWFOEjXk

The authorization server will reject the token request if the verifier does not hash to the earlier challenge.

Common mistakes and tips

  • Generate a new verifier for every authorization request; reuse opens a window for code interception.
  • Store the verifier only in memory or short-lived session storage, never in localStorage if the page can be shared.
  • Confirm your authorization server advertises S256 support; some older servers only accept plain.
  • The challenge is not secret; it is safe to place in the authorization URL. The verifier is secret.
  • If a token request fails with invalid_grant, the most common cause is a mismatched or missing code_verifier.

Frequently asked questions

How long is the generated verifier?

43 characters by default, which supplies 256 bits of entropy after Base64url encoding. This satisfies the RFC minimum and maximum.

Can I choose a custom length?

The tool uses the recommended length. If you need a different size for testing you can generate a verifier elsewhere and compute the challenge with a SHA-256 tool, but the generator itself is fixed.

Is the random source cryptographically secure?

Yes. It uses crypto.getRandomValues, the browser’s CSPRNG.

What is the difference between plain and S256?

Plain sends the verifier itself as the challenge. S256 sends a hash. S256 is required for public clients by current best practice.

Do I need to URL-encode the values?

Both values are already Base64url, so they are URL-safe. Still percent-encode them if you place them inside a larger query string that your HTTP library does not encode automatically.