Two protocols for the same job
SAML 2.0 and OpenID Connect both let users sign in once at an identity provider and then use many apps without signing in again. Both are open standards, both are widely supported, and Keycloak speaks both. The question is which one a given app should use.
SAML 2.0 was published by OASIS in 2005 and became the standard for enterprise single sign-on. OpenID Connect was finalized in 2014 as an identity layer on top of OAuth 2.0, and it is now the default for new web, mobile and API work.
How each one works
SAML
The app sends the browser to the identity provider with an AuthnRequest. After sign-in, the identity provider sends back a signed XML assertion, usually by having the browser post a form to the app. The app checks the signature and reads the user’s identifier and attributes from the assertion. The app never talks to the identity provider directly.
OpenID Connect
The app sends the browser to the identity provider’s authorization endpoint. After sign-in, the browser returns to the app with a short-lived code, and the app exchanges the code for tokens at the token endpoint. It gets an ID token, a signed JSON Web Token about the user, and an access token it can use to call APIs. Single-page and mobile apps use the same flow with PKCE instead of a client secret.
Side by side
| SAML 2.0 | OpenID Connect | |
|---|---|---|
| Message format | XML with XML signatures | JSON and JSON Web Tokens |
| Built on | Its own protocol | OAuth 2.0 |
| Delivery | Through the browser, usually a POSTed form | Code through the browser, tokens over a back channel |
| API access tokens | No | Yes |
| Single-page apps | Poor fit | Yes, with PKCE |
| Native mobile apps | Poor fit | Yes, with PKCE and the system browser |
| Configuration | Metadata documents | Discovery document at a well-known URL |
| Typical home | Enterprise SaaS, universities, older systems | New apps, mobile, APIs, consumer sign-in |
When SAML is the right choice
- The app supports only SAML. Many enterprise products still do, or have their richest single sign-on options there.
- A customer or partner insists on SAML because their identity provider and processes are built around it.
- You join a research or education federation, where SAML metadata exchange is the norm.
- You already run many SAML apps and the team knows the tooling well.
When OpenID Connect is the right choice
- You are building the app yourself. Libraries are plentiful and JSON tokens are simpler to handle than signed XML.
- The app is a single-page app or a native app. SAML expects a server to receive a posted form.
- The app calls APIs for the user. OpenID Connect gives you access tokens with the same sign-in.
- You need machine-to-machine access too, which OAuth 2.0 covers with the client credentials grant.
What this tool does
The chooser asks four questions: what you are connecting, which protocols the app supports, whether it calls APIs for the user, and where users sign in. It answers with a protocol, says whether it is a clear fit or either would work, and lists the reasons. When users come from company identity providers, it also explains how Keycloak can bridge the two protocols.
The rules are simple and explained in the result. They cover the common cases, not every edge case. If the app’s vendor recommends one protocol, follow the vendor.
How to use it
- Pick what you are connecting: a server-side web app, a single-page app, a mobile or desktop app, an API or a bought SaaS product.
- Pick which protocols the app supports, or say you are writing it.
- Say whether the app calls APIs on the user’s behalf.
- Say whether users have accounts in your own realm or sign in through a partner’s or customer’s company identity provider.
- Read the suggestion and the reasons.
Keycloak supports both, and can bridge them
In Keycloak, the protocol is a property of each client, not of the realm. One realm can hold SAML clients and OpenID Connect clients side by side. They share users, groups, roles and the user’s sign-in session, so a user who signed in to one app does not sign in again for the next, whatever its protocol.
Keycloak can also broker between them. Add a company’s SAML identity provider to the realm, and its users can sign in to your OpenID Connect apps: Keycloak receives the SAML assertion, creates or links the user, and issues OpenID Connect tokens to the app. The reverse works too, with an OpenID Connect identity provider and SAML clients.
A typical B2B setup
Your own app uses OpenID Connect against your realm. Each enterprise customer’s identity provider is added to the realm as a SAML or OpenID Connect identity provider, whichever the customer offers. The app does not change per customer; the realm does the translation.
Migrating from SAML to OpenID Connect
- Create an OpenID Connect client for the app next to the existing SAML client.
- Map the same user data into token claims that the SAML attributes carried.
- Make sure both protocols resolve to the same user account, for example by matching on a stable id rather than on the SAML NameID value.
- Switch the app, keep the SAML client for a while for rollback, then remove it.
Common misconceptions
- “SAML is more secure.” Both are secure when implemented and configured correctly. Both have had implementation flaws; SAML’s XML signatures are harder to get right.
- “OpenID Connect is only for consumer logins.” It is widely used for workforce and enterprise sign-in.
- “SAML is obsolete.” It is older, but it remains the standard in many enterprise products and federations.
- “You must pick one per organization.” With an identity provider like Keycloak, each app can use the protocol that suits it.
Logout in each protocol
Signing out of every app at once is harder than signing in, in both protocols. SAML single logout sends LogoutRequest messages to each app, through the browser or directly, and depends on every app handling them. OpenID Connect offers RP-initiated logout, plus front-channel and back-channel logout to notify apps.
In both cases, an app that ignores logout keeps its own session until it expires. If reliable sign-out across apps matters, test it per app, whichever protocol it uses. Keycloak supports SAML single logout and the OpenID Connect logout mechanisms for its clients.
Questions to ask an app vendor
Before you choose, ask the vendor or read their documentation for answers to these:
- Which protocols do you support, and which one gets new features first?
- Do you provision users on first sign-in, and from which attributes or claims?
- Can you sign requests, and do you require signed or encrypted assertions?
- Do you support single logout, and how?
- Do you read our metadata or discovery URL and refresh it, or is setup a one-time import?
The answers often settle the question before any of the general arguments do.