# How SAML v2 IdP-Initiated Login Works

Learn how FusionAuth handles a SAML v2 IdP-initiated login, and how FusionAuth chooses the redirect URI and scope.

> For the index of this section of the site, see [llms.txt](https://fusionauth.io/docs/llms.txt)

In a [service provider initiated login](https://fusionauth.io/docs/authentication/identity-providers/overview-samlv2.md), your application starts the login. Your application sends the user to the [Authorize endpoint](https://fusionauth.io/docs/apis/oauth/authorize.md), FusionAuth sends the user to the SAML v2 Identity Provider (IdP), and the IdP returns a SAML response to FusionAuth.

In an IdP-initiated login, the user starts at the IdP, such as a tile in an Okta or Azure AD dashboard. The IdP posts a SAML response to FusionAuth without a request from FusionAuth. FusionAuth then completes an OAuth Authorization Code grant for the Application, and sends the user to your application with an authorization code.

Caution

FusionAuth doesn't recommend IdP-initiated login. FusionAuth didn't start the login, so FusionAuth can verify less about the SAML response. FusionAuth must also accept a cross-site `POST` request from the IdP. Enable IdP-initiated login only to support a legacy integration, or when the user experience matters more than the risk.

## Identity Provider Types

The following Identity Provider types accept IdP-initiated logins:

*   A [SAML v2 Identity Provider](https://fusionauth.io/docs/authentication/identity-providers/overview-samlv2.md) with **Enable IdP initiated login** turned on. This type supports SP-initiated and IdP-initiated logins with the same configuration. Available in FusionAuth `1.43.0` and later.
*   A [SAML v2 IdP Initiated Identity Provider](https://fusionauth.io/docs/authentication/identity-providers/enterprise/samlv2-idp-initiated.md). This type supports only IdP-initiated logins. Use this type for an IdP that can't start an SP-initiated login. Available in FusionAuth `1.26.0` and later.

Both types require a paid plan, and handle the login in the same way.

## The Login Flow

An IdP-initiated login skips the Authorize request. During an SP-initiated login, the Authorize request carries the **`redirect_uri`** and **`scope`** parameters from your application. During an IdP-initiated login, FusionAuth reads those values from the IdP's request instead.

```mermaid
sequenceDiagram
    participant User
    participant IdP as SAML v2 IdP
    participant FusionAuth
    participant App as Application
    User ->> IdP : Log in and choose the application
    IdP ->> FusionAuth : POST the SAML response and RelayState to the ACS URL
    FusionAuth ->> App : Redirect to the redirect URI with an authorization code
    App ->> FusionAuth : Exchange the authorization code for tokens
```

During an IdP-initiated login, FusionAuth reads the redirect URI and scope from the request that the SAML v2 IdP sends to the ACS URL.

The IdP sends the SAML response to an [ACS](https://fusionauth.io/docs/authentication/identity-providers/overview-samlv2.md) URL for one Application:

```plaintext
<base_url>/samlv2/acs/<identityProviderId>/<clientId>
```

`<clientId>` is the **Client Id** of the Application. FusionAuth lists the URL for each enabled Application in **IdP Initiated Callback URLs (ACS)** in the Integration Details of the Identity Provider. For more information, see [Integration Details](https://fusionauth.io/docs/authentication/identity-providers/samlv2-settings.md#integration-details).

After FusionAuth validates the SAML response, FusionAuth logs the user in and creates an SSO session. The code exchange doesn't use PKCE, even when the Application requires PKCE, because the IdP can't send a code challenge.

## Redirect URI

FusionAuth chooses the redirect URI in the following order:

1.  The `RelayState` parameter that the IdP sends with the SAML response. Available in FusionAuth `1.41.0` and later.
2.  The **`redirect_uri`** query parameter on the ACS URL.
3.  The first URL in **Authorized redirect URLs** on the OAuth tab of the Application. FusionAuth skips URLs that contain a wildcard.

The redirect URI must match a URL in **Authorized redirect URLs**. When the redirect URI doesn't match, FusionAuth shows an error page with the `invalid_redirect_uri` reason, and doesn't log the user in.

Most IdPs have a setting for a fixed `RelayState` value, such as **Default RelayState** in Okta. When an IdP can't send `RelayState`, URL encode the redirect URI and add the encoded value to the ACS URL:

```plaintext
<base_url>/samlv2/acs/<identityProviderId>/<clientId>?redirect_uri=https%3A%2F%2Fexample.com%2Fwelcome
```

Don't add `RelayState` to the ACS URL as a query parameter. FusionAuth combines a `RelayState` query parameter with the `RelayState` form value from the IdP, and the combined value doesn't match any redirect URL.

When the Application is the FusionAuth Admin UI, FusionAuth ignores the redirect URI and sends the user to the Admin UI.

## Scope and Refresh Tokens

The Application settings don't add a scope to an IdP-initiated login. To request scopes, add the **`scope`** query parameter to the ACS URL. Separate scopes with an encoded space (`%20`), and join query parameters with `&`:

```plaintext
<base_url>/samlv2/acs/<identityProviderId>/<clientId>?scope=openid%20offline_access
```

The token response depends on the scopes:

*   FusionAuth returns a refresh token when the scopes include `offline_access` and **Generate refresh tokens** is enabled on the Application. To use the refresh token later, enable the `Refresh Token` grant in **Enabled grants**.
*   FusionAuth returns an Id token when the scopes include `openid`.

When the Application is the FusionAuth Admin UI, FusionAuth adds the `offline_access` scope. For more information, see [Reserved Scopes](https://fusionauth.io/docs/authorization/oauth-scopes.md#reserved-scopes).

## Limitations

IdP-initiated login doesn't support [CIMD clients](https://fusionauth.io/docs/authentication/identity-providers/applications-and-overrides.md#cimd-clients). The Applications list of an Identity Provider with IdP-initiated login doesn't show [CIMD](https://fusionauth.io/docs/concepts/types/cimd-domains.md) domains. Available since `1.70.0`

Related

[Authentication SAML v2 Identity Provider Settings Reference for the form fields and Integration Details of the SAML v2 and SAML v2 IdP Initiated Identity Providers. samlsaml v2idp initiated](https://fusionauth.io/docs/authentication/identity-providers/samlv2-settings.md)

[APIs SAML v2 IdP Initiated API Learn about the APIs for creating, retrieving, updating and deleting SAML v2 IdP Initiated identity providers. samlidp initiated](https://fusionauth.io/docs/apis/identity-providers/samlv2-idp-initiated.md)

[Authentication Add FusionAuth Login to an External Application Learn how to let users log in to a third-party application, such as a SaaS product, with their FusionAuth accounts over OpenID Connect or SAML v2. saml v2saml](https://fusionauth.io/docs/authentication/act-as-an-idp/add-login-to-external-app.md)

[Authentication Add SAML v2 IdP-Initiated Login With Okta Learn how to let users log in to FusionAuth from the Okta dashboard with SAML v2 IdP-initiated login. saml v2idp initiated login](https://fusionauth.io/docs/authentication/identity-providers/enterprise/okta-samlv2-idp-initiated.md)
---

## Other pages in Identity Providers

> For the full index of this section, see [Authentication](https://fusionauth.io/docs/llms-authentication.txt).

- [Identity Providers, Applications, and Overrides](https://fusionauth.io/docs/authentication/identity-providers/applications-and-overrides.md): Learn how Identity Providers work with Applications, CIMD clients, and Application-specific overrides.
- [Attribute Mappings](https://fusionauth.io/docs/authentication/identity-providers/attribute-mappings.md): Learn how to map claims from an Identity Provider response to FusionAuth user and registration fields without a lambda.
- [Add a SAML v2 with ADFS IdP](https://fusionauth.io/docs/authentication/identity-providers/enterprise/adfs.md): Configure SAML v2 for Active Directory Federation Services (ADFS).
- [Add an OpenID Connect with Azure AD IdP](https://fusionauth.io/docs/authentication/identity-providers/enterprise/azure-ad-oidc.md): Set up user login using Azure AD/Microsoft Entra ID as an OpenID Connect Identity Provider.
- [Add a SAML v2 with Azure AD IdP](https://fusionauth.io/docs/authentication/identity-providers/enterprise/azure-ad-saml.md): Learn how to configure Azure AD (Microsoft Entra ID) as a SAML v2 Identity Provider for FusionAuth.
- [Add a OpenID Connect with Cognito IdP](https://fusionauth.io/docs/authentication/identity-providers/enterprise/cognito.md): Set up user login using Cognito as an OpenID Connect Identity Provider.
- [Add a HYPR IdP](https://fusionauth.io/docs/authentication/identity-providers/enterprise/hypr.md): Set up user login with HYPR using the HYPR Identity Provider.
- [Add an OpenID Connect with Okta IdP](https://fusionauth.io/docs/authentication/identity-providers/enterprise/okta-oidc.md): Learn how to set up user login using Okta as an OpenID Connect Identity Provider.
- [Add SAML v2 IdP-Initiated Login With Okta](https://fusionauth.io/docs/authentication/identity-providers/enterprise/okta-samlv2-idp-initiated.md): Learn how to let users log in to FusionAuth from the Okta dashboard with SAML v2 IdP-initiated login.
- [Add a SAML v2 with Okta IdP](https://fusionauth.io/docs/authentication/identity-providers/enterprise/okta-samlv2.md): Configure SAML v2 for Okta.
- [Add a SAML v2 IdP-Initiated IdP](https://fusionauth.io/docs/authentication/identity-providers/enterprise/samlv2-idp-initiated.md): Learn how to let users log in to FusionAuth from a dashboard in a SAML v2 Identity Provider that supports only IdP-initiated login.
- [External JWT IdP Example Usage](https://fusionauth.io/docs/authentication/identity-providers/external-jwt/example.md): Learn how to federate identity using the External JWT Identity Provider.
- [Add an External JWT IdP](https://fusionauth.io/docs/authentication/identity-providers/external-jwt.md): Learn how to configure an External JWT Identity Provider so FusionAuth can log in users with JWTs from a third-party identity provider.
- [Add an OpenID Connect with Discord IdP](https://fusionauth.io/docs/authentication/identity-providers/gaming/discord.md): Learn how to add a Login with Discord button to the FusionAuth login pages with the OpenID Connect Identity Provider.
- [Add an Epic Games IdP](https://fusionauth.io/docs/authentication/identity-providers/gaming/epic-games.md): Learn how to add an Epic Games login button to the FusionAuth login pages.
- [Add a Nintendo IdP](https://fusionauth.io/docs/authentication/identity-providers/gaming/nintendo.md): Learn how to add a Nintendo login button to the FusionAuth login pages.
- [Add a Sony PlayStation Network IdP](https://fusionauth.io/docs/authentication/identity-providers/gaming/sony.md): Learn how to add a Sony PlayStation Network login button to the FusionAuth login pages.
- [Add a Steam IdP](https://fusionauth.io/docs/authentication/identity-providers/gaming/steam.md): Learn how to add a Steam login button to the FusionAuth login pages.
- [Add a Twitch IdP](https://fusionauth.io/docs/authentication/identity-providers/gaming/twitch.md): Learn how to add a Twitch login button to the FusionAuth login pages.
- [Add an Xbox IdP](https://fusionauth.io/docs/authentication/identity-providers/gaming/xbox.md): Learn how to add an Xbox login button to the FusionAuth login pages.
- [Identity Provider Hints](https://fusionauth.io/docs/authentication/identity-providers/hints.md): Learn how to send users from the hosted login pages straight to an Identity Provider with the idp_hint and login_hint parameters.
- [Identity Provider Scope](https://fusionauth.io/docs/authentication/identity-providers/identity-provider-scope.md): Learn about global and tenant-scoped Identity Providers, and how to limit the links that each user can have to an Identity Provider.
- [Add an Identity Provider (IdP)](https://fusionauth.io/docs/authentication/identity-providers.md): Learn how to let users log in through an external identity provider such as Google or Okta.
- [Linking Strategies](https://fusionauth.io/docs/authentication/identity-providers/linking-strategies.md): Learn how FusionAuth links a user from an Identity Provider to a FusionAuth user.
- [Managed Domains](https://fusionauth.io/docs/authentication/identity-providers/managed-domains.md): Learn how managed domains connect email domains to an Identity Provider.
- [Add an OpenID Connect IdP](https://fusionauth.io/docs/authentication/identity-providers/overview-oidc.md): Learn how to let users log in to FusionAuth through an external OpenID Connect Identity Provider.
- [Add an External SAML v2 IdP](https://fusionauth.io/docs/authentication/identity-providers/overview-samlv2.md): Learn how to let users log in to FusionAuth through an external SAML v2 Identity Provider.
- [SAML v2 Identity Provider Settings](https://fusionauth.io/docs/authentication/identity-providers/samlv2-settings.md): Reference for the form fields and Integration Details of the SAML v2 and SAML v2 IdP Initiated Identity Providers.
- [How FusionAuth Verifies SAML v2 Signatures](https://fusionauth.io/docs/authentication/identity-providers/samlv2-signature-verification.md): Learn how FusionAuth chooses the key that verifies the signature on a SAML response, and how certificate rotation works.
- [Add an Apple IdP](https://fusionauth.io/docs/authentication/identity-providers/social/apple.md): Learn how to add a Sign in with Apple button to your application.
- [Add a Facebook IdP](https://fusionauth.io/docs/authentication/identity-providers/social/facebook.md): Learn how to add a Login with Facebook button to your application.
- [Add a Github IdP](https://fusionauth.io/docs/authentication/identity-providers/social/github.md): Set up user login using Github as an OpenID Connect Identity Provider.
- [Add a Google IdP](https://fusionauth.io/docs/authentication/identity-providers/social/google.md): Learn how to add a Login with Google button to your application.
- [Add a LinkedIn IdP](https://fusionauth.io/docs/authentication/identity-providers/social/linkedin.md): Learn how to add a Sign in with LinkedIn button to your application.
- [Add a Twitter/X IdP](https://fusionauth.io/docs/authentication/identity-providers/social/twitter.md): Learn how to add a Login with Twitter/X button to your application.
