> For AI agents: the complete Sanity documentation index is available at [https://www.sanity.io/docs/llms.txt](https://www.sanity.io/docs/llms.txt).

# Set up SSO authentication with SAML and Azure/Entra ID

Implement single sign-on authentication with the SAML protocol and Microsoft Entra ID (formerly Azure AD) as the identity provider.

> [!NOTE]
> This developer guide was contributed by Saskia Bobinska (Senior Support Engineer), Benjamin Weinberger (Support Engineer at Sanity.io), Tim Naughton (Sanity Support Engineer), Dain Cilke (Software Engineer @ Sanity.io), and Marco Spinello (Technical writer at Sanity.io. I curate my own typos.).

Configure and enable single sign-on (SSO) for your Sanity organization using the SAML protocol, with Microsoft Entra ID (formerly Azure AD) as the identity provider (IdP).

During the setup and configuration process, it's a good idea to keep two windows side by side:

- One with [Sanity Manage](https://www.sanity.io/manage).
- The other with the configuration settings of the IdP; in this case, Azure (Microsoft Entra ID).

## Prerequisites

- An organization with a project on the [Enterprise plan](https://www.sanity.io/pricing).
- The Administrator role on your Sanity organization.
- Access to Microsoft Entra ID with permission to create and configure enterprise applications.

## Open the configuration screens

### Go to the service configuration (Sanity)

Go to [Sanity Manage](https://www.sanity.io/manage/org/settings/saml) and select the organization you want to enable SSO for.

To navigate to the service provider configuration inside Sanity Manage:

1. In the organization you intend to add SSO to, select **Settings > SAML SSO** in the sidebar.
2. If no SAML SSO provider exists, click **Configure** and proceed to create and configure a SAML SSO provider.

### Go to the service configuration (Azure/Entra ID)

To navigate to the identity provider configuration in Azure: 

1. Log in to Azure.
2. Go to **Azure Active Directory**.
3. On the sidebar, go to **Enterprise applications**.

![In Azure, go to Services, and then select Azure Active Directory.](https://cdn.sanity.io/images/3do82whm/next/5ab6659c9083bbc18e62deda29e6138ef81ab136-646x422.png)
*In Azure, go to Services, and then select Azure Active Directory.*

![On the sidebar, select Enterprise applications.](https://cdn.sanity.io/images/3do82whm/next/faf8dcdbec3a52ebb467d6b4bc674f7267168c64-516x764.png)
*On the sidebar, select Enterprise applications.*

In **Enterprise applications**:

1. Select an existing SAML application or create a new enterprise application. 
If you create a new application, you can also integrate any other applications not available in the gallery.
2. Go to **Set up single sign on**, and then choose the SAML sign-on method to use.

![Set up single sign-on.](https://cdn.sanity.io/images/3do82whm/next/582f16aa4f2e96702fbf4015b609ce16efa73ed9-704x300.png)
*Set up single sign-on.*

![Choose the SAML single sign-on method to use.](https://cdn.sanity.io/images/3do82whm/next/a3c77bfd1288363513fbcb8c2eba105c4d5aca3a-700x364.png)
*Choose the SAML single sign-on method to use.*

If you're keeping two browser tabs or windows open side by side, now you should have one on the configuration screen inside Sanity Manage, and the other on the configuration screen in Azure.

## Configure the Azure IdP

### Basic SAML Configuration

1. In Azure, edit the **Basic SAML Configuration** form.
2. Add an **Identifier (Entity ID)** to the basic SAML configuration.1. Use the value of **Sanity entity ID** from Sanity Manage.


3. Add a **Reply URL (Assertion Consumer Service URL)**.1. Use the value of **Sanity callback URL** from Sanity Manage.


4. Click **Save**.

![Edit the Basic SAML Configuration form.](https://cdn.sanity.io/images/3do82whm/next/d35116e2665bd60c8d831ba4d9aa4076c876e4ed-1440x364.png)
*Edit the Basic SAML Configuration form.*

![The Entity ID in Azure corresponds to the Sanity entity ID inside Sanity Manage.](https://cdn.sanity.io/images/3do82whm/next/c2708b282b7b68d938cb5f1bc336940fcaca14ef-384x216.png)
*The Entity ID in Azure corresponds to the Sanity entity ID inside Sanity Manage.*

![The Reply URL (Assertion Consumer Service URL) in Azure corresponds to the Sanity callback URL inside Sanity Manage.](https://cdn.sanity.io/images/3do82whm/next/3451d846dbf6ea46424433cbac85654f08029567-720x206.png)
*The Reply URL (Assertion Consumer Service URL) in Azure corresponds to the Sanity callback URL inside Sanity Manage.*

## Attributes & Claims

### Required claim

1. In Azure, edit the **Attributes & Claims** form.
2. Edit the **Unique User Identifier (Name ID)** claim, and change the **Name identifier format** to **Persistent**.
3. Click **Save**. 

![Edit the Unique User Identifier (Name ID) claim.](https://cdn.sanity.io/images/3do82whm/next/089281130cd065e95672fa2ab4241cdb6440fb49-792x234.png)
*Edit the Unique User Identifier (Name ID) claim.*

![Change the Name identifier format to Persistent.](https://cdn.sanity.io/images/3do82whm/next/4d0a84456cd0d0d1547af866afc635ff1defb202-1900x808.png)
*Change the Name identifier format to Persistent.*

### Additional claims

Now, configure Azure to send the claims that Sanity requires in the expected form.
The claims (attributes) that Sanity expects are listed inside Sanity Manage:

![The Attributes table in Sanity Manage, listing the required email, firstName, and lastName attributes and the optional id, displayName, and picture attributes.](https://cdn.sanity.io/images/3do82whm/next/18f810fa9a8fe4daf05d4c105097b09572626d66-1440x540.png)
*Inside Sanity Manage you can view the claims (attributes) that Sanity requires from Azure.*

For each claim:

1. Ensure the claim **Name** matches the attribute name listed in Sanity Manage.
2. Ensure the **Namespace** is deleted.
3. Ensure the **Name format** is set to **Unspecified**.
4. Ensure the **Source attribute** is mapped correctly. This varies, and it depends on the specific Azure Active Directory configuration.

![In the form, set the appropriate values for each claim.](https://cdn.sanity.io/images/3do82whm/next/34bbc8cae909e6c55fa2d8498312d3d61644ca5e-1934x830.png)
*In the form, set the appropriate values for each claim.*

Once all claims have been added:

![The mapping of Azure claims and the corresponding Sanity attributes.](https://cdn.sanity.io/images/3do82whm/next/ed5da2bd6c5ab19ac4a5757dc0445b71d89a6c66-1442x360.png)
*The mapping of Azure claims and the corresponding Sanity attributes.*

Sanity requires the `firstName` and `lastName` attributes. The mapping in the example maps both to `user.displayname`.

### Group claims

Enterprise customers can map user identity provider roles to service provider roles. For example, users with an Azure `example-azure-user-role` role are mapped to the Sanity `viewer` role when they log in.

- To support the mapping functionality, you must configure the identity provider to send the groups of the user.
- To do so, Sanity Manage expects a `groups` claim with the format set to `unspecified`. 

> [!WARNING]
> Azure/Entra ID sends the group ID, not the group name. Write your role mapping rules in Sanity against the group ID. If a rule uses the group name, it doesn't match, and users don't get the mapped role when they log in to Sanity.

![Inside Sanity Manage, set Name to groups and Format to unspecified. ](https://cdn.sanity.io/images/3do82whm/next/0c3a9ae47ad308db111a16c3fac735151b03f877-1586x242.png)
*Inside Sanity Manage, set Name to groups and Format to unspecified. *

In Azure, add a new group claim:

![In Azure, select + Add a group claim.](https://cdn.sanity.io/images/3do82whm/next/953a5eef6b8ba38663e52590f96e5ce178dd0447-1662x892.png)
*In Azure, select + Add a group claim.*

Select the groups that you want Azure to send to Sanity, and assign the group claim a descriptive name:

![In Azure, select the groups used to populate SAML tokens issued to Sanity. ](https://cdn.sanity.io/images/3do82whm/next/801b74d77d4b131b52139642e3cc885caa4f2ba7-1116x1794.png)
*In Azure, select the groups used to populate SAML tokens issued to Sanity. *

Once you're done, save the changes.

## Configure the Sanity service provider

### Sign-on URL and issuer

In Azure, browse to the `Set up {application name}` block:

![In Azure, go to the application setup to get the Azure URLs for login and authentication.](https://cdn.sanity.io/images/3do82whm/next/affefac7043ba67bab63f59c21463fe071033937-1538x418.png)
*In Azure, go to the application setup to get the Azure URLs for login and authentication.*

Get the Azure URLs for login and authentication, and add them to the **Your Identity Provider details** configuration section inside Sanity Manage:

![In Your Identity Provider details, set the Azure URLs for login, auth, and logout.](https://cdn.sanity.io/images/3do82whm/next/d4fd95f60ca3e8851ebcb6d41e7ea63114051d57-1700x676.png)
*In Your Identity Provider details, set the Azure URLs for login, auth, and logout.*

In this scenario:

1. Azure **Login URL** maps to Sanity **Identity Provider Single Sign-On URL**.
2. Azure **Azure AD Identifier** maps to Sanity **Identity Provider issuer**.

### InResponseTo

In the SAML specification, `InResponseTo` is defined as:

*The ID of a SAML protocol message in response to which an attesting entity can present the assertion.*

This setting is identity provider-specific, and Azure doesn’t support it. Clear **Enable InResponseTo**.

![Clear Enable InResponseTo.](https://cdn.sanity.io/images/3do82whm/next/9aa6f690939977d61a90f08844af5d57e774ecf5-1546x158.png)
*Clear Enable InResponseTo.*

### Signed SAML Assertion

The **Signed SAML Assertion** option notifies the Sanity instance that the identity provider is configured to use the signing certificate found in the Sanity service provider details section.

![Example certificate in the Signing certificate section.](https://cdn.sanity.io/images/3do82whm/next/6e3b733b9ce4bbd11718196658fcb5693081440a-1580x406.png)
*Example certificate in the Signing certificate section.*

This is an optional step configured in **Verification certificates**:

![Verification certificate is an optional step to configure signing certificates with a signed assertion.](https://cdn.sanity.io/images/3do82whm/next/0e2718c861204ca530273abba9d867413e35688b-1366x196.png)
*Verification certificate is an optional step to configure signing certificates with a signed assertion.*

Unless you have already uploaded the certificate, leave **Want assertion signed** cleared under **Signed SAML Assertion**.

![If no certificate has been uploaded, leave Want assertion signed cleared under Signed SAML Assertion.](https://cdn.sanity.io/images/3do82whm/next/4d1eddac90a89a91e98614b1f098712500ab730f-1578x158.png)
*If no certificate has been uploaded, leave Want assertion signed cleared under Signed SAML Assertion.*

### X.509 certificate

To get an [X.509](https://en.wikipedia.org/wiki/X.509) certificate:

1. Go to **SAML Certificates** and click **Edit**.
2. Download the certificate as **PEM certificate download**.
3. Open the downloaded certificate file with any text editor, and copy-paste the certificate content into Sanity Manage.

![Click Edit in SAML Certificates.](https://cdn.sanity.io/images/3do82whm/next/092c62ea49f0bffe485a58d6cf0e615d4791f93d-1532x766.png)
*Click Edit in SAML Certificates.*

![Select PEM certificate download.](https://cdn.sanity.io/images/3do82whm/next/bf9d54643bb3e2a1bd9aa18d5bffaa9ad7ca2597-1672x702.png)
*Select PEM certificate download.*

![Paste the certificate body into Sanity Manage.](https://cdn.sanity.io/images/3do82whm/next/70d9464b81e02c8c079e6a584a0e1e79afefb635-1612x292.png)
*Paste the certificate body into Sanity Manage.*

## Save

Ensure you save all changes inside Sanity Manage and in Azure.

## Common errors

These errors are specific to Azure/Entra ID. For SSO problems that aren't provider-specific, such as SSO not appearing as a login option in the studio, see the troubleshooting section of [Set up single sign-on with SAML](https://www.sanity.io/docs/developer-guides/sso-saml).

- Receiving a 422 error: `{"statusCode":422,"error":"Unprocessable Entity","message":"child \"attributes\" fails because [\"value\" must contain at least one of ...`- The assertion is missing a required attribute. Make sure the `email`, `firstName`, and `lastName` claims are all present, that you send only one casing of each (for example, `email` or `Email`, not both), and that the assertion includes either a `nameID` or an `id` attribute. For each claim, make sure the **Namespace** is empty and the **Name format** is **Unspecified**.


- My users are being assigned the default role and not their group mapped role- Make sure your role mapping rules in Sanity match the group ID from Azure/Entra ID. Azure/Entra ID sends group IDs, not group names.
- You may need to select **Enable auto update roles on login** in your SAML SSO configuration. When this setting is enabled, Sanity updates a SAML SSO user's roles to match the project's role mappings each time they log in. When it's cleared, changing the role mappings doesn't update the roles of existing users.
- Do you have a [default relay state](https://www.sanity.io/docs/developer-guides/setting-up-a-default-relay-state-for-idp-initiated-saml-logins) set up?


- When I access Sanity from my IdP dashboard, I receive:
`{ "id": "3431pXO", "displayName": "Sanity Support", "email": "sanity@sanity.io", "familyName": "Sanity Support", "givenName": "Sanity", "middleName": null, "imageUrl": null, "provider": "saml-f6a94", "tosAcceptedAt": "2024-11-20T18:51:57.264Z", "createdAt": "2024-11-20T18:51:57.264Z", "updatedAt": "2024-11-20T18:51:57.535Z", "isCurrentUser": true, "providerId": "49jc94jf949930304jkojfciojlj934003490943" }`- Your IdP doesn't have a default relay state, so the IdP-initiated login stops at the Sanity API and returns your user object as JSON. Set the default relay state in your IdP settings to the login URL from Sanity Manage. For the full walkthrough, see the [guide on setting the default relay state](https://www.sanity.io/docs/developer-guides/setting-up-a-default-relay-state-for-idp-initiated-saml-logins).



## Further reading

- [Set up single sign-on with SAML](https://www.sanity.io/docs/developer-guides/sso-saml)
- [Third-Party Login (SSO)](https://www.sanity.io/docs/developer-guides/third-party-login)

