trio.so
Explained

SP-Initiated vs. IdP-Initiated SSO: How Each SAML Flow Works

How SP-initiated and IdP-initiated SAML SSO work step by step, the replay and CSRF risks, when each fits, common SAML errors and how OIDC compares.

Mountain landscape representing leadership perspective and vision
Written by
Atena Ladchartabi

Content writer, trio.so

Published on

SP-Initiated vs. IdP-Initiated SSO: How Each SAML Flow Works

SP-initiated vs IdP-initiated SSO comes down to who starts the login. In an SP-initiated flow, the user opens the application (the service provider, or SP), and the application sends a SAML AuthnRequest to the identity provider (IdP). In an IdP-initiated flow, the user starts at the IdP, picks an app, and the IdP posts an assertion to the app without being asked. Most apps prefer SP-initiated because the app can tie the response to a request it made. This guide walks through both flows, the risks, when each fits, and the errors you will see when you set them up.

The two flows at a glance

 SP-initiatedIdP-initiated
Who starts itThe user, at the app URL or a bookmarkThe user, at the IdP portal or app tile
First SAML messageAuthnRequest from the SPUnsolicited SAML response from the IdP
InResponseTo in the responsePresent, matches the request IDAbsent, there was no request
RelayStateReturns the page the user wantedOften a fixed landing page, or blank
Best fitSecurity sensitive apps, deep links, customer facing appsInternal app portals, apps with a fixed landing page

