SAML Authentication (original) (raw)

Last Updated : 1 Jun, 2026

SAML is an XML-based open standard used to securely exchange authentication and authorization data between identity providers and service providers. It enables Single Sign-On (SSO), allowing users to authenticate once and access multiple applications without repeated logins.

Core Components of SAML

SAML works by defining clear roles for the parties involved in an authentication request:

SAML Authentication Workflow

The most common SAML workflow is SP-initiated. Here is a step-by-step breakdown:

user-

SAML Authentication Workflow

Key Elements of a SAML Request

A SAML request contains important data that ensures secure and correct authentication:

SAML Response Structure

The SAML response is divided into two main parts:

Key Generation in SAML Authentication

The process of signing and verifying the SAML response involves asymmetric key generation:

This public/private key pair ensures that only valid, IdP-signed responses are accepted, providing a strong layer of security.

Vulnerabilities and Best Practices for SAML

While SAML is a mature and secure protocol, misconfigurations can lead to serious vulnerabilities.

1. Improper Signature Validation

2. SAML Replay Attacks

**Note: XML comment injection exploits how different parsers read the same NameID value, not a registration bypass.

SAML vs. OAuth/OIDC

SAML, OAuth 2.0, and OpenID Connect are three widely used protocols that are often conflated. Each solves a distinct problem, verifying who the user is, deciding what they can access and combining both in a modern lightweight package.

**Feature **SAML 2.0 **OAuth 2.0 **OpenID Connect (OIDC)
**Primary Goal **Authentication (IdP confirms user identity to an SP). **Authorization (User grants app access to specific data). **AuthN + AuthZ (Identifies user _and grants permissions).
**Data Format **XML (Structured Assertions). **Opaque Tokens or JSON (Access Tokens). **JWT (JSON Web Tokens - ID Tokens).
**Transport Browser-only (HTTP POST/Redirect). API-centric (HTTP Headers/Back-channel). API-centric + Browser redirects.
**Token Validity Short-lived assertions (usually 5–10 mins). Short-lived Access Tokens + **Refresh Tokens. ID Token (session) + Refresh/Access Tokens.
**Trust Model Pre-configured (XML Metadata Exchange). Dynamic (Scopes and Consent screens). Semi-dynamic (Discovery endpoints).
**Session Control Managed by IdP (Single Log-Out is hard). Managed by Auth Server (Token revocation). Standardized "Logout" & "Check Session".
**User Info Access Assertions contain all info at login. Requires extra API call to Resource Server. Standardized /userinfo endpoint.
**Mobile Suitability **Poor (Hard to handle XML/Redirects). **Excellent (Native app support). **Excellent (Native/Web hybrid).

When to Use SAML, OIDC, or OAuth

SAML, OAuth, and OIDC are not strict alternatives ; they are complementary technologies that can work together.