All guides

SAML or OIDC: choosing a protocol for single sign-on

Both protocols let an application rely on an identity provider for sign-in. SAML carries a signed XML assertion through the browser. OpenID Connect returns a signed JSON Web Token from a token endpoint.

Hands typing on a laptop

How SAML works

The SAML standard is a framework that online business partners use to exchange security information. In web single sign-on it has two roles. The identity provider (IdP) authenticates the user and asserts that to the service provider (SP), the application.

The OASIS technical overview calls SP-initiated sign-on the most common way to start, and describes it with the Redirect and POST bindings:

  1. The user requests a resource at the SP, and the SP redirects the browser to the IdP with an AuthnRequest.
  2. The IdP checks whether the user has a logon session and, if not, asks for credentials.
  3. The IdP builds an assertion, digitally signs it and places it in a Response. It returns an HTML form that the browser posts to the SP's assertion consumer service.
  4. The SP validates the signature first, then processes the assertion and creates a local session for the user.

This assertion is shortened from the example in the overview. It holds the issuer, the subject's name identifier, a validity period and an audience restriction.

XML

<saml:Assertion xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion"
    ID="identifier_3" Version="2.0" IssueInstant="2004-12-05T09:22:05Z">
  <saml:Issuer>https://idp.example.org/SAML2</saml:Issuer>
  <saml:Subject>
    <saml:NameID Format="urn:oasis:names:tc:SAML:2.0:nameid-format:transient">
      3f7b3dcf-1674-4ecd-92c8-1544f346baf8
    </saml:NameID>
  </saml:Subject>
  <saml:Conditions NotBefore="2004-12-05T09:17:05Z"
      NotOnOrAfter="2004-12-05T09:27:05Z">
    <saml:AudienceRestriction>
      <saml:Audience>https://sp.example.com/SAML2</saml:Audience>
    </saml:AudienceRestriction>
  </saml:Conditions>
</saml:Assertion>

The two parties share configuration as SAML metadata: XML documents that can express an entity's bindings, roles, identifiers and the keys for signing and encryption. SAML also has an IdP-initiated flow, in which the user starts at the IdP and no AuthnRequest is sent.

How OIDC works

OpenID Connect (OIDC) is an identity layer on top of OAuth 2.0. It calls the identity provider the OpenID Provider and the application the relying party.

In its authorization code flow, the provider authenticates the user and sends the browser back to the application with an authorization code. The application presents the code at the provider's token endpoint and receives an ID token and an access token. The ID token is a signed JWT. This is the specification's example of its claims:

JSON

{
  "iss": "https://server.example.com",
  "sub": "24400320",
  "aud": "s6BhdRkqt3",
  "nonce": "n-0S6_WzA2Mj",
  "exp": 1311281970,
  "iat": 1311280970,
  "auth_time": 1311280969,
  "acr": "urn:mace:incommon:iap:silver"
}

The provider publishes its signing keys in a JWK Set at its jwks_uri. The verifier retrieves them again when a token names a key it does not know.

Where each one fits

  • SAML. The OASIS overview describes web single sign-on between domains as a use case for SAML, and the Web Browser SSO profile defines its message flows. Keycloak's documentation gives two reasons users pick SAML: a perception that it is mature, and existing applications that are secured with it.
  • OIDC. The OpenID Foundation says OpenID Connect lets developers launch sign-in flows across web-based, mobile and JavaScript clients. Keycloak's documentation says OIDC tokens are JSON, which makes them easier for JavaScript to consume. It recommends OIDC for most purposes.
  • APIs. An OpenID Connect token response includes an access token as well as the ID token.

Provisioning with SCIM

RFC 7642 draws the line. It says SCIM differs from SAML web single sign-on in this: SCIM provisions and de-provisions resources in a context separate from authentication.

SCIM is an HTTP-based protocol. RFC 7643 defines a JSON schema for users and groups, and RFC 7644 defines the protocol, with /Users and /Groups endpoints. A client sends the requests, and the application that holds the accounts is the service provider. RFC 7642 describes the flows: an enterprise pushes an account creation request when a user joins, an update when an attribute changes, and a suspend account request when employment ends.

Microsoft Entra ID is one such client. Its documentation shows the request it sends to disable a user:

Text

PATCH /Users/5171a35d82074e068ce2 HTTP/1.1
{
    "Operations": [
        {
            "op": "Replace",
            "path": "active",
            "value": false
        }
    ],
    "schemas": [
        "urn:ietf:params:scim:api:messages:2.0:PatchOp"
    ]
}

SCIM defines no authentication scheme of its own. RFC 7644 relies on TLS and standard HTTP authentication, and names bearer tokens with OAuth 2.0 as one option. The Microsoft page adds that SCIM, used with federation standards like SAML or OpenID Connect, gives administrators an end-to-end solution for access management.

What to ask a software vendor

  • Which protocols the product supports: SAML 2.0, OpenID Connect or both.
  • For SAML, whether sign-in can start at the product, at the identity provider or both. SAML defines both flows.
  • How the product obtains the identity provider's signing keys: from SAML metadata, or from the jwks_uri of an OpenID Provider.
  • Which value identifies the user. OpenID Connect says only iss and sub together are a stable identifier, and that an email address may change.
  • Whether the product validates the signature on the assertion or the ID token.
  • Whether the product has a SCIM endpoint for users and for groups.

How to decide

  1. If the product supports one protocol, that is the protocol you use.
  2. For a mobile app or a JavaScript application, choose OIDC. The OpenID Foundation and Keycloak statements above are the basis.
  3. Choose SAML for an application that offers nothing else, or that is already secured with it.
  4. Treat provisioning as its own decision, because SCIM is a separate protocol. Test it: remove a test user at the identity provider and confirm that the account in the application is deactivated.

Sources

Want a second pair of eyes on yours? We do this work for a living.

Book a call

More guides