State / Nonce Generator
Generate cryptographically secure state and nonce values for OAuth2 and OpenID Connect flows
Usage in Authorization Request
Generate values first to see the example
State & Nonce in OAuth2 / OIDC
Why these parameters matter for secure authorization flows
What is State?
The state parameter binds the authorization request to the callback. It prevents CSRF attacks by ensuring the response matches the request you initiated. Store it in a session or cookie before redirecting, then verify it when the user returns.
What is Nonce?
The nonce parameter is used primarily in OpenID Connect flows. It is sent with the authorization request and must appear in the id_token claim. It prevents replay attacks by ensuring the ID token was issued in response to your specific request.
Character Set
Both values use the unreserved character set from RFC 3986: A-Za-z0-9-._~. This makes them URL-safe and suitable for query parameters or fragments without encoding.
State and nonce in OAuth2 and OIDC
State prevents CSRF on the callback
Generate a random state, store it in the user's session, and include it on the authorization request. When the callback arrives, check the returned value matches what you stored, then discard it.
Without this, an attacker can feed a victim an authorization code from the attacker's own account. The victim's browser completes the callback and gets logged into the attacker's account — where any data they then enter belongs to the attacker. Session fixation, via the login flow.
Nonce binds the ID token to your request
The nonce is an OIDC concept. You send it on the authorization request, and the provider embeds it in the ID token as a claim. Your client verifies the claim matches what it sent.
This defends against token replay: an ID token captured from one flow can't be injected into another, because the nonce won't match. It's required for the implicit and hybrid flows and remains good practice with the authorization code flow.
They are not interchangeable, and neither is PKCE
state protects the callback from forgery. nonce binds the ID token to the request. PKCE binds the authorization code to the client instance. Three parameters, three different attacks.
Use all three. They're each a random value and a comparison — the total cost is negligible relative to what they cover.
Frequently asked questions
State and nonce are table stakes
Generating them is easy; validating them correctly on every callback is where CSRF bugs live. Our SDKs do it for you by default.
Free, unlimited users. No credit card required.