OpenID Connect (OIDC) Explained: Login with Identity Providers

How OpenID Connect adds authentication to OAuth 2.0: ID tokens, claims, discovery documents, userinfo, validating tokens.

Published December 4, 2026

OAuth 2.0 answers "may this app access that API?" but not "who is this user?". OpenID Connect (OIDC) is a thin identity layer on top of OAuth 2.0 that answers the second question in a standard way. It powers "Sign in with Google/Microsoft/Apple", enterprise single sign-on with Okta, Entra ID, Auth0, Keycloak and others, and even CI systems authenticating to clouds.

The concept

In OIDC you request the openid scope (plus profile, email as needed). Alongside the access token, the authorization server, now called the OpenID Provider, returns an ID token: a signed JWT containing claims about the authentication event and the user, such as iss (issuer), sub (stable user identifier), aud (your client ID), exp, iat, nonce, and optionally email and name.

Providers publish a discovery document at /.well-known/openid-configuration listing their endpoints and the URL of their public signing keys (JWKS). Your app validates every ID token: signature against the JWKS, issuer, audience, expiry and nonce. Then it maps the provider's sub (not email, which can change) to a local user account and creates its own session.

The OIDC login flow

BrowserYour appOpenID ProviderGET /.well-known/openid-configurationauthorize (scope=openid email, nonce)login, redirect with codeexchange code (+ PKCE)id_token + access_tokenvalidate id_token, create session
OIDC login on top of the authorization code flow.

ID token claims

ClaimMeaningCheck
issIssuer (provider URL)Must equal expected issuer
subStable user ID at the providerUse as the account key
audIntended client(s)Must contain your client ID
exp / iatExpiry / issued atReject expired tokens
nonceValue you sentMust match to prevent replay
email, email_verifiedUser emailOnly trust if verified, and do not use as primary key

Validating an ID token

kidvalidID token (JWT)Fetch JWKScache keysVerify signature + iss/aud/exp/nonceMap sub → local usercreate session
Never trust an ID token without validation.

Practical examples

Validate an ID token in Node.js with jose

Remote JWKS handles key rotation.

import { createRemoteJWKSet, jwtVerify } from 'jose'
const JWKS = createRemoteJWKSet(new URL('https://accounts.example.com/.well-known/jwks.json'))

const { payload } = await jwtVerify(idToken, JWKS, {
  issuer: 'https://accounts.example.com',
  audience: process.env.OIDC_CLIENT_ID,
})
if (payload.nonce !== session.nonce) throw new Error('nonce mismatch')
const user = await findOrCreateUserBySub(payload.iss, payload.sub)

Discovery document (excerpt)

Everything a client needs to integrate.

{
  "issuer": "https://accounts.example.com",
  "authorization_endpoint": "https://accounts.example.com/authorize",
  "token_endpoint": "https://accounts.example.com/token",
  "userinfo_endpoint": "https://accounts.example.com/userinfo",
  "jwks_uri": "https://accounts.example.com/.well-known/jwks.json",
  "scopes_supported": ["openid", "email", "profile"]
}

Account linking table

Key identities by (issuer, subject).

CREATE TABLE identities (
  issuer   text NOT NULL,
  subject  text NOT NULL,
  user_id  bigint NOT NULL REFERENCES users(id),
  PRIMARY KEY (issuer, subject)
);

Common mistakes

  • Using the email claim as the unique account key.
  • Accepting ID tokens without verifying signature, issuer and audience.
  • Using the ID token as an API access token.
  • Skipping nonce validation in browser-based flows.

Key takeaways

  • OIDC adds standardised identity (ID tokens) to OAuth 2.0.
  • Validate signature, iss, aud, exp and nonce on every ID token.
  • Key accounts by issuer + sub, not email.
  • Create your own session after validation.

FAQ

What is the userinfo endpoint?

An OAuth-protected endpoint returning user claims, useful when the ID token is minimal.

How is OIDC used in CI?

CI platforms issue OIDC tokens to jobs; cloud providers trust them to grant short-lived credentials without stored secrets.

OIDC or SAML for enterprise SSO?

Both are common; OIDC is simpler and JSON-based, SAML is older and XML-based but widely supported by enterprise identity providers.

More Security articles