Keycloak SAML Guide: Keycloak as an IdP and as an SP. SAML in Keycloak 26: set up a SAML client so Keycloak is the IdP, broker an external SAML IdP so Keycloak is the SP, plus metadata, mappers and errors.
Keycloak plays two SAML roles. As an identity provider (IdP), it signs users in and sends SAML assertions to applications you register under Clients, which is how you give a SAML-only app such as Jira or a partner’s portal single sign-on through Keycloak. As a service provider (SP), it accepts assertions from an external SAML IdP you register under Identity providers, which is how a customer’s Entra ID or Okta signs users into your realm. Both roles can run in the same realm, and both are set up by exchanging metadata: the IdP publishes who it is and how it signs, and the SP publishes where to send the assertion.
This guide is the starting point for SAML in Keycloak 26. It explains each role, walks through the settings for a SAML client in detail, summarizes the SP side, and links to the deeper guides for brokering, flows and troubleshooting. If you are not sure which side you are on, our explainer on IdP vs SP has a checklist for that.
How does SAML work in Keycloak?
SAML 2.0 is an XML-based standard for single sign-on, defined by OASIS (the technical overview is the readable introduction, and the core specification defines assertions and protocols). The service provider sends the user to the identity provider with an authentication request, the identity provider checks who the user is and sends back a signed assertion (an XML document that states who the user is and which attributes they have), and the service provider checks the signature before it signs the user in. Our post on what a SAML assertion is walks through that document element by element.
In Keycloak, the two roles live in two places in the realm, as the Server Administration Guide describes under SAML clients and SAML v2.0 identity providers:
| Keycloak’s role | Where you configure it | Who is on the other side | Metadata you hand over |
|---|---|---|---|
| Identity provider | Clients, with a SAML client per application | An application that trusts Keycloak, such as Jira or a partner portal | The realm’s IdP metadata at /realms/{realm}/protocol/saml/descriptor |
| Service provider | Identity providers, with a SAML v2.0 entry per upstream IdP | A customer’s or partner’s IdP, such as Entra ID, Okta or ADFS | The provider’s SP metadata at /realms/{realm}/broker/{alias}/endpoint/descriptor |
If your applications can speak OpenID Connect, you can often avoid SAML on the application side entirely and keep it only where a partner or a legacy app requires it. Our comparison of SAML vs OIDC covers when each protocol fits.
Keycloak as a SAML identity provider
This is the case where an application sends users to Keycloak to sign in. The application is the SP, and in Keycloak it is a client with the SAML protocol.
Create the SAML client
The quickest route is to import the application’s SP metadata, which the admin guide covers under using an entity descriptor to create a client. Under Clients, choose Import client and upload the XML entity descriptor the application gives you, and Keycloak fills in the entity ID, the assertion consumer service URL and the signing certificate. If the application has no metadata file, choose Create client, set Client type to SAML, and enter the Client ID.
The Client ID matters more for SAML than for OIDC: it must match exactly the entity ID (sometimes called the issuer or audience) that the application puts in its requests. A trailing slash or a different scheme is enough to make Keycloak reject the request as coming from an unknown client.
Set the URLs
On the client’s Settings tab, the fields that matter most are the following (each is documented in the admin guide’s SAML client section):
- Valid redirect URIs, the URLs Keycloak may send the assertion back to. Keep these as specific as you can.
- Master SAML Processing URL, a single URL that receives all SAML requests and responses, used when the application does not tell Keycloak where to send things.
- IDP-Initiated SSO URL name, which you only set if users should be able to start the login from Keycloak rather than from the application. With a value of
jira, the login link becomes/realms/{realm}/protocol/saml/clients/jira. Our guide to IdP-initiated vs SP-initiated SSO covers the security trade-offs before you turn that on.
The Advanced tab holds the per-binding endpoints, such as the assertion consumer service POST binding URL and the logout service URLs, if the application needs them set explicitly.
Choose the NameID format
The NameID is the identifier for the user in the assertion’s subject, as defined in section 2.2 of the SAML core specification. Under SAML capabilities, Name ID format can be username, email, transient or persistent, and Force name ID format makes Keycloak use your choice even when the application asks for something else. Pick what the application uses to find its accounts: many SaaS apps match on email, while some enterprise apps expect a stable persistent identifier that never changes when a user’s email does.
Signing and encryption
Under Signature and Encryption, Sign documents and Sign assertions control what Keycloak signs, and most applications want at least the assertion signed, with RSA_SHA256 as the signature algorithm. The application validates those signatures with the realm’s signing certificate, which is in the IdP metadata.
The Keys tab controls the other direction. Client signature required makes Keycloak reject authentication requests that the application has not signed with the certificate you upload there, and Encrypt assertions encrypts the assertion with the application’s certificate so it cannot be read in transit through the browser. Turn on what the application supports; a mismatch, such as requiring signed requests from an app that never signs, is a common cause of failed logins.
Send the right attributes
Applications usually need more than the NameID, such as an email address, a name or a list of roles. You add these as protocol mappers, either on the client’s dedicated scope or on a shared client scope:
- User Property and User Attribute mappers send fields of the user, such as
emailor a custom attribute, under the attribute name the application expects. - Role list sends the user’s roles. SAML clients get the
role_listclient scope by default, and its Single Role Attribute option sends all roles in one attribute instead of one attribute per role. - Group list sends group membership, and Hardcoded attribute sends a fixed value.
Ask the application’s documentation for its exact attribute names, because SAML matches them literally.
Give the application your metadata
Finally, hand the application your realm’s IdP metadata, a document in the format of the SAML metadata specification, at https://{your-keycloak}/realms/{realm}/protocol/saml/descriptor or under Realm settings, Endpoints, SAML 2.0 Identity Provider Metadata. It contains the realm’s entity ID, its single sign-on URL and its signing certificate. For a complete worked example with a real application, our guide to Jira Cloud SAML single sign-on with Keycloak goes through both consoles.
Keycloak as a SAML service provider
This is the case where Keycloak sends users to another identity provider, usually a customer’s corporate IdP, and trusts the assertion it gets back. Keycloak calls this identity brokering, and your applications are unaffected: they still sign in with Keycloak and receive Keycloak’s tokens, whichever IdP the user came from.
In outline, you add a SAML v2.0 entry under Identity providers, import the external IdP’s metadata so the single sign-on URL, NameID format and signing certificate are filled in, and then give the external IdP your SP metadata from the provider’s Endpoints link, which is served at /realms/{realm}/broker/{alias}/endpoint/descriptor (see the admin guide’s SP descriptor section). Mappers on the identity provider turn the incoming attributes into user fields, and the first login flow decides how a new user is created or linked to an existing account.
Our Keycloak SAML service provider guide covers every step, including assertion validation, attribute mapping and account linking. For the most common case, a customer on Microsoft’s identity platform, see Entra ID as a SAML identity provider in Keycloak. When you broker several customers, home realm discovery with Organizations routes each user to the right IdP by email domain, and kc_idp_hint lets an application pick the provider directly.
Somewhere to run this that stays patched
Everything above works the same on Skycloak, because it is real upstream Keycloak rather than a fork. What changes is who handles the upgrades, backups and security patches afterwards.
Using both roles together
A common B2B setup uses both roles at once. Your customers’ IdPs connect to Keycloak as SAML identity providers, and your own applications connect to Keycloak with OpenID Connect or SAML. Keycloak sits in the middle, so you integrate each customer’s IdP once, in Keycloak, instead of in every application, and your applications only ever see one token format. Keycloak can also translate between protocols in that position: a user can arrive from a SAML IdP and leave with an OpenID Connect token, which our post on bridging IdP-initiated SAML to OIDC shows in detail.
Troubleshooting SAML in Keycloak
Most SAML failures come down to a handful of mismatches, and the Keycloak server log usually names the one you hit.
- Unknown client or invalid requester. The entity ID in the request does not match the SAML client’s Client ID exactly.
- Invalid redirect URI. The assertion consumer service URL in the request is not covered by Valid redirect URIs.
- Invalid signature. One side is signing with a certificate the other side does not have, often after a key rotation. Compare the certificate in the metadata with the one actually in use.
- Missing or wrong attributes. The mapper’s attribute name differs from what the application expects, or the NameID format is not the one the application uses to find accounts.
- Clock skew. The assertion’s validity window has already passed or has not started yet because the servers’ clocks disagree.
To see what was actually sent, decode the request or response before you change any settings. Our SAML decoder shows the issuer, audience, NameID and attributes, and our post on decoding a SAMLRequest explains each field. For logout problems on Keycloak 26.8, also check our note on the 26.8.1 SAML logout SessionIndex fix.
Frequently asked questions
Does Keycloak support SAML?
Yes. Keycloak supports SAML 2.0 as an identity provider, through SAML clients, and as a service provider, through SAML identity providers, and it can do both in the same realm.
Where is Keycloak’s SAML metadata?
The realm’s IdP metadata, for applications that sign in with Keycloak, is at /realms/{realm}/protocol/saml/descriptor. The SP metadata for a brokered SAML identity provider is at /realms/{realm}/broker/{alias}/endpoint/descriptor.
Can Keycloak convert SAML to OpenID Connect?
Yes. A user can sign in through an upstream SAML identity provider and your application can receive an OpenID Connect token from Keycloak, because the application only ever talks to Keycloak.
What NameID format should I use?
Use the identifier the application uses to find its accounts. Email is the most common for SaaS applications, and a persistent identifier is safer when users’ email addresses can change.
Next steps
Decide which role you need, then follow the matching section: create a SAML client when an application should sign in with Keycloak, or add a SAML identity provider when Keycloak should trust a customer’s IdP. If you would rather not run the Keycloak cluster behind either, see what managed Keycloak hosting includes.


