Security Assertion Markup Language (SAML) 2.0 is an XML-based protocol that enables identity federation between separate security domains to deliver Single Sign-On (SSO). SAML allows users to authenticate with an identity provider (IdP) once and then access multiple service providers (SPs) without needing to re-enter their credentials.
SAML 2.0 was ratified as an OASIS open standard in 2005. It remains widely used for enterprise and government identity federation, though OpenID Connect (OIDC) has become increasingly common for modern applications.
Example: When you log in to your company’s internal hub, SAML allows you to immediately access GitHub Enterprise repositories, Jira tickets, and Confluence documentation throughout the day without providing your credentials again for each tool. The portal acts as either a SP or an IdP-hosted application launcher, and the downstream tools (Jira, GitHub Enterprise) are additional SPs that trust the same IdP.
SAML supports two initiation patterns, both resulting in SSO.
When a user tries to access the application directly:
When a user starts from their corporate dashboard:
Both flows verify identity without requiring passwords to be shared between systems. The IdP may require multi-factor authentication (MFA) before issuing the assertion, adding an extra security layer.
IdP-initiated SSO does not include an InResponseTo value from the SP. SPs rely more on assertion timestamps (NotBefore/NotOnOrAfter) and replay protection when validating IdP-initiated assertions.
SAML enables identity federation through three main components:
The assertion confirms the user’s identity and the access they are authorized to have, allowing the SP to grant or deny access without handling the user’s credentials directly.
A SAML assertion is a structured XML document with three statement types:
The assertion includes:
NotBefore and NotOnOrAfter) and the intended audienceThe assertion may be encrypted, typically the <Assertion> element rather than the entire <Response>, though individual attributes may also be encrypted for sensitive data. The SP must be able to decrypt encrypted elements if necessary.
Developers often confuse SAML with OAuth 2.0 and OIDC. Here’s how they compare:
| Aspect | SAML 2.0 | OAuth 2.0 | OpenID Connect |
|---|---|---|---|
| Primary Use | Enterprise SSO authentication | Delegated authorization | Modern authentication |
| Format | XML (Complex parsing; risk of XML signature wrapping attacks) | Token format agnostic in the specification, though many implementations use JWT access tokens | JSON-based (JWT ID Token) |
| Token Type | SAML Assertion | Access Token | ID Token and Access Token |
| Transport | Authentication requests commonly use HTTP-Redirect; assertions are almost always delivered via HTTP-POST | Typically via HTTP Authorization header (Bearer tokens), though other transports (form_post/query) exist depending on the flow | HTTP Authorization header |
| Mobile Support | Poor support for native apps (often requires WebView or a broker app) | Excellent | Excellent |
| Target Audience | Enterprises, governments | Consumer apps, APIs | Consumer apps, modern enterprises |
| Use Case | Enterprise SSO, workforce authentication | API access delegation, third-party integrations | Modern apps, mobile authentication, consumer SSO |
OAuth 2.0 handles authorization (what you can do), not authentication (who you are). OAuth 2.0 alone is not an authentication protocol. Providers often use proprietary methods to layer identity information on top; however, these methods are not standardized. OpenID Connect is the standard for adding authentication to OAuth 2.0.
SAML handles authentication and can include authorization attributes, but it is not an authorization framework. Authorization decisions are made in your application after SAML authentication is complete.
The protocols aren’t mutually exclusive. Many identity platforms support all three, letting you choose based on your users’ needs.
SAML relies on XML signatures for security. Implementing validation correctly is complex:
<Response> or the <Assertion>, depending on configuration) and ensure only the expected element is processedA single mistake in signature validation creates security vulnerabilities. Attackers can exploit XML-signature wrapping to bypass authentication.
Consider using a tested SAML library instead of building one from scratch.
SAML assertions include (NotBefore) and (NotOnOrAfter) conditions. Clock differences between IdP and SP can cause valid assertions to be rejected.
Best practices:
SAML typically uses metadata exchange between IdP and SP, although it is not strictly required by the specification:
Metadata changes break SSO. When IdPs rotate certificates, you must update the configuration. Some enterprises require manual approval for SP metadata changes, which can delay deployments.
Store IdP metadata in your database, not configuration files. Not all IdPs support dynamic metadata URLs. When available, auto-refresh is the best practice.
Different IdPs send different attribute names. The application needs flexible attribute mapping to handle these variations. Let customers configure which SAML attributes map to your application’s user fields.
When using role-based access control (RBAC), IdPs can send role information in SAML attributes. The application must map these IdP roles to the internal permission system.
Every SAML assertion must be cryptographically validated to confirm:
Never skip signature validation, even in development. It’s the foundation of SAML security.
Beyond signatures, validate:
The SAML specification doesn’t mandate one-time use of assertions, making replay protection the SP’s responsibility.
NotOnOrAfter window, ideally with a small buffer (a few seconds) to account for network latencyAs a first defense, the SP should validate NotBefore and NotOnOrAfter timestamps. Caching assertion IDs is secondary.
SAML assertions should only be transmitted over HTTPS. Even though they are signed, transmitting them over HTTP exposes users to man-in-the-middle attacks.
Configure the assertion consumer service (ACS) URL with HTTPS only. Most IdPs will warn or block HTTP endpoints.
SAML supports single logout (SLO), enabling users to sign out of all connected applications simultaneously. Implementation is optional but recommended for security-sensitive applications.
SLO can be front-channel (browser redirects) or back-channel (server-to-server). Front-channel SLO is widely supported but fragile. Back-channel logout exists, but it is complex and rarely implemented. Interoperability varies since different IdPs and SPs implement SLO differently, so expect to test multiple providers.
Building a secure SAML implementation from scratch requires deep XML security expertise and is generally recommended only for IdP implementations or highly specialized use cases.
Consider your options:
Some identity platforms help handle SAML complexity by providing:
This approach provides SAML support for enterprise customers while using modern protocols (OIDC, OAuth 2.0) for consumer-facing applications. Some platforms translate between protocols seamlessly.
For teams that need more control, mature SAML libraries handle XML parsing, signature validation, and low-level protocol details:
passport-saml, samlifypython3-saml, pysaml2Spring Security SAML, OpenSAMLSustainsys.Saml2, ITfoxtec.Identity.Saml2ruby-samlSimpleSAMLphpEven mature SAML libraries do not automatically handle replay attacks or encrypted assertions. Developers must implement caching/nonces and decryption as needed, and ensure the signature reference is verified.
Choose SAML when:
Choose OIDC or OAuth 2.0 when:
Many applications support multiple protocols. Your IdP choice should support both SAML for enterprise customers and OIDC for all other users. Consider using passwordless authentication methods, like WebAuthn and passkeys, to enhance user experience.
Before launching SAML support, test thoroughly:
Each IdP implements SAML slightly differently. Don’t assume behavior from one IdP applies to others. Attribute names, metadata formats, and certificate handling vary.
Log all SAML validation failures with assertion ID, reason, IdP entity, and timestamp for debugging. These logs are essential for debugging customer issues. SAML failures are often due to configuration issues rather than code bugs.
SAML provides SSO by enabling identity federation for enterprise users. Its main benefit is to simplify application security by shifting responsibility for storing and managing user passwords to a dedicated IdP. This reduces the application’s attack surface, cuts down on help desk calls for password resets, and centralizes policy enforcement.
SAML is primarily an authentication and federation protocol, designed to verify user identity. It is not, by itself, an authorization framework like OAuth 2.0. SAML answers the question: “Who is this user?” by transmitting a signed assertion (an identity statement) from an IdP to a SP. Authorization (determining what the user can do) occurs after SAML authentication completes, typically via user attributes (e.g., role or department) found in the SAML assertion.
SAML is an older, XML-based standard designed for enterprise identity federation and workforce SSO. OAuth 2.0 is an authorization framework issuing access tokens to grant delegated, limited-scope access to APIs. OIDC is an identity layer built on OAuth 2.0 that adds standardized authentication via ID tokens (JWTs), optimized for web, mobile, and API-driven applications. All three enable access, but SAML focuses on enterprise SSO, whereas OAuth and OIDC are better suited for today’s application authentication and API authorization.
Yes. SAML remains a dominant protocol for enterprise SSO, particularly in large organizations and government agencies with existing identity infrastructure. While OIDC has gained traction for applications, SAML’s widespread enterprise adoption means it continues to be actively used and supported.
SAML is secure when implemented correctly. The protocol uses XML digital signatures and encryption to protect identity data. Risks can stem from improper validation of assertions. SPs must verify XML signatures, validate assertion conditions (including issuer, audience, and timestamps), and implement replay protection.
Auth0 helps developers implement SAML quickly and securely, enabling enterprise SSO without building or maintaining SAML infrastructure from scratch.
Explore our Intro to IAM series on identity and access management.
These materials are intended for general informational purposes only. You are responsible for obtaining security, privacy, compliance, or business advice from your own professional advisors and should not rely solely on the information provided herein.
Table of contents
Quick assessment
Which of the following is a SAML benefit?
Quick assessment
Why is Single Sign On (SSO) a benefit for users?
Quick assessment
What role does an Identity Provider (IdP) play in SAML 2?