SDSystem DesignConcepts to case studies
System DesignDSA
x
0/311
Part 1: Foundations
Part 2: APIs and Communication
Part 3: Caching
Part 4: Data and Storage
Part 5: Architecture
Part 6: Distributed Systems
Part 7: Advanced Data Topics
Part 8: Operations and Security
  • SSL/TLS
  • Encryption at Rest
  • Secrets Management
  • Password Management
  • RBAC
  • SAML
  • OWASP Top 10 and Common Attacks
  • DDoS Attacks and Defenses
  • Web Application Firewall (WAF)
  • Certificates and PKI
  • Multi-Factor Authentication (MFA)
  • Zero Trust
  • Key Management (KMS)
  • Data Privacy and GDPR Basics
Part 9: Estimation and Interview Method
Part 10: Case Studies
System Design/Operations and Security/Advanced Security

SAML

An XML-based way for a company login to sign users in to other apps.

⏱ 13 min readAdvancedHas visualizer
SummaryConceptReal-Life ExampleWhy?Where?How It WorksStepsKey TermsPros & ConsMistakesReal WorldRead NextInterview Q&ACheat-Sheet

01Quick Summary

SAML (Security Assertion Markup Language) lets a company login system tell other apps who a user is, using a signed XML message. The user signs in once, and many apps trust the answer.

  • The identity provider (IdP) knows the user and checks the password and MFA.
  • The service provider (SP) is the app the user wants to open. It never sees the password.
  • The IdP sends a signed assertion (a statement about the user). The SP checks the signature and lets the user in.

02Concept: What is it?

Big companies use dozens of apps: email, HR, finance, ticketing. They do not want a separate password in each one. With SAML single sign-on, the company runs one login system (the IdP, such as Okta, Microsoft Entra ID or Active Directory Federation Services). Every app (the SP) trusts it.

The trust is built before anyone logs in. The IdP and the SP exchange metadata: an XML file with names, URLs and the public key the IdP uses to sign. Later, the SP can check that a message really came from the IdP, because only the IdP has the matching private key.

The three players
🧑Userbrowser
↔redirects and posts
🏢Service providerthe app
↔trust (metadata)
🪪Identity providercompany login
The browser carries the messages between the app and the identity provider.

The main message is the assertion. It says things like: "This is alice@company.com. She signed in with MFA at 10:02. Her role is viewer. This statement is meant for app.example.com and is valid until 10:05." The IdP signs it, so nobody can change it.

🧠SAML proves who you are, not what you may do
SAML is about authentication (and passing a few attributes). What the user can do inside the app is still decided by the app, for example with roles (RBAC).

03Real-Life Example

🍵The Embassy Letter
You want to enter a secure research lab (the app). The guard at the door does not know you. But the lab trusts your company's head office (the IdP). So you go to head office first. They check your passport and staff badge, then write a sealed letter: "This is Alice, a viewer, and this letter is only for the research lab, valid until 10:05." They stamp the letter with a seal that only head office owns. You carry the letter to the guard. The guard checks the seal (using a sample of the stamp they got earlier), the name of the lab, the time and that the letter is an answer to the request they gave you. If all is fine, you walk in.
Embassy letter
SAML
Head office
Identity provider (IdP)
The research lab
Service provider (SP)
The sealed letter
Signed assertion
The stamp only head office owns
The IdP's private signing key
A sample of the stamp given to the guard earlier
Public key in the metadata
'Only for the research lab'
Audience restriction
'Valid until 10:05'
NotBefore and NotOnOrAfter times
'This answers your request number 42'
InResponseTo
SP-initiated sign-in in short
🙋Open app
→↓
➡️Redirect to IdPAuthnRequest
→↓
🔐Sign inpassword + MFA
→↓
📨Post to appsigned assertion
→↓
✅Session

04Why Do We Need It?

🔑One login for many apps
Users remember one password (and one MFA), not twenty.
🛡️Apps never see passwords
Only the IdP handles credentials, so there are fewer places to leak them.
🏢Central control
IT can add MFA, or switch off a leaver, in one place, and every app follows.
🧾Audit in one place
All sign-ins pass through the IdP, so there is one log to review.
🤝Works between companies
A partner company's users can sign in to your app with their own login (federation).
📦Enterprise buyers ask for it
Large customers often will not buy a product that cannot use their SSO.
Let one trusted place check the password, and let every app trust its signed word.

05Where Do We Use It?

