Privacy and Security

PKCE Step by Step: Verifier, Challenge and a Real OAuth Test Run

How OAuth PKCE works, how to create a valid code verifier and S256 challenge, and how to test a full authorization code flow without guesswork.

Saizul Amin
Saizul Amin3 Nov 2026 · 4 min read
PKCE Step by Step: Verifier, Challenge and a Real OAuth Test Run

The problem PKCE solves

In the authorization code flow, the user signs in at the provider and the browser carries a short-lived code back to your app, which then trades it for tokens. That code travels through places you do not fully control: the browser's address bar, operating system link handlers on phones, logs and sometimes malicious apps registered for the same link. Anyone who grabs the code before your app does could try to redeem it.

Proof Key for Code Exchange, defined in RFC 7636, makes a stolen code worthless. Before the sign-in starts, the app creates a random secret called the code verifier and keeps it. It sends only a hash of that secret, the code challenge, with the authorization request. When it redeems the code, it sends the original verifier. The server hashes it, compares the result with the stored challenge, and refuses the exchange if they differ. A thief who saw the code and even the challenge still lacks the verifier.

PKCE was designed for mobile apps, but current guidance, including RFC 9700 and the upcoming OAuth 2.1, asks every client to use it, including confidential server-side apps.

Getting the details right

The rules are strict and small mistakes cause hard-to-read errors. The verifier must be 43 to 128 characters drawn only from letters, digits and the four symbols hyphen, dot, underscore and tilde. The S256 challenge is the SHA-256 hash of the verifier's ASCII bytes, encoded in Base64url without the trailing equals signs. The plain method, where the challenge equals the verifier, exists only for devices that cannot hash and offers little protection. The redirect URI must be exactly the same in the sign-in request and in the token request. State protects your callback from forged responses, and nonce ties the ID token to this particular sign-in.

Walking through a test

The OAuth PKCE Generator and Flow Tester follows the flow in tabs. In the first tab, press the button to create a verifier, state and nonce from the browser's cryptographic random generator. A slider changes the verifier length and shows the entropy. The S256 challenge appears next to it, and if you type your own verifier the tool checks its length and characters immediately.

Fill in the authorization endpoint, client ID, redirect URI and scope from your provider settings. Optional fields cover response_mode, prompt, login_hint and any extra parameters, such as an audience for an API. The finished URL appears with a parameter table, and you can open it in a new tab to sign in for real.

After the sign-in, the browser lands on your redirect URI. Copy that whole address into the callback tab. The checker reads the code, any error and description, compares state with the value you sent, and checks the iss parameter if the provider includes it. It also warns if tokens arrived in the URL, which means an implicit or hybrid flow slipped in.

The token tab then writes the exchange as a curl command and as raw HTTP, including the code, redirect URI and verifier, with client_id in the body for public clients or a basic authorization header for confidential ones. For a public test client you can send the request from the browser itself, if the provider allows cross-origin calls. A final tab verifies any verifier and challenge pair, which helps when a mobile app and a server disagree.

Common errors and what they mean

invalid_grant at the token endpoint is the usual complaint. Check whether the code was already used, since codes are single use and often expire within a minute; whether the redirect URI differs by a slash or letter case; and whether the verifier really produced the challenge you sent. invalid_request at sign-in often means the challenge has the wrong encoding, such as standard Base64 with plus, slash and padding.

A tool for learning and debugging

Use this page with test clients and staging providers. In a production app the verifier must be generated fresh by the app for every sign-in and kept in memory or session storage, never in a URL and never reused. Do not paste production client secrets into any website. With those habits, PKCE is one of the cheapest and most effective protections in modern sign-in.

Completely freeNo cost, no sign-up
Files stay privateEverything runs in your browser
Easy in your languageAvailable in many languages