What it is
OpenID Connect (OIDC) is an identity layer on top of OAuth 2.0. OAuth lets an application get an access token to call an API on a user's behalf. OIDC adds a second artefact, the ID token: a signed JSON Web Token in which the OpenID Provider (OP: Entra ID, Okta, Auth0, Keycloak, Google and so on) states that a particular user signed in, for a particular application (the relying party, RP), at a particular time. It also standardizes discovery, a UserInfo endpoint, scopes for profile claims, and logout.
Why it exists
Before OIDC, many sites "logged in with OAuth": they took an access token, called some profile API, and trusted whatever user id came back. Access tokens are not addressed to the client, so a token that a user had granted to any app could be replayed at another app to sign in as that user (token substitution). Every provider also invented its own profile API. OIDC fixes both: the ID token is addressed to one client (aud), bound to one sign-in (nonce) and verifiable offline, and the protocol is the same at every provider.
How it works
Discovery. The RP reads https://<issuer>/.well-known/openid-configuration once and caches it: the issuer identifier, authorization, token and UserInfo endpoints, supported algorithms, and jwks_uri, where the provider publishes its public signing keys as a JSON Web Key Set. Each key has a kid.
Authorization code flow with PKCE (the recommended flow for web, mobile and single-page apps; the implicit flow is deprecated by the OAuth 2.0 Security Best Current Practice, RFC 9700):
- The RP redirects the browser to the authorization endpoint with
response_type=code,scope=openid(plusemail,profile…),client_id,redirect_uri,state,nonceand a PKCEcode_challenge(S256). It storesstate,nonceand thecode_verifierin a short-lived cookie or server-side. - The user authenticates at the provider. The RP never sees the password or passkey.
- The provider redirects back to
redirect_uriwith a one-timecodeand the samestate. The RP checksstate. - The RP calls the token endpoint server-to-server with the code, the
code_verifierand its client authentication (secret,private_key_jwtclient assertion, or mTLS). It receives an ID token, an access token and often a refresh token.
ID token validation, done locally: verify the signature with the JWKS key named by kid, accepting only the algorithms you expect (never none); iss equals the discovered issuer exactly; aud contains your client_id (and azp is you if there are several audiences); exp is in the future, with small clock skew; nonce equals the stored value. Optionally check auth_time or acr/amr when you require recent or multi-factor authentication. The user's identity is the pair iss + sub.
UserInfo. With the access token, the RP can call the UserInfo endpoint for claims not in the ID token. The sub must match the ID token's.
After sign-in the RP creates its own session (a cookie, see Session-Based Authentication). It can renew claims with the refresh token, and learn about sign-outs through RP-initiated logout, front-channel or back-channel logout.
When to use it
- Signing users in with a corporate or social identity provider, or single sign-on across your own apps.
- Any time an app needs to know who the user is, rather than only call an API on their behalf.
- Federating identity between organizations (B2B customers bringing their own IdP).
- Workload identity federation also reuses OIDC tokens: CI systems and Kubernetes clusters issue OIDC tokens that clouds accept in exchange for short-lived credentials (see Secrets Management).
When not to
- Machine-to-machine calls with no user: use OAuth client credentials (or mTLS / workload identity). There is no one to sign in.
- A single app with its own user database and no federation needs: a local login plus sessions is simpler, though many teams still prefer a hosted provider to avoid storing credentials.
- Authorization decisions: OIDC tells you who the user is. What they may do is still your application's job.
Trade-offs
| Choice | You gain | You pay |
|---|---|---|
| Hosted provider instead of your own login | MFA, passkeys, breach detection, federation | Vendor dependency and cost; sign-in fails when it is down |
| Local ID token validation | No network call, works during provider hiccups | Must handle key rotation; revocation is only noticed on refresh |
| Short app sessions | Faster reaction to disabled accounts | More redirects or refreshes against the provider |
| Calling UserInfo per request | Always-fresh claims | A remote round trip on every request; provider outage = your outage |
| Fat ID tokens (many claims) | Fewer UserInfo calls | Larger cookies or headers, more personal data spread around |
Alternatives
- SAML 2.0: XML-based enterprise federation, still common for workforce SSO. Heavier, browser-centric, no native mobile story.
- Plain OAuth 2.0 plus a profile API: what OIDC replaced. Avoid for sign-in.
- Passkeys (WebAuthn) directly in your app: strong authentication without a federation protocol; you still own the account store.
- Session-only login with a local password store: fine for small apps, but you carry credential storage and MFA yourself.
Failure modes
- Accepting access tokens as login proof: token substitution, as in step 1.
- Skipping
audornoncechecks: tokens issued to other clients, or replayed tokens, are accepted. - Algorithm confusion: accepting
alg: noneor verifying an RS256 token as HS256 with the public key as the HMAC secret. Pin the expected algorithms. - Keying users by email: emails change and can be reassigned; some providers let users set unverified emails. Use
iss+sub. - Key rotation outages: a cached JWKS without a refresh path rejects every token after rotation. Refresh on unknown
kid, rate-limited. - Provider on the request path: calling UserInfo or introspection per request couples every page view to the provider's latency and availability (steps 8–9).
- Open redirects: loosely matched
redirect_urivalues let attackers receive codes. Register exact redirect URIs.
In production
Use a maintained OIDC client library rather than parsing tokens by hand. Register exact redirect URIs, use PKCE for every client, and prefer asymmetric client authentication (private_key_jwt) over shared secrets for confidential clients. Cache discovery and JWKS, refresh on unknown kid. Keep tokens server-side where possible (a backend-for-frontend holds tokens and gives the browser only an HttpOnly session cookie). Implement back-channel logout if you need sessions to end when the provider session ends. Monitor sign-in error rates separately from request error rates.
Common misconceptions
- "OAuth is an authentication protocol." OAuth is delegated authorization. OIDC is the authentication layer on top.
- "The ID token is a bearer token for my APIs." It is addressed to the client. APIs take access tokens issued for them.
- "Validating a token means calling the provider." ID tokens and JWT access tokens are verified locally with the published keys; only opaque tokens need introspection.
- "PKCE makes state and nonce unnecessary." They protect different steps; keep them.
- "Sign-out at the app signs the user out everywhere." Only with RP-initiated logout at the provider plus logout propagation to other apps.
Interview angle
Expect to draw the authorization code flow with PKCE, say which values travel through the browser (code, state) and which do not (tokens, verifier), and list the ID token checks. Strong answers distinguish ID token from access token, explain token substitution and why aud and nonce exist, handle JWKS rotation, and keep the identity provider off the hot path with an application session, while being clear that new sign-ins still depend on it.
Model assumptions
Steps 1–7 are a scripted illustration, not a simulation: redirects, the code exchange, token validation and the attacks are drawn as hand-placed packets with illustrative durations (10 ms between the browser and the app, 15 ms to the provider). The engine has no notion of tokens, signatures or redirects. Steps 8–10 use the simulation: Poisson arrivals at 200 page views per second, a notes app with 32 workers and 4 ms mean service time (lognormal, cv 0.3), a database with 16 connections and 3 ms reads 1 ms away, and in step 8 a UserInfo endpoint with 16 workers and 5 ms per call, 15 ms away. A provider that is down refuses connections and the app fails the request. That gives about 64 ms per page view with UserInfo on the path and about 29 ms without it. Numbers are illustrative, not benchmarks of any provider.