🏭Company intranets
HR, payroll, expenses and internal tools behind the corporate login.
☁️SaaS products for businesses
Tools such as ticketing, CRM and chat offer 'sign in with your company SSO'.
🎓Universities
Many campuses and research groups share logins through federations.
🏛️Government and health
Portals that need strong identity checks often use SAML.
☁️Cloud consoles
Companies let staff reach cloud accounts through their IdP instead of separate users.
🔌Older enterprise apps
SAML is older than OIDC, so many long-lived systems still speak it.

06Types / Parts / How It Works

The main parts

PartWhat it isWhy it matters
IdP (identity provider)The system that signs users in and issues assertionsThe one source of truth about identity
SP (service provider)The app that accepts the assertionTrusts the IdP, decides what the user can do
MetadataXML describing entity IDs, URLs and public keysSets up trust before any login
AuthnRequestThe app's request to sign the user inCarries a request ID to match the answer
AssertionThe signed statement about the userThe core of SAML
ACS URLAssertion Consumer Service: where the app receives the responseMust be exact, or an attacker could redirect it
AttributesExtra facts such as email, name, groupsMapped to the app's own user and roles

Two ways to start

SP-initiated and IdP-initiated
SP-initiated (recommended)
🏢User opens the app
↓AuthnRequest
🪪IdP signs user in
↓response with InResponseTo
✅App checks the match
IdP-initiated
🪪User clicks the app tile at the IdP
↓unrequested response
⚠️App has no request to match
SP-initiated is safer, because the app can match the answer to its own request.

SAML compared with OAuth2 and OpenID Connect

SAMLOAuth2OpenID Connect (OIDC)
Main jobSign users in (SSO), enterprise web appsLet an app call an API for you (delegated access)Sign users in, built on OAuth2
Message formatXML, signedTokens, often JSON or opaqueJSON Web Tokens (JWT)
Typical clientsBrowser-based enterprise appsWeb, mobile and server appsWeb, mobile and single-page apps
WeightHeavier, more set-upLighterLighter
AgeOlder, very common in enterprisesNewerNewer, the usual choice for new apps
VisualizerSAML sign-in, step by step, and the four checksStep through the seven steps with the normal flow first. Then pick an attack (an edited role, an old assertion, a wrong audience, a replay) and watch which one of the four checks stops it.
What happens to the response?

A normal sign-in. The app checks four things and lets the user in.

🧑Userbrowser
🏢Service providerthe app (SP)
🪪Identity providercompany login (IdP)
↓GET /dashboard
no session cookie, user is unknown
Step 1 of 7
1. The user opens the app
The user goes to the app (the service provider). The app sees no session, so it does not know who this is. It will ask the company's identity provider.

A simplified teaching flow. Real responses are longer XML, are signed with XML signatures, and an app should use a well-tested SAML library, never hand-written parsing. The times and IDs shown are illustrative.

07How to Use It / Steps / Implementation

Adding SAML sign-in to an app

  1. 1
    Use a tested library
    Never parse and verify SAML XML by hand. Use a well-maintained library or an identity service. XML signatures are full of traps.
  2. 2
    Exchange metadata
    Give the IdP your entity ID and ACS URL. Load the IdP's metadata so you know its signing certificate and login URL.
  3. 3
    Send an AuthnRequest
    Create a fresh request ID, store it (for example in the session), and redirect the user to the IdP.
  4. 4
    Receive the response at the ACS URL
    Accept a POST only on the exact ACS URL you registered.
  5. 5
    Verify before you trust
    Check the signature against the IdP's key, the audience, the time window, the destination, and that InResponseTo matches a request you made. Reject on any failure.
  6. 6
    Use each assertion once
    Keep the assertion IDs you have seen for a short time, so a captured response cannot be replayed.
  7. 7
    Map attributes to your user
    Match on a stable ID (not a changeable name), create or update the user, and map groups to your own roles.
  8. 8
    Start a normal session
    After success, issue your own session cookie. Plan for logout, and for rotating the IdP certificate.
⚠️Allow a little clock skew, not a lot
The app and the IdP clocks are never exactly the same. Allow a small tolerance (a few minutes at most) on the time window. Too strict and good logins fail. Too loose and old assertions work for longer.
💡Sign the assertion, and check what was signed
Make sure the data you read is exactly the data that the signature covers. Reading from a different part of the XML than the signed part is the root of the "signature wrapping" attack.

08Key Terms to Know

TermMeaning in easy words
SAMLSecurity Assertion Markup Language: an XML standard for passing identity between systems
IdPIdentity provider: signs users in and issues assertions
SPService provider: the app that trusts the IdP
AssertionThe signed XML statement about a user
MetadataXML that shares entity IDs, URLs and public keys between IdP and SP
ACS URLAssertion Consumer Service URL, where the SP receives the response
Entity IDA unique name for an IdP or SP
AuthnRequestThe SP's request asking the IdP to sign the user in
InResponseToA field in the response that points to the request ID it answers
Audience restrictionSays which SP the assertion is meant for
FederationTrust between separate organisations so their users can use each other's apps

