OAuth 2.0 Deep Dive
Master all OAuth 2.0 flows: Authorization Code, Client Credentials, and more. OAuth 2.0 Guide →
| Aspect | OAuth 2.0 | OpenID Connect (OIDC) |
|---|---|---|
| Purpose | Authorization | Authentication + Authorization |
| Question Answered | ”What can this app access?" | "Who is this user?” |
| Token Type | Access Token | ID Token + Access Token |
| Token Format | Opaque or JWT | JWT (always) |
| User Info | Optional (via API call) | Built-in (ID Token claims) |
| Use Case | API access, third-party integrations | Single Sign-On, user login |
| Specification | RFC 6749, RFC 6750 | OpenID Foundation spec |
OAuth 2.0 was designed to solve the delegated authorization problem. Before OAuth, if you wanted a third-party app to access your data, you had to give it your password.
Imagine you want a photo printing service to access your Google Photos. Without OAuth:
With OAuth 2.0:
User clicks “Connect with Google.” App redirects to Google’s authorization server with requested scopes (e.g., “read photos”).
User logs into Google (if needed) and sees a consent screen: “Photo Printer wants to access your photos. Allow?“
User approves. Google redirects back to the app with a short-lived authorization code.
App exchanges the authorization code for an Access Token (server-to-server, secure).
App uses the Access Token to call Google Photos API. Token proves authorization, not identity.
OAuth 2.0 has a critical limitation: it doesn’t tell you WHO the user is.
Access Token: "ey...abc123"Meaning: "Bearer of this token can read photos"Missing: Who is the user? What's their name? Email? User ID?This is where OpenID Connect comes in.
OpenID Connect (OIDC) extends OAuth 2.0 by adding an identity layer. It answers the question: “Who is this user?”
| OAuth 2.0 Component | OIDC Addition |
|---|---|
| Access Token | ID Token (user identity) |
Scopes (read, write) | openid, profile, email scopes |
| Token endpoint | UserInfo endpoint |
| - | Discovery document (.well-known/openid-configuration) |
| - | Standard claims (sub, name, email, picture) |
The ID Token is a JWT (JSON Web Token) containing claims about the authenticated user:
{ "iss": "https://accounts.google.com", "sub": "110248495921238986420", "aud": "your-client-id.apps.googleusercontent.com", "exp": 1735142400, "iat": 1735138800, "name": "Jane Developer", "email": "jane@example.com", "email_verified": true, "picture": "https://lh3.googleusercontent.com/..."}Key claims:
OIDC uses the same flow as OAuth 2.0, with key differences:
Include openid scope (required), plus profile and email as needed.
Server returns both an Access Token and an ID Token.
Verify signature, check issuer, audience, expiration. The ID Token is cryptographically signed proof of identity.
For additional claims not in the ID Token, call the UserInfo endpoint with the Access Token.
OAuth 2.0 alone is sufficient when you need:
Example: A scheduling app that posts to your Google Calendar. It doesn’t need to know who you are—just that you authorized calendar access.
OpenID Connect is required when you need:
Example: “Login with Google” on your web app. You need to know the user’s identity to create their account and personalize their experience.
OAuth 2.0 + OIDC together (the most common pattern):
Example: A project management app that logs you in with Okta (OIDC) and accesses your Jira issues (OAuth 2.0 API).
// WRONG - Never trust access tokens for identityconst user = await getUserFromAccessToken(accessToken);Access tokens are for API access, not identity. Always validate the ID Token for user identity.
// WRONG - Never skip validationconst claims = jwt.decode(idToken); // Just decodes, no verification!
// RIGHT - Always verify signatureconst claims = jwt.verify(idToken, publicKey, { algorithms: ['RS256'] });ID tokens are minted for specific clients. If your client_id isn’t in the aud claim, reject the token.
| Token Type | Browser Storage | Recommendation |
|---|---|---|
| Access Token | ❌ localStorage | ✅ Memory only, or httpOnly cookie |
| ID Token | ❌ localStorage | ✅ Validate and discard, or httpOnly cookie |
| Refresh Token | ❌ NEVER in browser | ✅ Server-side only |
| Protocol | Specification | Key Documents |
|---|---|---|
| OAuth 2.0 | IETF RFC 6749 | RFC 6749, RFC 6750 |
| OAuth 2.1 | Draft | Consolidates OAuth 2.0 best practices |
| OpenID Connect | OpenID Foundation | Core Spec |
| PKCE | RFC 7636 | Required for public clients |
| DPoP | RFC 9449 | Sender-constrained tokens |
OAuth 2.0 Deep Dive
Master all OAuth 2.0 flows: Authorization Code, Client Credentials, and more. OAuth 2.0 Guide →
OpenID Connect Deep Dive
Learn ID Token validation, discovery, and session management. OIDC Guide →
Implement SSO
Put it all together with a Single Sign-On implementation. SSO Patterns →
Secure Your Tokens
Learn about PKCE, DPoP, and token security best practices. Token Security →