We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

SAML and OIDC

Enterprise systems often need single sign-on (SSO): a way for users to authenticate with one identity provider, and then access multiple applications.

SAML 2.0 and OpenID Connect (OIDC) support SSO through federated identity. Your app relies on an identity provider (IdP) to authenticate the user, then validates a protocol message from that IdP.

SAML vs. OIDC

SAML is widely used for legacy enterprise SSO. It uses XML documents called assertions to tell your app, the service provider, what the IdP verified about the user.

OIDC is an identity layer built on OAuth 2.0. Its ID tokens are JWTs, and the protocol fits naturally into web, mobile, and API architectures that already use OAuth.

Both can solve the same SSO problem, but their message formats, flows, and validation rules are different.

How They Work

SAML flow:

  1. The user visits your app.
  2. Your app redirects the user to the IdP.
  3. The user logs in with the IdP.
  4. The IdP returns a SAML response through the browser to your app's assertion consumer service.
  5. Your app validates the response and assertion before creating a local session.

OIDC flow:

  1. The user visits your app.
  2. Your app creates request-binding values like state, nonce, and a PKCE challenge, then redirects the user to the IdP.
  3. The user logs in with the IdP.
  4. The IdP redirects back with an authorization code.
  5. Your app verifies the callback and exchanges the code for tokens, including an ID token.
  6. Your app validates the ID token, including its nonce, before creating a local session.

The important detail is that your app should not ask for the user's password. The IdP handles authentication; your app validates the result. For an OIDC ID token, that includes its signature, issuer, audience, expiration, and nonce when one was sent. Don't trust identity claims until the protocol response passes every required check!

Don't implement SAML or OIDC from scratch! Use a mature protocol library or a trusted identity product, then configure and validate it according to the provider and protocol documentation.