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.

Short answer

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.

SAMLOIDC
StandardSAML 2.0, OASIS, 2005OpenID Connect Core 1.0, 2014, on OAuth 2.0 (RFC 6749)
TokenXML assertion signed with XML SignatureID token: a JWT signed with JWS
TransportBrowser redirects and auto-posted formsRedirects plus a back-channel token request
Typical flowSP-initiated or IdP-initiated POST bindingAuthorization code flow with PKCE
Native and mobile appsAwkward, browser-only by designFirst-class, with PKCE and system browser
API accessNone built inAccess token from the same flow
ConfigurationExchange XML metadata and certificatesDiscovery document and JWKS URL
Key rotationManual certificate swap in metadataAutomatic via JWKS kid
LogoutSingle Logout (fragile in practice)RP-initiated, front-channel and back-channel logout specs
Main attack classXML signature wrapping, parser bugsWeak token validation: aud, iss, alg, nonce
ProvisioningNot included; use SCIMNot 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.

iThe structural difference

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 (trimmed)xml
<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>
OIDC ID token payload (decoded)json
{
  "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

CheckSAMLOIDC
Who issued itIssuer and signature against pinned IdP certiss and signature against JWKS, alg allow-list
Meant for youAudience and Recipientaud equals your client_id
Still validNotBefore, NotOnOrAfterexp, iat, small clock skew
Answers your requestInResponseTo matches your AuthnRequest IDnonce and state match what you sent
Not replayedCache assertion IDs until expiryCode 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.
!Account linking

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

“How to say it in the room

"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.

Go deeper

Terms on this page