How SP-initiated SSO works, step by step

  1. The user requests the app. They open a URL such as the app's sign in page or a deep link to a report. The app has no session for them.
  2. The SP builds an AuthnRequest. It is a small XML message with a unique ID, the Issuer (the SP's entity ID, its unique name), and the Assertion Consumer Service (ACS) URL, the address on the app where the response should land. The SP stores the ID. It usually sends the message to the IdP's SSO URL through the HTTP Redirect binding (a way of carrying a SAML message, here in the URL), compressed and base64 encoded in the query string.
  3. The SP sets RelayState. RelayState is a short value the SP sends with the request and the IdP returns unchanged. Apps use it to remember where the user was going, or a reference to saved state. The SAML bindings specification limits RelayState to 80 bytes, so apps store a short reference rather than a full URL where they can.
  4. The IdP authenticates the user. It checks for an existing session, or prompts for credentials and multi-factor authentication (MFA).
  5. The IdP returns a signed response. It posts a SAML response containing an assertion to the ACS URL through the HTTP POST binding. The response carries InResponseTo set to the ID of the AuthnRequest (the field that names the request being answered), plus the audience, the validity window (NotBefore and NotOnOrAfter), the NameID and any attributes.
  6. The SP validates and signs the user in. It checks the signature against the IdP certificate, the destination (the URL the response was sent to), the audience (the SP it was issued for), the time window, and that InResponseTo matches a request ID it issued and has not yet used. Then it creates a session and sends the user to the RelayState target.

How IdP-initiated SSO works, step by step

  1. The user signs in to the IdP. They land on a portal or dashboard that lists their apps.
  2. The user clicks an app tile. The SP has not been contacted, so no AuthnRequest exists.
  3. The IdP sends an unsolicited response. It builds a signed assertion for that app and posts it to the ACS URL. There is no InResponseTo. RelayState, if the IdP sends one, is set in the IdP's app settings.
  4. The SP validates and signs the user in. It checks the signature, audience, destination and time window, and it must accept a response that matches none of its stored requests. That last point is the difference from the SP-initiated flow, and it is why many SPs make IdP-initiated login an option you turn on.

Security trade-offs

The SP-initiated flow has a built-in check: the app only accepts a response that answers a request it issued. IdP-initiated login has no request to compare against, so the response must be trusted on its own. That leads to three concerns.

  • Replay. An attacker who captures a valid response can post it again before it expires. The SP can defend by recording assertion IDs until NotOnOrAfter and rejecting repeats, and by keeping validity windows short. In the SP-initiated flow, the app accepts each request ID once, so a replayed response fails the InResponseTo check without any extra assertion ID tracking.
  • Login CSRF (cross-site request forgery), also called assertion injection. An attacker can get their own valid response posted from a victim's browser, for example through a hidden form on a page the victim visits. The app then signs the victim in to the attacker's account, where the victim may enter real data. A stored request ID and a RelayState tied to the user's browser session stop this in the SP-initiated flow. The IdP-initiated flow has no request to check against.
  • Full trust in the IdP. An app that accepts unsolicited responses has no second check, so a stolen signing key or a misconfigured IdP lets an attacker sign in as anyone.

OWASP's SAML guidance describes IdP-initiated SSO as less secure by design and recommends SP-initiated flows where possible. If you must enable IdP-initiated login, shorten the assertion lifetime, require signed assertions, restrict the ACS URL and audience, reject repeated assertion IDs, and do not redirect to a RelayState target without checking it against an allow list (otherwise the page becomes an open redirect: an attacker can use your login page to send users to any site).

When each flow fits

  • Choose SP-initiated for apps that hold sensitive data, apps users reach through bookmarks or deep links, and customer or partner apps where users never see your IdP portal.
  • Choose IdP-initiated when users live in the IdP portal and the app has a single landing page, or when the app only supports that flow. Turn IdP-initiated login on as a second option and keep SP-initiated login enabled, because bookmarks and direct links to the app start the SP-initiated flow.
  • Support both in most workplaces. Users click tiles in the portal and also open the app directly. Test both before rollout, because they fail in different ways.

How OIDC compares

OpenID Connect (OIDC) is built on OAuth 2.0 and uses JSON web tokens rather than XML assertions. The standard login flow is already client-initiated: the app redirects to the provider with a state value (a random string the app checks on return) and a nonce (a random string that must appear in the ID token). The recommended version is the authorization code flow with PKCE (Proof Key for Code Exchange), which proves that the app that started the login is the one finishing it. The state value ties the response to the request, and the nonce ties the ID token to it. In SAML, the AuthnRequest ID does this job. In OIDC, state and nonce do it together. OIDC has no unsolicited response. The closest feature is third-party initiated login, where the identity provider only links to the app. The link points to a login initiation URL, and the app decides whether to start its own authorization request. The app stays in control, so the SAML IdP-initiated weakness does not carry over. For a deeper comparison of the protocols, read OIDC vs SAML.

Common SAML errors and fixes

SymptomLikely causeFix
Works from the app, fails from the IdP portal (or the reverse)The app has IdP-initiated login off, or the IdP tile uses a different ACS URLEnable the flow on the SP and compare the ACS URL on both sides
"InResponseTo does not match" or "unknown request ID"The request ID was not stored, expired, or the user returned through a different server behind a load balancer, or in a different sessionStore request IDs where every server can read them, lengthen the ID lifetime a little, and retry from a clean session
"Audience restriction" or "invalid audience"The SP entity ID configured in the IdP differs from the one the app expectsCopy the entity ID from the SP metadata exactly, including any trailing slash
"Assertion is not yet valid" or "has expired"Clock skew between IdP and SP outside the NotBefore and NotOnOrAfter windowSync both to NTP and allow a small skew, such as a minute or two
"Signature validation failed"The IdP rotated its signing certificate, or the SP checks the wrong elementImport the new IdP metadata and check whether the response, the assertion or both are signed
"Destination mismatch" or an ACS URL errorThe ACS URL in the response differs from the SP's configured URL (scheme, host or path)Make the IdP value match the SP's ACS URL character for character
Signed in, but as the wrong user or with no accessNameID format or attribute names differ from what the app mapsSet the NameID format (email is common) and match the attribute names on both sides
User lands on the home page, not the page they asked forRelayState was dropped or exceeded the 80 byte limitStore the target server side and send a short reference as RelayState

A browser extension that decodes SAML messages, or the IdP's sign in log, shows the exact assertion and which check failed. For setup detail, see the SAML configuration guide and how SAML authentication works.

Where trio.so fits

trio.so is a device and identity management platform. You add apps for single sign on and register your identity provider in trio.so. SSO apps and identity provider registration each support SAML 2.0 or OIDC, so you can connect the identity provider you already run. trio.so manages devices and identity together across Windows, macOS, Linux, iOS/iPadOS and Android. Read how single sign on works in trio.so. Plans start at $5 per device.

For how SSO relates to the wider identity picture, see federated identity vs SSO.

Start free trial or Book a demo.

14 day free trial. No credit card required.

Ready-to-use Templates

Must-have Template Toolkit for IT Admins

Explore All
Template Toolkit

Start your free trial

No credit card required
Full access to all features

Manage Every Device From One Console

trio.so brings device management, patching and security policies for Windows, macOS, Linux, iOS/iPadOS and Android into one console. Enroll a device and see it in the console within minutes.

14-day free trial. No credit card required.

trio.so brings device management, patching and security policies for Windows, macOS, Linux, iOS/iPadOS and Android into one console. Enroll a device and see it in the console within minutes.

Smiling womanAbstract geometric patternAbstract geometric patternSmiling womanSmiling woman

Frequently asked questions

In SP-initiated SSO the user starts at the app, and the app sends an AuthnRequest to the IdP. In IdP-initiated SSO the user starts at the IdP, and the IdP sends an unsolicited response to the app. The first lets the app match the response to its own request.

It carries more risk, because the app cannot check the response against a request it made. That exposes it to replay and login CSRF. Short assertion lifetimes, signed assertions, assertion ID tracking and an allow list for redirects reduce the risk but do not remove it.

RelayState is an opaque value the SP sends with a request and the IdP returns unchanged. Apps use it to send the user back to the page they wanted. The SAML bindings specification caps it at 80 bytes, so store a short reference.

Yes, if the app supports both. Many teams keep SP-initiated as the default and enable IdP-initiated login for portal tiles. Test each path separately, since the ACS URL, RelayState and validation rules differ.

Not as an unsolicited token. OIDC defines third-party initiated login, where the provider points the user at a login initiation URL on the app and the app starts a normal authorization request with its own state and nonce.

Related

From the blog

The related industry news, interviews, technologies, and resources.