OpenID Connect: validate an ID Token before creating a login session
Learn how OIDC differs from OAuth, what an ID Token proves, and how to validate issuer, signature, audience, expiry, and nonce.
OpenID Connect (OIDC) adds an identity layer on top of OAuth 2.0. OAuth access tokens authorize API access; an OIDC ID Token carries the result of user authentication for a client. Do not create a login session merely because a token decodes as readable JSON: validate it first.
In the authorization-code flow, the relying party (RP) sends an authentication request with the openid scope, correlates the browser callback using a transaction-specific state, and receives an ID Token from the OpenID Provider (OP). A nonce, when sent, binds the ID Token to that authentication request. profile and email scopes request claim categories; they do not guarantee every claim will be returned.
Before establishing a session, validate the ID Token with a maintained OIDC library: (1) iss exactly matches a preconfigured or trusted discovered issuer; (2) verify the JOSE signature using keys from that issuer and an algorithm allowed by client policy; (3) aud includes this RPʼs client_id and any additional audience is trusted; if azp is present it must match the client, and apply the profileʼs azp rule for multiple audiences; (4) reject an expired exp; (5) compare nonce when one was sent; (6) check requested auth_time/acr policy; (7) if using UserInfo, require its sub to exactly match the ID Tokenʼs sub.
Use (iss, sub) as the stable account key. sub is unique only within an issuer; email and display name can change or be reused. Treat Discovery metadata as trusted configuration: use a preapproved OP or enforce an explicit issuer trust policy and TLS validation, rather than letting untrusted user input select arbitrary endpoints. state and nonce have distinct purposes; one does not replace the other.
OIDC standardizes authentication claims, not your appʼs roles, account provisioning, or post-login session policy. Decide how a verified (iss, sub) maps to an internal account and how locked or departed users lose sessions. Never accept a token based only on its decoded payload.
References
[OpenID Connect Core 1.0 incorporating errata set 2](https://openid.net/specs/openid-connect-core-1_0.html)
[OpenID Connect Discovery 1.0 incorporating errata set 2](https://openid.net/specs/openid-connect-discovery-1_0.html)
[IETF RFC 9700 / BCP 240: OAuth 2.0 Security Best Current Practice](https://www.rfc-editor.org/rfc/rfc9700.html)