Skip to content

SAML vs OpenID Connect: which should you use?

Answer four questions about your app and its users to see whether SAML or OpenID Connect fits better, and why.

Runs in your browser. Nothing you paste is sent to us.

Your app

What are you connecting?
Which protocols does the app support?
Does the app call APIs on the user’s behalf?
Where do the users sign in?

Suggestion

clear fit
Use OpenID Connect
  • Single-page apps sign in with the authorization code flow and PKCE; SAML expects a server to receive a posted form.
  • You need tokens to call APIs, which OpenID Connect gives you with the same sign-in.
Keycloak serves both from the same realm: users, roles and sessions are shared, and each client picks its protocol.

How to use it

  1. Pick what you are connecting: a web app, a single-page app, a mobile app, an API or a bought SaaS product.
  2. Say which protocols the app supports.
  3. Say whether the app calls APIs for the user and where users sign in.
  4. Read the suggestion and the reasons behind it.

What to know

SAML and OpenID Connect both let users sign in once at an identity provider. SAML sends a signed XML assertion through the browser; OpenID Connect sends JSON tokens and is built on OAuth 2.0, so it also gives access tokens for APIs.

When the app supports only one protocol, that settles it. Otherwise OpenID Connect is usually the simpler choice for new apps, and the only good choice for single-page apps, mobile apps and APIs.

Keycloak supports both in the same realm, and it can broker between them: users can sign in at a company identity provider over SAML while your app talks OpenID Connect to Keycloak.

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.0OpenID Connect
Message formatXML with XML signaturesJSON and JSON Web Tokens
Built onIts own protocolOAuth 2.0
DeliveryThrough the browser, usually a POSTed formCode through the browser, tokens over a back channel
API access tokensNoYes
Single-page appsPoor fitYes, with PKCE
Native mobile appsPoor fitYes, with PKCE and the system browser
ConfigurationMetadata documentsDiscovery document at a well-known URL
Typical homeEnterprise SaaS, universities, older systemsNew 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

  1. 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.
  2. Pick which protocols the app supports, or say you are writing it.
  3. Say whether the app calls APIs on the user’s behalf.
  4. Say whether users have accounts in your own realm or sign in through a partner’s or customer’s company identity provider.
  5. 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

  1. Create an OpenID Connect client for the app next to the existing SAML client.
  2. Map the same user data into token claims that the SAML attributes carried.
  3. 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.
  4. 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.

Questions

Frequently asked questions

Should I use SAML or OpenID Connect?

If the app supports only one, use that one. Otherwise OpenID Connect is usually simpler for new apps and is the only good choice for single-page apps, mobile apps and APIs. SAML remains common for enterprise SaaS products.

Is SAML outdated?

It is older and heavier than OpenID Connect, but it is still the standard for enterprise sign-in in many SaaS products, company identity providers and research federations.

Is OpenID Connect more secure than SAML?

Neither is inherently more secure. Both are secure when implemented correctly. SAML’s XML signatures have a longer history of implementation mistakes, so use well-maintained libraries either way.

Can one Keycloak realm serve SAML and OIDC apps?

Yes. Each client has its own protocol. Users, roles, groups and the sign-in session are shared across all clients in the realm.

Can users from a SAML identity provider sign in to an OIDC app?

Yes, through identity brokering. Add the SAML identity provider to a Keycloak realm; Keycloak accepts the SAML assertion and issues OpenID Connect tokens to the app.

Can I use SAML for a mobile app?

It is possible through a browser and a server, but awkward. OAuth 2.0 with PKCE through the system browser, as OpenID Connect uses, is the standard for native apps.

Does SAML give me an access token for APIs?

No. SAML gives the app an assertion for sign-in. For API access you need OAuth 2.0 tokens, which OpenID Connect provides alongside sign-in.

What is the difference between OAuth 2.0 and OpenID Connect?

OAuth 2.0 is for delegated access to APIs. OpenID Connect adds sign-in on top: an ID token that says who the user is, a userinfo endpoint and discovery.

Is SAML or OIDC better for enterprise SSO?

Both are used for enterprise single sign-on. SAML is more common in older enterprise products; OpenID Connect is common in newer ones. Support whichever your customers’ identity providers and your apps offer.

Rather not run Keycloak yourself?

We run it for you on a cluster of your own, with backups, upgrades and written support. Starter and Premium begin with a 7-day trial.