DEV Community

Cover image for 🔐 Understanding SAML, OAuth 2.0 and OpenID Connect
Fazal Mansuri
Fazal Mansuri

Posted on

2

🔐 Understanding SAML, OAuth 2.0 and OpenID Connect

🔎 What Are These Protocols?

SAML 2.0 (Security Assertion Markup Language)

SAML is an authentication and authorization protocol primarily used for Single Sign-On (SSO) in enterprises. It enables users to log in once and access multiple applications without entering credentials again.

Used For: Enterprise authentication (e.g., logging into Google Workspace, Salesforce, etc.)

How It Works: Uses XML-based security assertions to exchange authentication and authorization data.

Downside: Verbose XML format, and not actively developed anymore.

OAuth 2.0 (Open Authorization)

OAuth 2.0 is an authorization protocol designed to grant limited access to resources without exposing user credentials. It’s commonly used for API access and delegated permissions.

Used For: Third-party API authorization (e.g., "Allow this app to access your Google Drive")

How It Works: Uses access tokens to grant specific permissions.

Downside: It doesn’t authenticate users—it just authorizes actions.

OpenID Connect (OIDC)

OIDC is an authentication protocol built on top of OAuth 2.0. It adds ID Tokens to OAuth, allowing applications to verify a user's identity in a secure, standardized way.

Used For: Modern authentication (e.g., "Sign in with Google")

How It Works: Extends OAuth 2.0 by providing identity tokens (JWTs) to verify users.

Why It’s Popular: Lightweight, JSON-based, and designed for modern web and mobile apps.


At this point, you might be thinking:

"Okay, I just read these definitions, but things still seem a bit confusing."

"Don’t worry—I felt the same when I first tried to understand them! So, let me break it down in the simplest way possible."

Before we jump into the story-based explanation, let’s first understand two key terms that will make everything clearer:

✔ Identity Provider (IdP):

The system that authenticates users and confirms their identity.

Example: Google, Okta, Microsoft Entra ID (Azure AD).

✔ Service Provider (SP):

The application or website that users want to access after authentication.

Example: Gmail, Slack, Salesforce.

💡 Think of it this way:

The IdP is like a security guard checking your ID before letting you in.

The SP is the building or service you’re trying to enter.


🔍 Let’s Understand This with a Story

Imagine a big amusement park 🎡 where visitors need special passes to access different rides.

In this park:
🎟 A Ticket (Token) = Proof of Access
🏛 The Ticket Counter (Identity Provider) = Authenticates visitors
🎢 The Ride (Service Provider) = Grants access based on the ticket

This analogy will help you understand how authentication and authorization work in each protocol.

1️⃣ SAML 2.0 – The VIP Pass for Employees

📖 Story: The Corporate Park & Employee Pass

SAML image with the amusement park analogy, where a visitor uses a single ticket to access multiple rides after verification.

Imagine one company that owns a huge amusement park. Employees don’t buy separate tickets for every ride—they get a VIP Employee Badge 🎫 from the HR office.

How It Works (SAML Flow):

1️⃣ 🏛 HR Office = Identity Provider (IdP)

Employees check in at the HR office (login page).

The HR office verifies who they are and issues a VIP badge (SAML token).

2️⃣ 🎢 Amusement Park Rides = Service Providers (SP)

The employee shows the badge at any ride’s entrance.

The ride operator trusts the badge (without asking for a password).

The employee gets access to the ride (authorization).

Key Takeaways:
✅ SSO (Single Sign-On): Employees log in once and access multiple rides.
✅ Authentication + Authorization: The badge confirms who you are and grants access to specific rides.
✅ Enterprise Use: Best for corporate authentication, but not ideal for modern mobile/web apps.
✅ Legacy & Declining Use: SAML is no longer actively developed, and many modern applications are shifting towards OpenID Connect (OIDC).

📌 Example Use Case:

A company uses SAML-based SSO so employees can log in once and access tools like Google Workspace, Salesforce, and Slack without re-entering credentials.


2️⃣ OAuth 2.0 – Borrowing a Friend’s Car (Authorization, Not Authentication)

📖 Story: The Car Rental & Borrowing Keys

OAuth 2.0, Rental car analogy

Imagine you need a rental car 🚗 (access to an app), but instead of getting a car yourself, you ask your friend to get it for you.

How It Works (OAuth Flow):

