OIDC nonce: bind an ID Token to the login request
Learn when OIDC nonce is required, how to create and store a per-login value, and how to verify it separately from state and the ID Token signature.
OIDC nonce: bind an ID Token to the login request
In OpenID Connect, the RP sends a nonce in an authentication request and the OP returns the same value in the ID Token. The RP checks that the claim matches the value for the current login transaction. This helps prevent an ID Token from another session or an earlier login being inserted into the response. Nonce does not replace OAuth state or ID Token validation.
Nonce and state have different jobs
A nonce is a random, one-time transaction value, not a password or permanent user ID. Generate a new unpredictable value for each login and do not reuse it across sessions. state binds the authorization response to the client’s request and helps defend against CSRF. Nonce binds the OIDC ID Token to the authentication request and RP login transaction. Use separate values and validate both when the flow uses both.
When OIDC Core requires nonce
| Flow/request | OIDC Core requirement |
|---|---|
| Authorization Code Flow | Optional. If sent, the OP returns it in the ID Token and the RP checks it. |
| Implicit Flow | Required; use sufficient entropy to prevent guessing. |
Hybrid: code id_token or code id_token token | Required. |
Hybrid: code token | Optional. |
Current OAuth security guidance recommends avoiding Implicit Flow and using Code Flow. A nonce can still provide the separate ID Token binding check in Code Flow.
Implementation sequence
Create a fresh, high-entropy random value with a cryptographic random generator for each login.
Bind it to that browser’s login transaction. A web server may keep an unguessable session cookie marked HttpOnly and use its hash as the nonce. Browser clients need a security design that accounts for XSS risks in script-accessible storage.
Send the nonce in the supported OIDC authentication request. Keep it out of logs and analytics.
Validate the returned ID Token normally first: verify signature, issuer, audience, expiration, and other required checks. Decoding the token alone is not validation.
Compare the token’s nonce claim exactly with the value stored for this transaction. Reject the authentication if the claim is absent when required or does not match. Then consume the transaction state so the same response cannot create another session.
Keep separate nonce and request state for simultaneous logins, such as multiple browser tabs; do not overwrite one transaction’s value with another.
For example, a fictional login transaction stores n-A7f..., sends it in the request, and receives it unchanged in the ID Token. After normal token validation, the RP compares the claim with the stored value. The string is only a placeholder.
Troubleshooting
**Nonce claim missing:** check that the request included nonce, that the response contains an ID Token, and that the OP follows the applicable flow rules. Reject rather than disabling validation.
**Nonce differs:** check whether concurrent tabs selected the wrong transaction record or a value was overwritten; OIDC nonce strings are case-sensitive.
**Old nonce appears again:** ensure the login transaction is consumed and token/session data are not retained unnecessarily. The RP should check for replay; the storage method is implementation-specific.
**Using state instead:** validate OAuth `state` and OIDC nonce separately because they serve different purposes.
References
[OpenID Connect Core 1.0, errata set 2, §§2–3](https://openid.net/specs/openid-connect-core-1_0.html)
[RFC 9700 — OAuth 2.0 Security Best Current Practice](https://www.rfc-editor.org/rfc/rfc9700.html)