Modern organizations often use many separate applications. Employees may need access to email, cloud storage, learning platforms, finance systems, internal dashboards, and external software services. Creating and managing a separate username and password for every system would be inconvenient and difficult to secure.
SAML helps solve this problem. It allows one trusted system to authenticate a user and send identity information to another system. The receiving application can then create a session without asking the user to enter another password.
SAML uses structured XML messages to move this identity data. These messages can describe who authenticated the user, when authentication happened, which application should accept the result, and which user attributes may be shared.
What Is SAML?
SAML stands for Security Assertion Markup Language. It is a standard for exchanging authentication and identity information between separate systems.
SAML is commonly used for enterprise Single Sign-On, often shortened to SSO. With SSO, a user signs in through one trusted identity system and then accesses connected applications without entering credentials again for each one.
SAML does not usually transfer the user’s password to the application. Instead, the identity system sends an assertion stating that the user has already been authenticated.
This approach allows organizations to centralize login policies, multifactor authentication, password rules, and account management while still using many independent services.
Why SAML Uses XML
XML provides a structured and platform-independent way to represent identity information. Different applications can read the same message even when they are built with different programming languages or run on different operating systems.
XML also supports namespaces, schemas, digital signatures, encryption, nested elements, and detailed metadata. These features are useful when systems need to exchange security-sensitive information through a standardized format.
A SAML message may include:
- The identity of the sending system
- The identity of the user
- The time of authentication
- The intended receiving application
- User attributes such as email or department
- Conditions that limit how long the message is valid
- A digital signature
Because this information is structured, the receiving system can validate each part before granting access.
The Main Participants in a SAML Flow
A typical SAML login involves three main participants: the user, the Identity Provider, and the Service Provider.
The user is the person trying to access an application. The Identity Provider authenticates the user. The Service Provider offers the application or service the user wants to use.
The browser usually carries SAML messages between the Identity Provider and Service Provider. The user may see redirects and forms, but most of the process happens automatically.
What Is an Identity Provider?
An Identity Provider, often shortened to IdP, is the system responsible for authenticating the user.
The IdP may check a username and password, a security key, a one-time code, biometric data, or another authentication method. It may also connect to a corporate directory that stores employee accounts.
After successful authentication, the IdP creates a SAML response. This response may contain a signed assertion confirming the user’s identity and including approved attributes.
The Service Provider trusts the IdP because the two systems have been configured in advance to recognize each other’s identifiers, endpoints, and certificates.
What Is a Service Provider?
A Service Provider, or SP, is the application the user wants to access. It may be a learning platform, collaboration tool, cloud service, human resources system, or another web application.
The Service Provider does not necessarily authenticate the user directly. Instead, it redirects the user to the trusted Identity Provider.
After receiving a SAML response, the SP checks the message. If the response is valid, the application creates a local session and allows the user to continue.
The Service Provider remains responsible for deciding what the user can do inside the application. SAML authentication confirms identity, but access permissions may still depend on local roles, groups, or policies.
What Is a SAML Assertion?
A SAML assertion is an XML structure containing statements about a user. It is created by the Identity Provider and evaluated by the Service Provider.
An assertion may state that a user was authenticated at a specific time using a particular method. It may also provide attributes such as the user’s email address, employee number, department, or role.
The assertion usually includes restrictions. These restrictions may define which application can accept it, when it becomes valid, and when it expires.
A simplified assertion may look like this:
<saml:Assertion
xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion"
ID="_a123"
IssueInstant="2026-07-20T10:00:00Z"
Version="2.0">
<saml:Issuer>https://idp.example.com</saml:Issuer>
<saml:Subject>
<saml:NameID>[email protected]</saml:NameID>
</saml:Subject>
<saml:AuthnStatement
AuthnInstant="2026-07-20T09:59:55Z" />
</saml:Assertion>
Real SAML assertions normally contain more information and security controls.
The Main Types of SAML Statements
SAML assertions can contain several types of statements.
An authentication statement describes the authentication event. It may include the authentication time, session identifier, and method used.
An attribute statement contains information about the user. Common examples include email, display name, department, employee ID, and group membership.
An authorization decision statement can express whether a user is allowed to perform a specific action on a resource. This type is less common in ordinary SSO implementations.
Most practical SAML integrations focus mainly on authentication and attribute statements.
A Simple SAML Single Sign-On Flow
A typical SAML login begins when the user opens a protected application.
- The user visits the Service Provider.
- The Service Provider detects that no local session exists.
- The SP creates a SAML authentication request.
- The browser is redirected to the Identity Provider.
- The Identity Provider authenticates the user.
- The IdP creates a signed SAML response.
- The browser sends the response to the Service Provider.
- The SP validates the response and assertion.
- The application creates a local session.
The user may experience this as a few redirects followed by immediate access to the application.
SP-Initiated SSO
SP-initiated SSO begins at the Service Provider. The user opens the application first, and the application sends the user to the Identity Provider.
The SP usually creates an XML message called an AuthnRequest. This request identifies the application and may specify where the response should be returned.
<samlp:AuthnRequest
xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol"
ID="_request123"
Version="2.0"
IssueInstant="2026-07-20T10:00:00Z"
Destination="https://idp.example.com/sso"
AssertionConsumerServiceURL="https://app.example.com/saml/acs">
<saml:Issuer
xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion">
https://app.example.com
</saml:Issuer>
</samlp:AuthnRequest>
SP-initiated login is useful because the application knows where the user originally wanted to go. After authentication, it can return the user to the correct page.
IdP-Initiated SSO
IdP-initiated SSO begins at the Identity Provider. The user signs in to an identity portal and selects an application from a list.
The IdP creates a SAML response and sends it to the chosen Service Provider. There may be no earlier authentication request from that application.
This method can provide a convenient application dashboard. However, the Service Provider has less information about the original request because it did not start the flow.
Some security controls are also easier to apply in SP-initiated SSO because the response can be connected to a specific request through identifiers such as InResponseTo.
What Is a SAML Request?
A SAML request is a structured XML message asking another system to perform an action.
In an SSO flow, the most familiar request is the authentication request sent by the Service Provider to the Identity Provider.
The request may include:
- A unique request ID
- The creation time
- The destination Identity Provider endpoint
- The Service Provider entity ID
- The return endpoint
- The requested NameID format
- Authentication requirements
The Identity Provider should validate the request before responding. It should confirm that the requesting Service Provider is trusted and that the response destination is allowed.
What Is a SAML Response?
A SAML response is an XML message sent by the Identity Provider to the Service Provider.
It usually contains a status and one or more assertions. A successful response indicates that authentication completed and provides the information needed by the application.
<samlp:Response
xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol"
ID="_response123"
Version="2.0"
IssueInstant="2026-07-20T10:00:05Z"
Destination="https://app.example.com/saml/acs"
InResponseTo="_request123">
<saml:Issuer
xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion">
https://idp.example.com
</saml:Issuer>
<samlp:Status>
<samlp:StatusCode
Value="urn:oasis:names:tc:SAML:2.0:status:Success" />
</samlp:Status>
<saml:Assertion
xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion">
...
</saml:Assertion>
</samlp:Response>
The Service Provider must not trust the response only because it contains a success status. It must validate the digital signature, issuer, destination, audience, time limits, and other conditions.
Anatomy of a SAML Assertion
A SAML assertion contains several important sections.
The Issuer identifies the Identity Provider that created the assertion. The Subject identifies the user. The NameID provides the main user identifier.
The Conditions section defines when and where the assertion may be accepted. The AuthnStatement describes the authentication event. The AttributeStatement contains additional user information.
A digital signature may appear on the assertion or on the containing response. Some systems require both to be signed.
Understanding NameID
The NameID element identifies the authenticated user. It may contain an email address, username, employee identifier, or a generated persistent value.
<saml:NameID
Format="urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress">
[email protected]
</saml:NameID>
The Identity Provider and Service Provider must agree on the format and meaning of this value.
Using an email address may be convenient, but email addresses can change. A stable internal identifier may be safer when the application needs to maintain the same account over many years.
Incorrect NameID mapping can create duplicate accounts or connect a login to the wrong user record.
User Attributes in SAML
SAML attributes provide additional information about the user. They are usually placed inside an AttributeStatement.
<saml:AttributeStatement>
<saml:Attribute Name="email">
<saml:AttributeValue>
[email protected]
</saml:AttributeValue>
</saml:Attribute>
<saml:Attribute Name="department">
<saml:AttributeValue>
Engineering
</saml:AttributeValue>
</saml:Attribute>
</saml:AttributeStatement>
An attribute may contain one value or several values. Group membership is often represented as a multi-value attribute.
The Service Provider maps these attributes to local profile fields, roles, or access rules. The two systems must agree on attribute names and expected formats.
Organizations should send only the information the application actually needs. Unnecessary identity data increases privacy and security risks.
XML Namespaces in SAML
SAML relies on XML namespaces to distinguish different vocabularies inside the same document.
The protocol elements commonly use this namespace:
urn:oasis:names:tc:SAML:2.0:protocol
Assertion elements use another namespace:
urn:oasis:names:tc:SAML:2.0:assertion
XML Signature elements use a separate namespace:
http://www.w3.org/2000/09/xmldsig#
Prefixes such as samlp, saml, and ds are common, but the prefix itself is not the namespace identity. A document may use different prefixes as long as they point to the correct namespace URIs.
SAML Metadata
SAML metadata is an XML document that describes the technical configuration of an Identity Provider or Service Provider.
It may include:
- The entity ID
- Supported SAML bindings
- Single Sign-On endpoints
- Assertion Consumer Service endpoints
- Single Logout endpoints
- Public certificates
- Supported NameID formats
Metadata reduces manual configuration because administrators can import a structured document rather than entering every value separately.
However, imported metadata should come from a trusted source. A malicious metadata file could introduce an unsafe endpoint or certificate.
Entity ID Explained
An entity ID uniquely identifies a SAML participant. Both Identity Providers and Service Providers have their own entity IDs.
An entity ID often looks like a URL:
https://app.example.com/saml/metadata
It does not necessarily need to open a webpage. Its main purpose is identification.
The value must match exactly across configuration and messages. A missing slash, different protocol, or different letter case may cause validation to fail.
The Service Provider checks the assertion issuer against the trusted IdP entity ID. The Identity Provider also uses the SP entity ID when deciding whether to accept an authentication request.
Assertion Consumer Service
The Assertion Consumer Service, or ACS, is the Service Provider endpoint that receives the SAML response.
A typical ACS URL may look like this:
https://app.example.com/saml/acs
The Identity Provider usually sends the response to this endpoint through the user’s browser.
The Service Provider must confirm that the response destination matches an approved ACS URL. Accepting arbitrary destinations could allow identity data to be sent to an attacker-controlled endpoint.
An SP may have more than one ACS endpoint, but each should be explicitly registered and identified.
SAML Bindings
A SAML binding defines how a SAML message is transported between systems.
Common bindings include:
- HTTP Redirect Binding
- HTTP POST Binding
- HTTP Artifact Binding
The authentication request and response do not need to use the same binding. A common pattern sends the request through HTTP Redirect and returns the response through HTTP POST.
HTTP Redirect Binding
HTTP Redirect Binding places the SAML message into a URL query parameter.
The XML is normally compressed, Base64-encoded, and URL-encoded. The resulting value is included in a parameter such as SAMLRequest.
https://idp.example.com/sso?SAMLRequest=encoded-value
This binding is frequently used for authentication requests because they are usually smaller than responses.
URL length limits can make Redirect Binding less suitable for large messages. The request may also include a signature and a RelayState parameter.
HTTP POST Binding
HTTP POST Binding sends the SAML message inside an HTML form.
The form usually contains a hidden field named SAMLResponse. JavaScript or page markup submits the form automatically to the Assertion Consumer Service.
<form method="post" action="https://app.example.com/saml/acs">
<input
type="hidden"
name="SAMLResponse"
value="base64-encoded-response" />
<input
type="hidden"
name="RelayState"
value="/dashboard" />
</form>
POST Binding is well suited to SAML responses because assertions, attributes, and signatures can make the XML relatively large.
Base64 encoding is only a transport format. It does not encrypt or protect the message.
What Is RelayState?
RelayState carries application-specific state through the SAML flow.
For example, it may remember that the user originally wanted to open a reports page. After successful authentication, the application reads the value and sends the user to that page.
RelayState is separate from the SAML assertion. It should not be treated as trusted only because it arrived beside a valid response.
The Service Provider should validate it to prevent unsafe redirects or manipulation. Many applications use a short server-side identifier instead of placing a full destination URL directly in the parameter.
Digital Signatures in SAML
Digital signatures help the receiving system verify who created the SAML message and whether the XML was changed after signing.
The Identity Provider signs the response, assertion, or both with a private key. The Service Provider uses the corresponding public certificate to verify the signature.
A simplified signature section may contain elements such as:
<ds:Signature
xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
<ds:SignedInfo>...</ds:SignedInfo>
<ds:SignatureValue>...</ds:SignatureValue>
<ds:KeyInfo>...</ds:KeyInfo>
</ds:Signature>
Signature validation must be performed by a trusted SAML library. XML Signature processing contains many technical details, and custom implementations can introduce serious vulnerabilities.
Signing the Response or Assertion
Some Identity Providers sign the complete SAML response. Others sign only the assertion. Some configurations sign both.
The Service Provider must know which signatures are required and verify the correct element.
It is not enough to detect that a signature exists somewhere in the XML. The application must confirm that the trusted signature covers the exact assertion or response being used.
Incorrect signature selection can allow an attacker to add or replace unsigned content while leaving a valid signature elsewhere in the document.
Encryption in SAML
Signing and encryption solve different problems. A signature verifies origin and integrity. Encryption hides the content from systems that do not have the decryption key.
An Identity Provider may encrypt the entire assertion before sending it to the Service Provider.
<saml:EncryptedAssertion>
<xenc:EncryptedData
xmlns:xenc="http://www.w3.org/2001/04/xmlenc#">
...
</xenc:EncryptedData>
</saml:EncryptedAssertion>
The IdP encrypts the data using the Service Provider’s public key. The SP decrypts it with its private key.
HTTPS should still be used even when assertions are encrypted. HTTPS protects the complete browser connection, form submission, cookies, and other data surrounding the SAML message.
Certificates and Trust
SAML trust is commonly established through public certificates exchanged in advance or published in trusted metadata.
The Service Provider stores the Identity Provider certificate and uses it to verify signed messages. The Identity Provider may also store an SP certificate when requests are signed or assertions are encrypted.
Certificates eventually expire or may need to be replaced. Organizations should plan certificate rotation before the expiration date.
A sudden certificate change can break SSO if the receiving system still trusts only the old certificate. Metadata may temporarily publish both old and new keys during a controlled transition.
SAML Conditions
The Conditions element limits how and when an assertion may be used.
<saml:Conditions
NotBefore="2026-07-20T09:59:00Z"
NotOnOrAfter="2026-07-20T10:04:00Z">
<saml:AudienceRestriction>
<saml:Audience>
https://app.example.com
</saml:Audience>
</saml:AudienceRestriction>
</saml:Conditions>
The assertion is invalid before the NotBefore time and must not be accepted at or after the NotOnOrAfter time.
The Service Provider should reject assertions that are expired, not yet valid, or intended for another audience.
Audience Restriction
The audience restriction identifies the Service Provider for which the assertion was created.
The receiving application compares the audience value with its own entity ID. If the values do not match, the assertion should be rejected.
This check prevents an assertion created for one application from being reused at another application.
Audience mismatches are also a common configuration problem. They may occur when one system uses an old entity ID or includes an unexpected slash in the value.
Time Validation and Clock Skew
SAML messages contain several timestamps. These may include the issue time, authentication time, and assertion validity period.
Servers do not always have perfectly identical clocks. A small difference is called clock skew.
Service Providers may allow a limited amount of clock skew when checking timestamps. This prevents valid messages from failing because one server is slightly ahead or behind.
The allowed difference should remain small. A large tolerance extends the period in which an assertion can be reused and weakens replay protection.
Organizations should synchronize server clocks through reliable time services.
Preventing Replay Attacks
A replay attack occurs when someone captures a valid SAML response and tries to submit it again.
Several controls reduce this risk:
- Short assertion validity periods
- Unique response and assertion IDs
- Validation of
InResponseTo - Tracking already accepted message IDs
- Secure HTTPS transport
- Session and recipient restrictions
The Service Provider should connect an SP-initiated response to the request it previously created. If the response refers to an unknown request, it may be invalid or malicious.
SAML and Browser Sessions
A SAML assertion is usually used only during login. The Service Provider does not normally process the same assertion for every page request.
After successful validation, the application creates its own local session. This session may use a secure cookie or another application-specific token.
The browser then uses the local session when navigating through the application.
This distinction is important. SAML establishes the user’s identity at login, while the application session maintains access afterward.
The Service Provider should apply normal session security controls, including secure cookies, appropriate expiration, logout handling, and protection against session theft.
Single Logout
SAML Single Logout attempts to end sessions across the Identity Provider and connected Service Providers.
A user may log out from one application, which sends a logout request to the IdP. The IdP can then notify other applications involved in the same identity session.
In practice, Single Logout can be difficult to implement reliably. Applications may use different session models, browser restrictions may interrupt communication, and one Service Provider may be unavailable.
Some organizations therefore treat local application logout and central identity logout as separate operations.
How Identity Data Is Mapped
The Service Provider must connect incoming SAML identity data to a local user account.
It may use the NameID, email address, employee number, or another stable identifier. Additional attributes may populate the user’s name, department, title, or group membership.
Mapping rules should be defined clearly. The application needs to know which SAML attribute corresponds to each local field.
Problems can occur when the IdP changes an attribute name, sends a different data format, or stops including a required value.
Identity mapping should also be protected against account takeover. A mutable value such as an email address should not automatically connect to an existing privileged account without careful controls.
Just-in-Time Provisioning
Just-in-Time provisioning creates a local account when a user signs in through SAML for the first time.
The Service Provider reads the assertion and uses its attributes to create a profile automatically. This can simplify onboarding because administrators do not need to create every account manually.
However, the application must define what happens when attributes are missing or inconsistent. It must also prevent duplicate accounts and avoid granting excessive permissions automatically.
SAML authentication and provisioning are related but separate functions. More advanced organizations may use a dedicated provisioning protocol to create, update, suspend, and remove accounts outside the login process.
Authentication vs. Authorization
Authentication answers the question, “Who is this user?” Authorization answers, “What is this user allowed to do?”
SAML is often used primarily for authentication. The Identity Provider confirms the user’s identity and sends that result to the Service Provider.
The assertion may also contain groups or roles, but the application should still apply its own authorization rules.
A valid SAML login should not automatically provide access to every feature. The Service Provider must check whether the user has the required local role, license, group, or permission.
Common SAML Configuration Errors
SAML integrations often fail because the two systems use slightly different configuration values.
Common problems include:
- Incorrect entity IDs
- Wrong Assertion Consumer Service URLs
- Unexpected NameID formats
- Missing user attributes
- Different attribute names
- Expired signing certificates
- Incorrect audience values
- Server clock differences
- Unsupported signature algorithms
- Untrusted request or response destinations
Most configuration errors can be found by comparing the SAML message with the metadata and settings on both sides.
Common XML-Related SAML Errors
SAML can also fail because of XML structure or processing problems.
An XML document may be malformed, use the wrong namespace, contain an unexpected element, or include an invalid signature reference.
Encoding and decoding mistakes are also common. A Redirect Binding request may need decompression after Base64 decoding, while a POST response normally requires Base64 decoding without the same compression step.
Applications should use standards-compliant SAML libraries rather than manually parsing XML through string operations.
XML parsers must also be configured securely to prevent external entity processing and other unsafe behavior.
How to Troubleshoot a SAML Login
SAML troubleshooting usually begins by examining the request, response, and logs from both systems.
Useful steps include:
- Confirm that the user reached the correct Identity Provider.
- Check whether authentication succeeded at the IdP.
- Decode the SAML response in a secure environment.
- Verify the issuer and destination.
- Check the audience value.
- Review the assertion validity times.
- Confirm the NameID format and value.
- Inspect required user attributes.
- Check the signing certificate and signature result.
- Compare the response with the original request.
Production assertions may contain personal or security-sensitive data. They should not be pasted into public online decoding tools.
Protecting Sensitive Identity Data
SAML messages may contain names, email addresses, group memberships, employee identifiers, and other personal information.
Organizations should follow data minimization principles. The Identity Provider should send only the attributes required by the Service Provider.
All SAML endpoints should use HTTPS. Assertions containing especially sensitive information may also be encrypted.
Application logs should avoid storing complete production assertions unless there is a controlled and justified need. Access to identity logs should be restricted.
Temporary debugging data should be removed after the problem is resolved.
SAML vs. OAuth 2.0
SAML and OAuth 2.0 are sometimes compared because both can appear in systems that connect users and applications. However, they solve different primary problems.
SAML is commonly used for federated authentication and enterprise Single Sign-On. It sends XML assertions about identity and authentication.
OAuth 2.0 is an authorization framework. It allows an application to obtain limited access to another service on behalf of a user or system.
OAuth access tokens are not automatically proof of user identity. Authentication is usually added through another protocol such as OpenID Connect.
SAML and OAuth may coexist in the same organization. One may handle employee login, while the other controls API access.
SAML vs. OpenID Connect
SAML and OpenID Connect can both support Single Sign-On, but they use different architectures and message formats.
SAML is XML-based and remains common in enterprise and institutional systems. OpenID Connect is built on OAuth 2.0 and usually uses JSON-based tokens.
OpenID Connect is often a natural choice for modern web, mobile, and API-focused applications. SAML may be preferred when an organization already has enterprise identity infrastructure or must integrate with systems that require it.
The best choice depends on compatibility, security requirements, implementation support, and the systems that need to communicate.
Where SAML Is Commonly Used
SAML is widely used in environments where organizations need centralized control over access to third-party applications.
Common examples include:
- Enterprise software platforms
- Educational systems
- Human resources applications
- Financial and administrative tools
- Cloud management portals
- Business-to-business applications
- Research and institutional services
It is especially useful when an organization wants employees or students to use existing institutional credentials across many services.
When SAML May Not Be the Best Choice
SAML can be more complex than necessary for a small consumer application or a simple login system.
It may not be the best fit for mobile-first products, direct API authorization, lightweight consumer identity, or systems without enterprise federation requirements.
New applications may prefer OpenID Connect when they need modern token-based flows and broad support across web and mobile platforms.
However, technology choice should not be based only on age or popularity. Existing infrastructure and partner compatibility often determine whether SAML remains the most practical option.
Best Practices for SAML Implementations
Use a mature and maintained SAML library. Avoid building custom XML signature, encryption, or validation logic.
Always verify the digital signature using a trusted certificate. Check the issuer, audience, destination, recipient, and assertion time limits.
For SP-initiated login, validate InResponseTo and connect the response to a request created by the application.
Allow only approved algorithms and endpoints. Do not trust values taken directly from the incoming message when they should come from local configuration.
Use secure XML parser settings, HTTPS, protected session cookies, and limited assertion lifetimes.
Plan certificate rotation, monitor authentication errors, and document all attribute mapping rules.
A Practical SAML Security Checklist
- Is the response or assertion signature required and verified?
- Does the issuer match the trusted Identity Provider?
- Does the audience match the Service Provider entity ID?
- Does the destination match an approved ACS endpoint?
- Is the assertion currently valid?
- Is clock skew limited?
- Is
InResponseTochecked when applicable? - Are replayed message IDs rejected?
- Are only necessary attributes accepted?
- Are authorization rules applied after authentication?
- Are certificate expiration and rotation monitored?
- Are production assertions protected from public exposure?
Conclusion
SAML allows identity information to move between trusted systems through structured XML messages. The Identity Provider authenticates the user, and the Service Provider relies on the resulting assertion to create a local session.
XML gives SAML a standardized way to describe issuers, users, attributes, authentication events, validity conditions, and security information. Namespaces separate protocol, assertion, signature, and encryption elements inside the same document.
Secure SAML implementation requires more than decoding XML. The Service Provider must verify signatures, certificates, audience restrictions, destinations, timestamps, request relationships, and replay protections.
When configured correctly, SAML provides a practical foundation for enterprise Single Sign-On. It allows users to move between connected systems while organizations maintain centralized control over authentication and identity data.