Introduction
OAuth 2.0 and OpenID Connect (OIDC) are the standards behind "Login with Google/GitHub/etc." They're powerful but often misunderstood. Let's clarify.
OAuth 2.0: Authorization
OAuth 2.0 is an authorization framework. It allows applications to access resources on behalf of a user without knowing their password.
Key Terms
- Resource Owner: The user
- Client: Your application
- Authorization Server: Issues tokens (Google, Okta)
- Resource Server: Hosts protected resources (API)
OAuth 2.0 Flows
Authorization Code (Recommended)
For server-side applications with a backend.
Authorization Code + PKCE
For SPAs and mobile apps (no client secret).
Client Credentials
For machine-to-machine communication.
OpenID Connect: Authentication
OIDC is a layer on top of OAuth 2.0 that adds authentication (proving who the user is).
ID Token
A JWT containing user identity claims (sub, email, name).
UserInfo Endpoint
API to fetch additional user profile information.
Token Types
- Access Token: Short-lived, used to access APIs
- Refresh Token: Long-lived, used to get new access tokens
- ID Token: Contains user identity (OIDC)
Best Practices
- Always use HTTPS
- Validate tokens properly (signature, expiry, audience)
- Use short-lived access tokens (15 min)
- Store refresh tokens securely
- Implement token rotation
Conclusion
OAuth 2.0 handles authorization, OIDC adds authentication. Use Authorization Code + PKCE for web apps, Client Credentials for services. Always validate tokens server-side.
