SAML, Simplified.
SAML has a bit of a reputation. For many developers, it lives in that shadowy corner of the B2B internet where XML still rules and stack traces seem to go on forever. If you've ever had the misfortune of debugging a malformed <Assertion>, you know the pain. But here's the thing: it doesn't have to be a nightmare.
At Phase Two, we provide managed hosting and enterprise support for Keycloak, a leading open-source Identity and Access Management platform. And while OIDC has become the default for most modern applications, SAML is still alive and well—especially in enterprise environments.
This post is a gentle (and opinionated) introduction to what SAML is, how it works, and why it still matters particularly if you're implementing SAML SSO in Keycloak.
What even is SAML?
SAML — short for Security Assertion Markup Language — is a standardized XML-based protocol used to exchange authentication and authorization data between parties, most commonly between an Identity Provider (IdP) and a Service Provider (SP).
The core idea? Let users log in once (with the IdP) and then access multiple systems (the SPs) without re-authenticating. That's Single Sign-On (SSO), and it's where SAML shines.
To make this concrete, imagine you're using Google Workspace to access your company's internal tools. You open up a tool like Jira (that's the Service Provider — it provides the service you want to use). But instead of logging in directly, you're redirected to Google to sign in — that's your Identity Provider. Google verifies who you are, then sends a message back to Jira saying, “Yes, this is the correct user, and here's some information about them.” The service (Jira) trusts that identity because it already trusts Google. In simple terms: the IdP is who you log in with, the SP is what you're trying to access.
Keycloak and SAML
Keycloak supports both sides of the SAML flow. It can act as:
- A SAML Identity Provider, enabling users to authenticate in Keycloak and then access SAML-based applications.
- A SAML Service Provider, allowing external IdPs (like Okta, Azure AD, or even legacy ADFS systems) to federate users into Keycloak-managed apps.
That flexibility is one of Keycloak's greatest strengths — and also where things can get a bit complex.
The SAML Triad: User, SP, IdP
Let's simplify things. In a typical Keycloak-based SAML setup, you're dealing with three entities:
- The User: someone trying to log in.
- The Service Provider (SP): your application.
- The Identity Provider (IdP): Keycloak or another IdP.
When Keycloak is the IdP, it authenticates the user and issues a SAML response back to the SP. When Keycloak is the SP, it receives the SAML response and handles session creation internally.
What does a SAML flow look like in Keycloak?
Let's say Keycloak is acting as the SAML Service Provider. Here's the basic flow:
- A user tries to access your app.
- The app redirects the user to Keycloak (the SP).
- Keycloak identifies that the user should log in via SAML (based on their realm or identity provider configuration).
- Keycloak sends a SAML AuthnRequest to the external IdP (e.g., Okta).
- The IdP authenticates the user and sends a signed SAML Response back to Keycloak.
- Keycloak parses the assertion, validates the signature, and creates a user session.
From there, the user gets access to the protected application—without having logged in directly with your app or even with Keycloak.
SAML messages: what you're actually passing around
In SAML, two XML messages do most of the heavy lifting:
- AuthnRequest (from SP → IdP): "Hey, can you authenticate this user for me?"
- Response (from IdP → SP): "Yes, here's proof that I authenticated them."
The Response contains one or more Assertions, which are signed blobs of XML confirming that the user is who they say they are. It might look like gibberish to humans, but to systems like Keycloak, it's gold.
And yes, validating those signatures is as fussy as it sounds. But Keycloak handles most of that for you — so long as your trust relationships are properly configured.