OAuth 2.0 PKCE Generator - Code Verifier & Challenge for S256
Developer Tools
Generate OAuth 2.0 PKCE code_verifier and code_challenge (S256) pairs for public clients. Build the complete authorization URL with client ID, redirect URI, scope, and state.
Authorization URL Builder
Create a random code_verifier (43–128 chars).
Compute code_challenge = BASE64URL(SHA-256(verifier)).
Send code_challenge in the authorization request.
Send code_verifier when exchanging the auth code for tokens.
How to use this tool
- Click Generate to create a cryptographically random code_verifier and its S256 code_challenge.
- Fill in your OAuth server endpoint, client ID, redirect URI, and scope.
- Copy the authorization URL and use it to start the OAuth flow.
- Send the code_verifier when exchanging the authorization code for tokens.
What is OAuth 2.0 PKCE?
PKCE (Proof Key for Code Exchange, pronounced "pixy") is a security extension to the OAuth 2.0 authorization code flow. It prevents authorization code interception attacks that could occur in public clients (single-page apps, mobile apps) that cannot securely store a client secret.
How PKCE works
- The client generates a random code verifier (a high-entropy random string, 43–128 characters).
-
The client computes the code challenge:
BASE64URL(SHA256(code_verifier)). -
The authorization request includes
code_challengeandcode_challenge_method=S256. -
The auth server stores the challenge. When the client exchanges the code for a token, it
sends the original
code_verifier. - The auth server re-hashes the verifier and compares it to the stored challenge. They must match.
Why it matters
Even if an attacker intercepts the authorization code, they cannot exchange it for a token because they don't have the code verifier. PKCE is now recommended for all OAuth 2.0 clients, including confidential server-side apps (RFC 9700).
Code verifier requirements
The code verifier must meet specific requirements per RFC 7636:
- Character set: URL-safe base64 characters only - A–Z, a–z, 0–9, hyphen (
-), period (.), underscore (_), tilde (~). - Length: minimum 43 characters, maximum 128 characters.
- Entropy: minimum 256 bits of cryptographic randomness (use
crypto.getRandomValuesor equivalent - never Math.random()).
These constraints exist to ensure the verifier cannot be guessed or brute-forced, even if the code challenge is exposed.
Integration code example
// Generate PKCE code verifier and challenge (Web Crypto API)
async function generatePKCE() {
// Generate 32 random bytes -> 43 base64url chars
const array = new Uint8Array(32);
crypto.getRandomValues(array);
const codeVerifier = btoa(String.fromCharCode(...array))
.replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, '');
// SHA-256 hash of the verifier
const encoder = new TextEncoder();
const data = encoder.encode(codeVerifier);
const hashBuffer = await crypto.subtle.digest('SHA-256', data);
const hashArray = new Uint8Array(hashBuffer);
const codeChallenge = btoa(String.fromCharCode(...hashArray))
.replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, '');
return { codeVerifier, codeChallenge };
} Comparison to implicit flow
The OAuth 2.0 implicit flow (now deprecated in RFC 9700) was designed for browser-based apps
that could not safely store client secrets. Instead of an authorization code, it returned
access tokens directly in the URL fragment (e.g., #access_token=abc123). This
exposed tokens in browser history, server logs, and referrer headers.
PKCE eliminates this attack surface by keeping the token exchange server-side (or at minimum, preventing its reuse without the verifier). All new OAuth implementations should use the authorization code flow with PKCE rather than the implicit flow.
Frequently asked questions
What is PKCE?
PKCE (Proof Key for Code Exchange) is an extension to the OAuth 2.0 Authorization Code flow for public clients. It prevents authorization code interception attacks.
What is S256?
S256 is the SHA-256 based code challenge method. The code_challenge = BASE64URL(SHA256(code_verifier)). This is the recommended method.
Is it safe to generate PKCE pairs here?
All generation happens in your browser using the Web Crypto API. Nothing is sent to any server. Generate a fresh pair for each authorization request.
Related tools
- JWT GeneratorUse JWT Generator to generate and sign JSON Web Tokens (JWT) using.
- Keypair GeneratorUse Keypair Generator to generate RSA or Elliptic Curve (ECDSA, ECDH) public/private.
- URL ParserUse URL Parser to parse any URL into its components: protocol, hostname,.
- Base64url EncoderUse Base64url Encoder to encode and decode text using URL-safe Base64 (Base64url,.