OpenID Connect (OIDC): The Identity Layer on Top of OAuth 2.0
Unify identity and delegated access: ID Tokens vs Access Tokens, OIDC standard claims (sub, nonce, at_hash), the UserInfo endpoint, and automated Discovery via /.well-known/openid-configuration.
OpenID Connect (OIDC) Protocol Flow 🆔
Layering identity (ID Token) on top of OAuth 2.0 authorization (Access Token).
01.1. Why OIDC was Created: Fixing the "Pseudo-Authentication" Hack
OAuth 2.0 was designed strictly as an authorization protocol, not an authentication protocol. An OAuth 2.0 access token merely signifies that some client is authorized to perform some operations on a server. It gives the client zero standardized information about who the user is, when they logged in, or how they authenticated.
Before OpenID Connect, every tech company invented proprietary hacks:
- Facebook created
graph.facebook.com/me. - GitHub created
api.github.com/user. - Twitter created custom user profile JSON endpoints.
Developers had to write separate custom wrappers for every provider. OpenID Connect (OIDC 1.0) solved this by creating an open, standardized identity layer built directly on top of the OAuth 2.0 framework. By adding the scope=openid parameter to an OAuth 2.0 request, the Authorization Server becomes an OpenID Provider (OP) and returns a standardized ID Token.
02.2. ID Token vs Access Token: Critical Architectural Distinctions
One of the most dangerous beginner security bugs is sending the ID Token to an API backend for authorization, or using an Access Token on the client UI for authentication:
| Dimension | ID Token (OIDC) | Access Token (OAuth 2.0) |
|---|---|---|
Intended Audience (aud) | The Client Application (Single Page App / Mobile App) | The Resource Server API |
| Primary Purpose | Authentication (AuthN): Informs the client app about user identity (name, email, avatar, login time). | Authorization (AuthZ): Authorizes the client to execute actions on protected APIs. |
| Format | Strictly a signed JWT (JWS) compliant with OIDC specifications. | Unspecified (Can be an opaque string, reference token, or JWT). |
| Consumed By | Decoded and verified by the frontend UI to personalize user experience. | Sent in Authorization: Bearer <token> header and verified by API gateway / backend. |
| Security Risk if Misused | If sent to an API, the API cannot verify if the token was intended for it (confused deputy vulnerability). | If read by frontend, claims may be missing or non-standardized. |
03.3. Anatomy of an OIDC ID Token & Standard Claims
An OIDC ID Token is a cryptographically signed JWT containing standardized claims defined in RFC 7519 and the OIDC Core specification:
json{ "iss": "https://accounts.google.com", "sub": "109823491823901238", "aud": "my-spa-client-id-889.apps.googleusercontent.com", "exp": 1714003600, "iat": 1714000000, "auth_time": 1713999950, "nonce": "n-0S6_WzA2Mj", "at_hash": "f9m_28v1Lq08_Xz9Q", "email": "alice@example.com", "email_verified": true, "name": "Alice Smith", "picture": "https://lh3.googleusercontent.com/a/alice-avatar.png" }
Key Security Claims:
nonce(Number Used Once): A client-generated random string included in the authorization request and echoed back in the ID token to prevent Replay Attacks.at_hash(Access Token Hash): Base64URL encoding of the left-most half of the hash of theaccess_token. It cryptographically binds the ID token to the specific access token issued alongside it.auth_time: The epoch timestamp when the user actually completed the login challenge (allows apps to enforce re-authentication if the session is stale).
04.4. The OIDC Discovery Document & Dynamic Configuration
OIDC eliminates hardcoded endpoint configurations through the OpenID Connect Discovery 1.0 specification. Every compliant provider publishes its configuration at the well-known URL:
https://<domain>/.well-known/openid-configuration
json{ "issuer": "https://accounts.google.com", "authorization_endpoint": "https://accounts.google.com/o/oauth2/v2/auth", "token_endpoint": "https://oauth2.googleapis.com/token", "userinfo_endpoint": "https://openidconnect.googleapis.com/v1/userinfo", "jwks_uri": "https://www.googleapis.com/oauth2/v3/certs", "response_types_supported": ["code", "token", "id_token", "code id_token"], "subject_types_supported": ["public"], "id_token_signing_alg_values_supported": ["RS256"] }
Benefits of Discovery:
- Zero-Configuration Client Setup: Applications simply configure the
issuerURL; client libraries automatically fetch the correct authorization, token, and JWKS public certificate endpoints. - Seamless Key & Endpoint Migration: If an IdP rotates endpoints or migration certificates, client applications adapt automatically without manual config edits.
⚖️Architectural Trade-offs & Production Realities
Architectural Advantages
- Universal, open standard for social logins (Sign in with Google/Apple) and enterprise SSO federation
- Provides standardized user profile claims (sub, email, name, picture) across heterogeneous identity providers
- Discovery metadata (`/.well-known/openid-configuration`) automates client library configuration and key rotation
Trade-offs & Constraints
- Requires strict client-side validation logic (checking signature, issuer, audience, and nonce) to prevent token spoofing
- Adds cryptographic parsing overhead compared to simple server-side cookie authentication
Apple uses OpenID Connect with mandatory PKCE and ES256 asymmetric signing. Apple's IdP issues signed ID tokens containing real or relay email addresses (`@privaterelay.appleid.com`), verified by third-party apps using Apple's public JWKS certificates.
🎯 Staff+ Engineering Takeaways
- OpenID Connect (OIDC) is the standardized identity layer built on top of OAuth 2.0.
- ID Tokens (JWTs) are for the client app; Access Tokens are for backend resource APIs.
- The discovery document (`/.well-known/openid-configuration`) standardizes IdP integration.
- Validate `iss`, `aud`, `exp`, and `nonce` on every ID token to ensure security.
Topic Knowledge Assessment 🧠
Step through 2 scenario questions to test your staff-level grasp.
Which component is the intended audience and consumer of an OIDC "ID Token"?
How clear and staff-actionable was this system breakdown?