🔐 OAuth 2.0 and OpenID Connect (OIDC)
They’re closely related, but they serve different purposes:
Protocol | Purpose | Summary |
---|---|---|
OAuth 2.0 | Authorization | Lets an app access your data on another service without your password |
OpenID Connect (OIDC) | Authentication (Login) | Built on top of OAuth 2.0 — confirms who you are |
🧩 OAuth 2.0 — Delegated Authorization
💡 Definition
OAuth 2.0 is an open standard that allows users to grant a third-party app limited access to their resources on another service — without sharing their password.
🎯 Purpose
“Let this app do something on my behalf.”
🔄 Example: OAuth 2.0 Flow (Real-world)
You’re using a fitness app that wants to read your Google Fit data.
- The app redirects you to Google’s authorization page.
- You log into Google and see a consent screen:
“Allow this app to view your Google Fit data?” - If you agree, Google issues the app an Access Token.
- The app uses that token to fetch your fitness data — without ever seeing your Google password.
⚙️ OAuth 2.0 Key Roles
Role | Description | Example |
---|---|---|
Resource Owner | The user who owns the data | You |
Client | The app requesting access | Fitness app |
Authorization Server | Issues tokens after user consent | Google’s OAuth server |
Resource Server | API that holds the data | Google Fit API |
🔑 OAuth 2.0 Tokens
Token Type | Description | Example |
---|---|---|
Access Token | Grants access to a resource | Used by app to call Google API |
Refresh Token | Used to get a new access token without user login | Keeps session alive |
🔄 OAuth 2.0 Grant Types (Flows)
Flow | Used For | Description |
---|---|---|
Authorization Code Flow | Server-side web apps | Most secure, uses separate steps to exchange code for token |
Implicit Flow | Browser apps (legacy) | Now discouraged due to security risks |
Client Credentials Flow | Machine-to-machine | No user, uses app credentials only |
Password Flow | Legacy apps | User credentials sent directly (deprecated) |
🧭 OpenID Connect (OIDC) — Authentication Layer
💡 Definition
OpenID Connect (OIDC) is a simple identity layer built on top of OAuth 2.0 that allows clients to verify the user’s identity and obtain basic profile information.
While OAuth 2.0 says:
“App A is allowed to access user’s data.”
OIDC adds:
“And the user’s name is Alice, with email alice@example.com.”
🧠 How OIDC Works (Simplified)
- The app (client) redirects you to the identity provider (like Google).
- You log in once.
- The IdP sends back:
- An ID Token (JWT) → proves your identity.
- An Access Token → allows the app to access APIs.
- The app uses the ID Token to authenticate you.
🧾 Example of an ID Token (JWT)
{
"iss": "https://accounts.google.com",
"sub": "1122334455",
"email": "alice@gmail.com",
"name": "Alice Johnson",
"iat": 1739050000,
"exp": 1739053600
}
This tells the app:
The user is Alice, authenticated by Google, and the token expires in one hour.
⚙️ OIDC Endpoints
Endpoint | Purpose |
---|---|
/authorize | User login and consent |
/token | Exchange authorization code for tokens |
/userinfo | Get user’s basic profile info |
/.well-known/openid-configuration | Metadata about the IdP (used by apps to integrate easily) |
⚖️ OAuth 2.0 vs OpenID Connect (OIDC)
Feature | OAuth 2.0 | OpenID Connect (OIDC) |
---|---|---|
Purpose | Authorization (access to resources) | Authentication (login & identity) |
Token Type | Access Token | Access Token + ID Token |
Data Format | Usually JSON | JSON Web Tokens (JWT) |
Used For | APIs, app integrations | Single Sign-On, user login |
Example | A photo editor accessing your Google Drive photos | Logging into Reddit with your Google account |
🌍 Real-World Examples
Provider | Protocol Used | Example |
---|---|---|
OAuth 2.0 + OIDC | “Sign in with Google” | |
Microsoft | OAuth 2.0 + OIDC | Office 365 / Azure AD logins |
GitHub | OAuth 2.0 | Third-party apps accessing your repos |
OAuth 2.0 + OIDC | “Login with Facebook” |
✅ Summary
Concept | OAuth 2.0 | OpenID Connect (OIDC) |
---|---|---|
Primary Goal | Authorization | Authentication |
Defines | How apps access user data | How apps verify user identity |
Token | Access Token | ID Token (JWT) |
Common Use | APIs, integrations | SSO, user login |
Example | Allow an app to post to Twitter for you | Log in to Twitter with Google |