1️⃣ 🧍‍♂️ User (You) asks your Friend (Client App) to get a Car (Protected Resource).

You don’t have direct access to the rental car system.

Instead, you give your friend (third-party app) permission to get a car for you.

2️⃣ 🏛 Rental Agency (Authorization Server) issues a Car Key (Access Token).

The agency checks if your friend is authorized.

They issue a temporary key (OAuth token) that allows your friend to drive the car.

3️⃣ 🚗 Using the Car (Accessing Resources).

Your friend shows the car key and gets the car without needing your ID.

They can’t modify the rental agreement—just drive the car based on the given permission.

Key Takeaways:
✅ Authorization, Not Authentication: The car key doesn’t prove who you are, it just lets someone use a resource.
✅ Token-Based: If someone steals the key, they can use the car, even if they aren’t you (Bearer Token Risk).
✅ Used for API Access: Perfect for granting limited access to apps (e.g., "Allow this app to access your Google Drive").

🚨 Key Misconception:

OAuth ≠ Authentication. It’s about authorization (permissions), not logging in.


3️⃣ OpenID Connect (OIDC) – VIP Pass with Your Photo (Authentication + Authorization)

📖 Story: The All-Access Digital ID

OIDC, where a visitor uses a special wristband to enter an amusement park and access rides, symbolizing both authentication and authorization.

Now, imagine a more modern amusement park where you can:
✔ Use a digital ID 📱 instead of a paper ticket.
✔ Your ID has your photo to prove who you are (Authentication).
✔ Your ID also includes ride permissions (Authorization).

How It Works (OIDC Flow):

1️⃣ 🏛 Ticket Booth (Identity Provider) issues an ID with your photo.

The booth verifies your identity and gives you a digital ID (ID Token) with your photo and details.

2️⃣ 🎢 Amusement Park Scanners (Apps & APIs) accept the ID.

When you go to a ride, you scan your digital ID.

The system verifies your photo (Authentication) and checks ride access (Authorization).

Key Takeaways:
✅ Authentication + Authorization: OIDC proves who you are (ID Token) + controls what you can do (Access Token).
✅ Modern & Lightweight: Uses JSON instead of XML (simpler than SAML).
✅ Best for Web & Mobile Apps: Google, Facebook, and Microsoft use OIDC for "Sign in with Google/Facebook" logins.
✅ Replacing SAML: Many modern applications are shifting from SAML to OIDC for better support in web & mobile apps.


🤔 When to Use Which Protocol?

Use Case Best Choice Why?
Enterprise SSO (Internal Apps) SAML Secure, well-established in enterprises
Third-party API Access OAuth 2.0 Grants limited access without credentials
Social Login & Modern Web Apps OIDC Lightweight, authentication + authorization

🎯 Final Thoughts

Understanding SAML, OAuth and OIDC is crucial for securing applications. These protocols ensure users and apps interact securely without sharing sensitive credentials.

You might have noticed that SAML and OIDC seem similar—both handle authentication and enable Single Sign-On (SSO). However, the key difference is how they work:

✔ SAML: Uses XML, is enterprise-focused, and is mainly for web-based applications.
✔ OIDC: Uses JSON, is lightweight, and works well for modern web and mobile apps.

While SAML is older and widely used in enterprises, OIDC is the future—it’s more flexible and designed for modern applications.

🚀 If your system already uses SAML, you might stick with it. But if you're building something new, OIDC is likely the better choice!

💬 Which protocol have you worked with the most? Let’s discuss in the comments! 🚀

Heroku

Built for developers, by developers.

Whether you're building a simple prototype or a business-critical product, Heroku's fully-managed platform gives you the simplest path to delivering apps quickly — using the tools and languages you already love!

Learn More

Top comments (0)

AWS Security LIVE!

Tune in for AWS Security LIVE!

Join AWS Security LIVE! for expert insights and actionable tips to protect your organization and keep security teams prepared.

Learn More

👋 Kindness is contagious

Engage with a wealth of insights in this thoughtful article, valued within the supportive DEV Community. Coders of every background are welcome to join in and add to our collective wisdom.

A sincere "thank you" often brightens someone’s day. Share your gratitude in the comments below!

On DEV, the act of sharing knowledge eases our journey and fortifies our community ties. Found value in this? A quick thank you to the author can make a significant impact.

Okay