Dev tools
SAML vs OIDC: Which Single Sign-On Protocol to Use
SAML vs OIDC compared: how each single sign-on protocol works, tokens, flows, security, mobile and API support, and which to build or offer first.
In SAML vs OIDC, both protocols do the same core job: they let a user sign in to an application with an account held by an identity provider (IdP) such as Okta, Microsoft Entra ID or Google, instead of a separate password for every app. That's single sign-on (SSO). The difference is age and design. SAML 2.0 is an XML-based standard from 2005, built for browser sign-in to enterprise web apps. OpenID Connect (OIDC), launched in 2014, is a thin identity layer on top of OAuth 2.0 that uses JSON tokens and works naturally for web, mobile and single-page apps.
The difference between OIDC and SAML matters most when you build the integration, less for the end user. For a new application, OIDC is usually the easier and more flexible choice. SAML remains essential in enterprise sales, because many corporate IT teams still connect apps to their IdP through SAML. This guide explains what each protocol is, how their login flows differ, compares tokens, security and tooling, and shows which to support first.
SAML vs OIDC at a Glance
| SAML 2.0 | OpenID Connect (OIDC) | |
|---|---|---|
| Standardised | OASIS Standard, approved March 2005 | OpenID Foundation, launched February 2014 |
| Built on | XML, XML Signature | OAuth 2.0, JSON, JSON Web Tokens |
| Identity token | Signed XML assertion | ID token (a signed JWT) |
| Typical transport | Browser redirects and auto-submitted HTML forms (HTTP-POST) | Browser redirects plus a back-channel token request |
| Configuration | XML metadata exchanged between IdP and app | Discovery document at a well-known URL |
| Mobile and native apps | Awkward | Designed for them (authorisation code flow with PKCE) |
| API access | Not designed for it | Pairs with OAuth access tokens for APIs |
| Developer experience | Verbose XML; libraries essential | JSON; widely supported libraries |
| Where it dominates | Enterprise workforce SSO, older SaaS, education and government | Consumer login, modern SaaS, mobile apps, new enterprise integrations |
What Is SAML?
What is SAML? Security Assertion Markup Language is an open standard for exchanging authentication and attribute information between an identity provider and a service provider (SP), the application. SAML 2.0 was approved as an OASIS Standard on 1 March 2005 and has been the backbone of enterprise web SSO ever since.
The key object is the assertion: an XML document signed by the IdP that says, in effect, "this user authenticated at this time, and here are their attributes". Setup works by exchanging metadata: XML files that hold each side's entity ID, endpoint URLs and signing certificates.
A minimal assertion looks like this (shortened):
<saml:Assertion ID="_a75adf55" IssueInstant="2026-11-23T10:00:00Z">
<saml:Issuer>https://idp.example.com</saml:Issuer>
<ds:Signature>...</ds:Signature>
<saml:Subject>
<saml:NameID>[email protected]</saml:NameID>
</saml:Subject>
<saml:Conditions NotOnOrAfter="2026-11-23T10:05:00Z">
<saml:AudienceRestriction><saml:Audience>https://app.example.com</saml:Audience></saml:AudienceRestriction>
</saml:Conditions>
<saml:AttributeStatement>
<saml:Attribute Name="department"><saml:AttributeValue>Finance</saml:AttributeValue></saml:Attribute>
</saml:AttributeStatement>
</saml:Assertion>What Is OIDC?
What is OIDC? OpenID Connect is an identity layer built on top of OAuth 2.0, the authorisation framework used to grant apps access to APIs. OAuth on its own says what an app may access, not who the user is. OIDC adds that missing piece: an ID token, a signed JSON Web Token (JWT) carrying claims about the user and the login. The OpenID Foundation ratified the standard on 26 February 2014.
Configuration is simpler than SAML. An app needs the IdP's issuer URL, a client ID and usually a client secret. Everything else, such as endpoints and signing keys, comes from a discovery document at /.well-known/openid-configuration.
A decoded ID token payload looks like this:
{
"iss": "https://idp.example.com",
"sub": "248289761001",
"aud": "my-app-client-id",
"exp": 1795424400,
"iat": 1795424100,
"nonce": "n-0S6_WzA2Mj",
"email": "[email protected]",
"name": "Ana Lopez"
}SAML vs OIDC Login Flows
Both start with the user trying to open the app and end with the app knowing who they are. The middle differs:
| Step | SAML (SP-initiated, HTTP-POST binding) | OIDC (authorisation code flow) |
|---|---|---|
| 1 | User opens the app | User opens the app |
| 2 | App redirects the browser to the IdP with a SAML AuthnRequest | App redirects the browser to the IdP's authorise endpoint with client ID, redirect URI, scope=openid and a PKCE challenge |
| 3 | User signs in at the IdP (password, MFA) | User signs in at the IdP (password, MFA) |
| 4 | IdP returns an HTML form that auto-posts the signed assertion to the app's Assertion Consumer Service URL | IdP redirects back to the app with a short-lived authorisation code |
| 5 | App validates the XML signature, audience, time limits and replay | App exchanges the code for tokens directly with the IdP (back channel), sending the PKCE verifier |
| 6 | App creates a session | App validates the ID token signature and claims, then creates a session |
The biggest practical difference is step 4. In SAML, the identity assertion travels through the user's browser. In OIDC's code flow, only a one-time code passes through the browser; the tokens come straight from the IdP to the app. That's one reason OIDC fits mobile apps, where there's no browser form to post.
SAML also supports IdP-initiated login, where a user clicks an app tile in their company portal and lands signed in. Enterprises like it; it's also harder to protect against forged or replayed logins, so many apps restrict or carefully validate it.
OIDC vs SAML for Enterprise SSO
On OIDC vs SAML for enterprise SSO: if you sell software to companies, customers' IT teams will ask "do you support SSO?" and usually mean their IdP (Okta, Entra ID, Google Workspace, Ping, OneLogin and others) connecting to your app.
| Consideration | SAML | OIDC |
|---|---|---|
| Customer IdP support | Universal among enterprise IdPs | Supported by all major IdPs |
| What customers ask for | Still the most common request in enterprise security questionnaires | Increasingly accepted, especially by newer IT teams |
| Setup by the customer | Upload or exchange metadata, map attributes | Create an app registration, share client ID and secret |
| Multi-tenant handling in your app | One SAML connection per customer | One OIDC connection per customer |
| Attribute mapping | Flexible attribute statements | Standard claims plus custom claims |
| Logout | Single logout defined, often unreliable in practice | Front-channel and back-channel logout specs; also unevenly supported |
The practical answer for B2B SaaS: support both. Most identity platforms and SSO libraries let you offer SAML and OIDC connections per customer. If you must start with one for enterprise customers, start with SAML, since every corporate IdP speaks it; offer OIDC as soon as you can.
Alongside SSO, enterprise customers often ask for SCIM, a separate standard for automatically creating, updating and removing user accounts. SSO handles sign-in; SCIM handles the user lifecycle.
SAML vs OAuth
SAML vs OAuth is a common mix-up, because both appear in SSO discussions. They solve different problems:
- SAML is about authentication: telling an app who the user is.
- OAuth 2.0 is about authorisation: letting an app access an API on a user's behalf, with an access token, without sharing the user's password.
- OIDC adds authentication on top of OAuth, which is why the real login comparison is SAML vs OIDC.
Our guide to authentication vs authorization explains the distinction, and OAuth vs JWT covers how OAuth and tokens relate.
SAML vs OIDC Security
Both protocols are secure when implemented correctly, and both have a history of implementation bugs.
| Risk | SAML | OIDC |
|---|---|---|
| Signature handling | XML signature wrapping attacks: a crafted document passes signature checks while the app reads an unsigned part | Algorithm confusion: accepting alg: none or the wrong key type |
| Token interception | Assertion passes through the browser | Code interception, mitigated by PKCE and exact redirect URI matching |
| Replay | Must check assertion ID, time limits and audience | Must check nonce, exp, aud and iss |
| Parsing complexity | XML canonicalisation and namespaces are hard to get right | JSON is simpler to parse |
| Key rotation | Certificates in metadata, often updated by hand | Keys published as a JWKS document and fetched automatically |
Rules that apply to both:
- Use a maintained library or identity service. Don't parse SAML XML or verify JWTs with hand-written code.
- Validate everything: signature, issuer, audience, expiry and replay protection.
- Pin each customer connection to the expected IdP and keys, so one tenant can't sign in as another.
- Use HTTPS everywhere and exact redirect or ACS URLs.
Mobile Apps, SPAs and APIs
OIDC's advantage is clearest outside traditional web apps:
- Mobile and desktop apps use the authorisation code flow with PKCE in the system browser, then receive tokens. SAML has no clean equivalent.
- Single-page apps can use the same flow, or a backend-for-frontend that holds tokens server side.
- APIs need access tokens. OIDC logins come with OAuth access tokens; SAML logins don't, so SAML-based apps need a separate mechanism for API calls. For machine-to-machine access, see our comparison of an API key vs OAuth.
Which Should You Use?
There's no single answer to which is better SAML or OIDC; it depends on who your users are and what their identity providers support.
| Situation | Choose | Why |
|---|---|---|
| New consumer or SaaS app with "Sign in with Google/Microsoft" | OIDC | Native to modern IdPs and social logins |
| Mobile or desktop app | OIDC | Code flow with PKCE is designed for it |
| Selling to large enterprises | SAML first, then OIDC | Every corporate IdP and IT team knows SAML |
| Internal tools at a company using Entra ID, Okta or Google | Either; OIDC is usually simpler | Both are supported |
| App also needs API access tokens | OIDC | Built on OAuth |
| Legacy or government system that only speaks SAML | SAML | Compatibility |
Adding SSO to Your App: A Checklist
- Decide where SSO lives. A managed identity service or an open-source identity server can handle both protocols for you; building on raw libraries means owning every protocol detail.
- Model tenants and connections. Each customer gets its own SAML or OIDC connection, tied to their email domains, so users are routed to the right IdP.
- Choose the user key. Store the IdP's issuer plus the stable subject identifier (SAML NameID, OIDC
sub), not just an email address. - Map attributes. Decide which claims set name, email, groups and roles, and what happens when they change.
- Plan provisioning and deprovisioning. Just-in-time creation at first login is a start; SCIM lets customers remove access centrally.
- Handle certificate and key rotation without downtime: OIDC fetches keys automatically; SAML usually needs a second certificate slot.
- Test with real IdPs. Okta, Entra ID and Google each have quirks; most offer free developer tenants.
Common Mistakes
- Treating OAuth access tokens as proof of identity. Use the OIDC ID token, or the userinfo endpoint, to identify the user.
- Skipping assertion or token validation because the request came from the IdP's domain.
- Accepting IdP-initiated SAML without safeguards.
- Hard-coding certificates or keys and breaking when the IdP rotates them.
- Matching users by email alone across tenants, which can let someone with the same address at another IdP take over an account. Match on the IdP plus its stable subject identifier.
FAQ
Is OIDC replacing SAML?
For new apps and consumer logins, largely yes. In enterprise workforce SSO, SAML is still widely used and will be for years, so B2B apps usually support both.
Is OIDC more secure than SAML?
Neither is inherently more secure. OIDC's JSON tokens and code flow avoid some of SAML's XML parsing pitfalls, but both are safe only when validated correctly.
Can SAML and OIDC be used together?
Yes. Many identity providers accept a SAML login from one system and issue OIDC tokens to another, acting as a bridge.
Does OIDC use JWT?
Yes. The ID token is a JSON Web Token, signed by the identity provider. Access tokens may also be JWTs, but that depends on the provider.
What does an app need to set up SAML or OIDC?
For SAML: the IdP's metadata (entity ID, SSO URL, signing certificate) and your app's metadata. For OIDC: the issuer URL, a client ID and secret, and a redirect URI.