OAuth 2.0 handles authorization (what you can access). OpenID Connect (OIDC) adds authentication (who you are). Together, they power secure authentication for modern applications.
Understanding the Difference#
OAuth 2.0 = Authorization
"Can this app access my photos?"
Result: Access token
OpenID Connect = Authentication
"Who is this user?"
Result: ID token + Access token
OIDC is built on top of OAuth 2.0
OAuth 2.0 Flows#
Authorization Code Flow (Recommended)#
Best for: Server-side applications
┌──────┐ ┌────────────────┐ ┌──────────────┐
│ User │────▶│ Authorization │────▶│ Your Server │
└──────┘ │ Server │ └──────────────┘
└────────────────┘
│
▼
Authorization Code
│
▼
Exchange for Tokens
Authorization Code Flow with PKCE#
Best for: Single-page apps, mobile apps (no client secret)
PKCE = Proof Key for Code Exchange
Prevents authorization code interception attacks
Client Credentials Flow#
Best for: Machine-to-machine communication
Tokens#
Access Token#
ID Token (OIDC)#
Refresh Token#
Scopes#
Security Best Practices#
Token Storage#
Validate Tokens#
Prevent Common Attacks#
Logout#
Conclusion#
OAuth 2.0 and OIDC provide robust authorization and authentication. Use PKCE for public clients, validate all tokens properly, and never store sensitive tokens in browser storage.
Start with a well-tested library (Auth0, Okta, NextAuth.js) rather than implementing from scratch. The security details matter greatly.