09Pros, Cons and Trade-offs

✅ Pros
  • Single sign-on across many apps
  • Passwords stay at the IdP
  • Mature and widely supported in enterprises
  • Central MFA and central access removal
  • Works across company boundaries
⚠️ Cons
  • Verbose XML and a tricky signature standard
  • Set-up is manual (metadata, certificates, URLs)
  • Built for browsers, awkward for mobile and APIs
  • Certificate expiry can break logins suddenly
  • Mistakes in verification cause serious security holes

Trade-offs

ChoiceWe gainWe lose
SAMLStrong enterprise support and many existing IdPsHeavier set-up, XML complexity
OIDCSimpler JSON tokens, good for mobile and single-page appsSome older enterprise apps cannot use it
SP-initiated loginResponse is tied to a request (InResponseTo)Users must start from the app
IdP-initiated loginHandy app tiles in the IdP portalNo request to match, easier to replay or inject
Short assertion lifetimeA stolen assertion is useful for a short timeClock skew errors become more likely
Encrypted assertionsHides user data from the browser and intermediariesMore keys to manage

10Common Problems and Mistakes

Common mistakes

  1. Not checking the signature, or checking it but reading data from an unsigned part of the XML (signature wrapping).
  2. Hand-written XML parsing instead of a trusted library.
  3. Ignoring the audience. An assertion made for another app is accepted here.
  4. No time check, or a huge clock tolerance. Old assertions keep working.
  5. No replay protection. The same response can be posted again and again.
  6. Loose ACS URL or redirect checks, so a response can be sent to the wrong place.
  7. Matching users by a changeable value such as a display name or an email that can be re-used.

Things to watch

📅Certificate expiry
The IdP's signing certificate ends one day. Plan the rollover, or all logins fail.
⏱️Clock drift
If server clocks drift, valid assertions look expired or not yet valid. Use time sync (NTP).
🚪Logout is hard
Signing out of the app does not always sign the user out of the IdP or other apps.
🧩Group mapping
A wrong mapping of IdP groups to app roles can give too much access.

11Real-World Examples

🪪Okta and Microsoft Entra ID
Popular identity providers. They act as the IdP for thousands of SaaS apps.
🏢Active Directory Federation Services
A long-used way for companies to offer SAML sign-in from their own directory.
☁️Cloud and SaaS tools
Many business tools (cloud consoles, chat, ticketing, CRM) support 'single sign-on with SAML'.
🎓Research and education
National federations let staff and students use one login across institutions.
🤝Partner portals
A supplier's staff can open your portal with their own company login.
🛠️Open-source options
Keycloak and similar tools can be an IdP or a broker that speaks SAML and OIDC.
📝Note
Product names and screens change. Follow the current guide of your IdP and your SAML library.
Mini case: a new customer wants SSO
🏢Customer IdPtheir company login
↔exchange metadata
🧩Your SaaS appSP
→↓map groups to roles
🎭Your rolesviewer, editor
Identity App Permissions
The customer's IT team sets up the trust once. Their users then sign in with their own login.

12Related Topics to Read Next

Single Sign-On (SSO)→

SAML is one of the main ways to do SSO.

OAuth / OAuth2→

A different standard: delegated access to APIs.

JWT→

OpenID Connect uses JWTs where SAML uses XML assertions.

Authentication vs Authorization→

SAML answers who you are. Roles answer what you may do.

RBAC→

Groups from the assertion are often mapped to roles in the app.

SSL/TLS→

SAML messages travel over HTTPS, and signatures add a second layer.

13Interview Questions with Short Answers

14Quick Revision Cheat-Sheet

  • ✔What: XML single sign-on. The IdP signs an assertion, the SP trusts it.
  • ✔Players: user (browser), SP (the app), IdP (company login).
  • ✔Setup: swap metadata (entity IDs, URLs, public key, ACS URL).
  • ✔Flow: AuthnRequest, IdP login, signed assertion posted to ACS, session.
  • ✔Verify: signature, audience, time window, InResponseTo, and no replay.
  • ✔Attacks: signature wrapping, replay, wrong audience, loose ACS URL.
  • ✔Versus: OIDC is the lighter, newer choice. OAuth2 is for API access, not login.
  • ✔One line: “A company login signs a letter about you, and the app checks the seal.”
← Previous
RBAC
Next →
OWASP Top 10 and Common Attacks