SAML, OAuth 2.0, OpenID Connect (OIDC)
๐ช Quick Definitions
Protocol | What it Does | Used For |
---|---|---|
SAML | Authentication | Web-based SSO (Single Sign-On) |
OAuth 2.0 | Authorization (not authentication) | Letting apps access resources on behalf of a user |
OpenID Connect (OIDC) | Authentication (built on OAuth 2.0) | Logging users into apps securely |
๐ง What Each One Is
๐ SAML (Security Assertion Markup Language)
Old but gold — XML-based standard.
Used for authentication (NOT authorization).
Popular for SSO in enterprise environments (e.g., login to Salesforce, Google Workspace, etc.).
Works with browsers and web apps.
๐ Flow Summary:
User tries to access an app (called Service Provider).
App redirects user to Identity Provider (IdP) (like Azure AD, Okta).
User logs in.
IdP sends back a SAML assertion (XML) to the app.
App verifies the assertion → user gets access.
✅ Common Use Case:
Enterprise SSO: "Log in to Workday using your company credentials."
๐ OAuth 2.0
A framework for authorization.
Doesn't deal with identity directly (so it doesn’t log users in).
It lets apps access data on behalf of a user, without sharing the user’s password.
๐ Flow Summary:
User logs into App A.
App A asks App B (like Google or Microsoft): "Can I access this user’s calendar?"
User is redirected to App B to approve access.
App B gives App A a token to access calendar data.
✅ Common Use Case:
Giving a third-party app permission to access your Google Drive, Microsoft Graph, or GitHub repo.
๐งพ OpenID Connect (OIDC)
An identity layer built on top of OAuth 2.0.
Adds authentication to OAuth.
Returns an ID token (JWT) that confirms who the user is.
Supports mobile apps, web apps, APIs, and SPAs (single-page apps).
๐ Flow Summary:
User logs into an app.
App redirects to an Identity Provider (IdP) like Microsoft, Google, or Auth0.
User authenticates.
IdP sends back:
ID token → proves user’s identity
Access token → lets app access user data (optional)
✅ Common Use Case:
Logging into a mobile app using "Sign in with Google" or Microsoft.
๐ Key Differences
Feature | SAML | OAuth 2.0 | OpenID Connect (OIDC) |
---|---|---|---|
Purpose | Authentication | Authorization | Authentication + Authorization |
Standard Format | XML | JSON (tokens) | JSON (JWTs) |
Main Use Case | SSO for enterprise web apps | Delegated access to APIs | User login (web, mobile, APIs) |
Mobile Friendly | ❌ Not ideal | ✅ Yes | ✅ Yes |
Token Type | SAML Assertion (XML) | Access Token | ID Token (JWT) + Access Token |
Password Shared? | No | No | No |
Built On | N/A | N/A | Built on top of OAuth 2.0 |
๐ฏ When to Use What?
Scenario | Best Protocol |
---|---|
SSO for enterprise web apps | SAML |
Letting a 3rd party app access user data (e.g., calendar, files) | OAuth 2.0 |
Logging users into a web/mobile app using Google/Microsoft | OpenID Connect |
๐งช Real-Life Example:
Imagine you're building a mobile app that lets users view their Outlook calendar.
Use OpenID Connect to authenticate the user.
Use OAuth 2.0 to get a token that allows you to access their calendar data via Microsoft Graph API.