0
How Authorization Code + PKCE Works

PKCE prevents the Authorization Code Interception Attack where a malicious actor or extension snoops the redirect URL to steal the auth code. Here is the step-by-step cryptographic sequence:

  1. Cryptographic Key Generation (Local): Before contacting the IdP, the browser creates a high-entropy secret string (code_verifier) using crypto.getRandomValues(). It then hashes this verifier using SHA-256 and base64url-encodes the digest to produce the code_challenge. The verifier stays safely in the browser's local memory.
  2. Front-Channel Authorization (GET /authorize): The browser redirects the user to the IdP's login page, appending response_type=code, code_challenge, and code_challenge_method=S256. The IdP authenticates the user, records the challenge with the session, and prompts for consent.
  3. Authorization Code Redirect: Upon approval, the IdP redirects back to the registered redirect_uri with an authorization code in the query string. Even if an attacker intercepts this code in browser history, they cannot use it without the unhashed verifier.
  4. Back-Channel Token Exchange (POST /token): The browser makes a direct HTTP POST (via fetch) to the token endpoint, presenting the code and the original plain code_verifier. The IdP computes SHA256(code_verifier): if the hash matches the recorded challenge, it confirms the caller is authentic and issues tokens.
  5. Token Reception & Claims: The IdP returns an id_token (JWT asserting the user's identity) and an access_token (bearer token for API calls).
1
Client & IdP Configuration

Enter your OpenID Connect provider details. Values are saved to sessionStorage and update the live request previews.

The IdP user-facing endpoint where authentication and consent take place.
The IdP REST endpoint where authorization codes are exchanged for tokens (must allow CORS).
Must be registered as a Public Client / SPA (no client secret required).
Must match exactly one of the Allowed Callback URLs configured in your IdP application.
openid is mandatory to request an ID token; profile and email request user claims.

Additional URI Parameters

Key Value
2
Generate PKCE Keys (Local Web Crypto)

Generates a cryptographically secure random code_verifier (32 random bytes converted to hex, 256 bits of entropy), then computes the code_challenge as BASE64URL(SHA-256(code_verifier)). Also generates a unique state token to guard against Cross-Site Request Forgery (CSRF).

LOCAL CRYPTO · Web Crypto API (SHA-256)
// Click Generate Keys to run window.crypto.subtle.digest('SHA-256', ...)
3
Authorization Request (Browser Redirect)

The user's browser redirects to the IdP's authorization endpoint. Notice how the code_challenge is passed in the query string, while the plain code_verifier remains stored safely in the browser.

GETBrowser Redirect
// Fill in config above to preview the Authorization URL
4
Authorization Code Received

After successful login and consent, the IdP redirects back to the redirect_uri with a short-lived, single-use code and returns the matching state parameter.

REDIRECT RESPONSE · URL Query Params
// Awaiting redirect from IdP…
5
Token Exchange (PKCE Verification)

The browser sends a direct HTTP POST to the token endpoint containing the code and the plain code_verifier. The IdP verifies that SHA256(code_verifier) == code_challenge, guaranteeing that the entity redeeming the code is the same client that initiated the flow.

POSTToken Endpoint · Fetch API
// Waiting for Step 4…

IdP Token Response

// Awaiting token exchange…
6
Token Decoding & Claims Inspection

Explore the contents of the returned tokens. The id_token contains user identity claims (sub, email, name) signed by the IdP. The access_token authorizes calls to downstream protected APIs.

// Decoded tokens will appear here after token exchange