SAML vs OIDC: choosing an SSO protocol for apps and enterprises
SAML 2.0 vs OpenID Connect for single sign-on: XML assertions vs JWT ID tokens, flows, mobile support, attack surface and when to use each.
Use OIDC for anything new: web apps, SPAs, mobile apps and APIs, because it uses JSON and JWTs, works with native apps and builds on OAuth 2.0 so you get API access in the same flow. Use SAML 2.0 when an enterprise customer or a legacy SaaS app demands it, which is still common in B2B. Both solve browser single sign-on well; SAML just carries a larger, XML-shaped attack surface. Many products support both and let the customer choose.
| SAML | OIDC | |
|---|---|---|
| Standard | SAML 2.0, OASIS, 2005 | OpenID Connect Core 1.0, 2014, on OAuth 2.0 (RFC 6749) |
| Token | XML assertion signed with XML Signature | ID token: a JWT signed with JWS |
| Transport | Browser redirects and auto-posted forms | Redirects plus a back-channel token request |
| Typical flow | SP-initiated or IdP-initiated POST binding | Authorization code flow with PKCE |
| Native and mobile apps | Awkward, browser-only by design | First-class, with PKCE and system browser |
| API access | None built in | Access token from the same flow |
| Configuration | Exchange XML metadata and certificates | Discovery document and JWKS URL |
| Key rotation | Manual certificate swap in metadata | Automatic via JWKS kid |
| Logout | Single Logout (fragile in practice) | RP-initiated, front-channel and back-channel logout specs |
| Main attack class | XML signature wrapping, parser bugs | Weak token validation: aud, iss, alg, nonce |
| Provisioning | Not included; use SCIM | Not included; use SCIM |
01How each one works
SAML: the service provider (SP) redirects the browser to the identity provider (IdP) with an AuthnRequest. The user authenticates, and the IdP returns an HTML form that auto-posts a signed XML Response containing an Assertion to the SP's Assertion Consumer Service URL. The SP validates the signature against the IdP certificate from metadata, checks conditions, and creates its own session.
OIDC: the relying party redirects the browser to the OpenID provider with scope=openid, a state, a nonce and a PKCE challenge. After login the browser returns with a short-lived code, which the relying party exchanges server to server for an ID token (and usually an access token). The ID token is a signed JWT whose keys come from the provider's JWKS endpoint.
In SAML the identity proof travels through the browser. In the OIDC code flow only a one-time code does; the token itself comes over a direct TLS connection, which removes a whole class of injection and leakage problems.
02What the relying party actually receives
<saml:Assertion ID="_a75adf55" IssueInstant="2026-11-15T09:00:00Z" Version="2.0">
<saml:Issuer>https://idp.example.com</saml:Issuer>
<ds:Signature>...</ds:Signature>
<saml:Subject>
<saml:NameID Format="urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress">ana@corp.example</saml:NameID>
<saml:SubjectConfirmation Method="urn:oasis:names:tc:SAML:2.0:cm:bearer">
<saml:SubjectConfirmationData InResponseTo="_req123"
NotOnOrAfter="2026-11-15T09:05:00Z" Recipient="https://app.example.com/saml/acs"/>
</saml:SubjectConfirmation>
</saml:Subject>
<saml:Conditions NotBefore="2026-11-15T08:59:30Z" NotOnOrAfter="2026-11-15T09:05:00Z">
<saml:AudienceRestriction><saml:Audience>https://app.example.com</saml:Audience></saml:AudienceRestriction>
</saml:Conditions>
</saml:Assertion>{
"iss": "https://idp.example.com",
"sub": "248289761001",
"aud": "app123",
"email": "ana@corp.example",
"iat": 1795251600,
"exp": 1795251900,
"nonce": "n-0S6_WzA2Mj",
"auth_time": 1795251590,
"amr": ["pwd", "otp"]
}What you must check
| Check | SAML | OIDC |
|---|---|---|
| Who issued it | Issuer and signature against pinned IdP cert | iss and signature against JWKS, alg allow-list |
| Meant for you | Audience and Recipient | aud equals your client_id |
| Still valid | NotBefore, NotOnOrAfter | exp, iat, small clock skew |
| Answers your request | InResponseTo matches your AuthnRequest ID | nonce and state match what you sent |
| Not replayed | Cache assertion IDs until expiry | Code is single use; nonce bound to session |
03When to pick which
- Building a new app or API: OIDC. Use the authorization code flow with PKCE for every client type.
- Selling B2B SaaS: support both. Large enterprises still run SAML-only IdP configurations, and procurement will ask for it.
- Native mobile or desktop app: OIDC through the system browser (RFC 8252). SAML has no good native story.
- Integrating an older enterprise app that only speaks SAML: use SAML, or put an identity broker in front that speaks OIDC to the app and SAML to the IdP.
- Need user provisioning and deprovisioning: neither protocol does it. Add SCIM 2.0 (RFC 7643 and RFC 7644) alongside whichever you choose.
04Common mistakes and migration notes
- SAML: validating the signature on one element and reading identity from another. This is XML signature wrapping; use a maintained library and read only from the signed assertion.
- SAML: accepting IdP-initiated responses without care. There is no InResponseTo to bind to, so replay and login CSRF are easier. Disable it unless a customer needs it.
- OIDC: decoding the ID token without verifying it, or trusting the alg header. Pin expected algorithms and fetch keys only from the issuer's JWKS.
- OIDC: using the ID token as an API credential. It is proof of login for the client; APIs should receive access tokens with their own audience.
- Migrating SAML to OIDC: map the NameID to a stable subject first. Email addresses change; keying accounts on them causes takeovers and duplicates.
When a user arrives through a new protocol or IdP, match on issuer plus subject, never on email alone. Unverified email claims are a well known account takeover path.
05How to say it in an interview
"Both do browser SSO. SAML posts a signed XML assertion through the browser; OIDC returns a code and the app swaps it server side for a signed JWT, and it sits on OAuth so I get API tokens too. For anything new I pick OIDC with PKCE, I keep SAML for enterprise customers who need it, and either way I pair it with SCIM so deprovisioning actually happens."
Questions people ask
Q1Is OIDC more secure than SAML?+
Neither is inherently secure or insecure, but OIDC's code flow keeps tokens out of the browser and JWT validation is simpler to get right than XML signature validation. Most real SAML breaches come from parser and signature handling bugs.
Q2Can SAML and OIDC be used together?+
Yes. Identity brokers such as Keycloak, Entra ID or Okta routinely accept SAML from an upstream IdP and issue OIDC tokens to applications, or the reverse.
Q3Is SAML deprecated?+
No. SAML 2.0 is stable and widely deployed in enterprises. It is simply not where new protocol work happens.
Q4Does OIDC replace OAuth?+
No. OIDC is an identity layer on top of OAuth 2.0. OAuth handles delegated access to APIs; OIDC adds a standard way to learn who logged in.
Q5What is the SAML equivalent of an ID token?+
The SAML assertion. Both are signed statements from the IdP about who authenticated, when, and for which audience.