> For the complete documentation index, see [llms.txt](https://docs.cubu.com/guides/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.cubu.com/guides/technical-guide/advanced-configuration/configuring-single-sign-on-sso/configuring-sso-with-azure-ad.md).

# Configuring SSO with Azure AD

## Azure Configuration <a href="#getting-started" id="getting-started"></a>

### Getting Started <a href="#getting-started" id="getting-started"></a>

Create a new Azure tenant for your organization and sign into the [Azure active directory portal](https://portal.azure.com/#view/Microsoft_AAD_IAM/ActiveDirectoryMenuBlade/~/Overview).

### Add an App Registration. <a href="#add-an-app-registration" id="add-an-app-registration"></a>

This application registration will be a stand-in for the cubu application and handle both the client-side SPA login flow and API access management.

1. Go to **Manage > App registrations** blade in the Azure AD portal and click the **New Registration** button.<br>

   <div align="left"><figure><img src="https://828786245-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFaQmpl3dnlIuuQovEhR8%2Fuploads%2FAbpdu4UPJUl3HVIyjief%2Fimage.png?alt=media&amp;token=69b73b86-8018-488e-b133-365a85566ab3" alt="" width="375"><figcaption></figcaption></figure></div>
2. In the **Register an application** page, give the application an easy-to-recognize name (this guide will use **cubu** as the name in further references), select **Accounts in this organizational directory only (Single tenant)** in the **Supported account types** section, and leave the **Redirect URI** section empty since we’ll handle this part later.

   &#x20;

   <div align="left"><figure><img src="https://828786245-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFaQmpl3dnlIuuQovEhR8%2Fuploads%2FW4Jj24SBQAHEg60J8pkJ%2Fimage.png?alt=media&amp;token=2880dd01-7b84-4b87-9d05-bab38bb4cca1" alt="" width="375"><figcaption></figcaption></figure></div>
3. Write down the **Application (client) ID** and **Directory (tenant) ID** for the newly created app. Those will be used later to configure SSO in your cubu organization.<br>

   <div align="left"><figure><img src="https://828786245-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFaQmpl3dnlIuuQovEhR8%2Fuploads%2FxZO5Boa6UiivAgJKgLDM%2Fimage.png?alt=media&amp;token=2eb771c6-1e65-4b45-8466-c4d9fa091e60" alt="" width="375"><figcaption></figcaption></figure></div>
4. Switch to the **Manage > Authentication** blade and click the **Add a platform** button.
   * In the newly opened panel select **Single-page application** and fill in the following values:
     * Redirect URIs: **<https://YOUR\\_ORG\\_SUBDOMAIN.app.cubu.com>**
     * Front-channel logout URL: **<https://YOUR\\_ORG\\_SUBDOMAIN.app.cubu.com/logout>**<br>

       <div align="left"><figure><img src="https://828786245-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFaQmpl3dnlIuuQovEhR8%2Fuploads%2FNeqLofFmtiubny1QDTAO%2Fimage.png?alt=media&amp;token=464f8987-06b5-4002-9f63-cc2f345de4dd" alt="" width="293"><figcaption></figcaption></figure></div>
5. Switch to the **Manage > Expose an API** blade to configure the authorization settings.
   * Click on the **Set** button near the **Application ID URI** leaving the default ID provided by azure. Write down this uri since it will later be used to configure SSO in cubu.
   * Click on the **Add a scope** button to create a default scope for the cubu application.
     * In the **Add a scope** panel, name the scope **cubu\_user**.
     * The consent fields are required but you’re free to fill them in with anything you like.\
       &#x20;

       <div align="left"><figure><img src="https://828786245-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFaQmpl3dnlIuuQovEhR8%2Fuploads%2FZ39a2UtNIPjwsIPySy7O%2Fimage.png?alt=media&amp;token=636237b9-f288-4749-86f5-12119e7ade09" alt="" width="293"><figcaption></figcaption></figure></div>
6. Cubu uses the access token email during a new user’s creation. To add the email claim to the access token Switch to the **Manage > Token configuration** blade and click the **Add optional claim** button.
   * In the opened panel select the **Access** token type and check the **email** claim.<br>

     <div align="left"><figure><img src="https://828786245-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFaQmpl3dnlIuuQovEhR8%2Fuploads%2FYOTRiMluYRknm7wYHwhm%2Fimage.png?alt=media&amp;token=bf5f0a9c-c32b-4f9b-b6e7-4e49978bd282" alt="" width="293"><figcaption></figcaption></figure></div>
7. Switch to the **Manage > API permissions** blade to add openid and api permissions to the application.
   * Click the **Add a permission** button.
     * In the opened panel, select the **Microsoft APIs** tab, click on **Microsoft Graph**, select **Delegated permissions**, and check the **email**, **openid**, and **profile** scopes under the **OpenId permissions** category.<br>

       <div align="left"><figure><img src="https://828786245-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFaQmpl3dnlIuuQovEhR8%2Fuploads%2F2uERTUE668fsx5R0EAYS%2Fimage.png?alt=media&amp;token=09f11f46-32d6-4433-8bf4-1e40c9e5c0ce" alt="" width="375"><figcaption></figcaption></figure></div>
   * Click on the **Add a Permission** button again.

     * Select the **APIs My Organization Uses** tab in the opened panel and pick the **cubu** API from the list.<br>

     <div align="left"><figure><img src="https://828786245-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFaQmpl3dnlIuuQovEhR8%2Fuploads%2FT8cVjEC9wu2C1tCaynhh%2Fimage.png?alt=media&amp;token=8ead7666-d624-44e6-bd7a-2ed03e0d0757" alt="" width="375"><figcaption></figcaption></figure></div>
   * Select the **Delegated permissions** type. Ensure the **cubu\_user** scope is checked and click the **Add permission** button to save.<br>

     &#x20;

     <div align="left"><figure><img src="https://828786245-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFaQmpl3dnlIuuQovEhR8%2Fuploads%2Fvf3Re3QnqQyYR7X9taMH%2Fimage.png?alt=media&amp;token=9e0c4c8c-8c5c-4f4a-a4ba-55e99a9a3087" alt="" width="375"><figcaption></figcaption></figure></div>
   * After all of the permissions have been added, you can click on the **Grant admin consent for YOUR\_TENANT** button to skip the user consent page for users.\
     &#x20;

     <div align="left"><figure><img src="https://828786245-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFaQmpl3dnlIuuQovEhR8%2Fuploads%2FBkxgWq8wOaiCwcHydFqW%2Fimage.png?alt=media&amp;token=3cb81747-2ccc-4dfd-90e8-ef4a3d715e38" alt="" width="375"><figcaption></figcaption></figure></div>
8. Cubu relies on having the user’s email claim in the access token for user creation.\
   Switch to the **Manage > Token configuration** blade and click the **Add optional claim** button.
   * In the **Add optional claim** panel, select the **Access** token type and check the **email** claim.<br>

     <div align="left"><figure><img src="https://828786245-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFaQmpl3dnlIuuQovEhR8%2Fuploads%2F89KtWRDqsHiOkafLEtVE%2Fimage.png?alt=media&amp;token=753ed1c2-342e-4fbb-ab76-d8b7db522d6e" alt="" width="293"><figcaption></figcaption></figure></div>
9. Finally, switch to the **Manage > Manifest** blade and make sure that the **accessTokenAcceptedVersion** is set to **2**<br>

   &#x20;

   <div align="left"><figure><img src="https://828786245-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFaQmpl3dnlIuuQovEhR8%2Fuploads%2FGk0ZqTgqXhJcmfge5VoG%2Fimage.png?alt=media&amp;token=ca6546e9-e04d-4f2e-a4ea-d40353e1ff19" alt="" width="375"><figcaption></figcaption></figure></div>

## Configuring Cubu to Use SSO <a href="#configuring-your-organization-in-cubu-to-use-your-auth0-provider" id="configuring-your-organization-in-cubu-to-use-your-auth0-provider"></a>

* Log in to your organization in cubu with the user that created the organization in cubu (organization owner) and navigate to the **SSO** page of the **Settings** tool in the **Admin tools** toolbelt.\ <br>

  <div align="left"><figure><img src="https://828786245-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFaQmpl3dnlIuuQovEhR8%2Fuploads%2FXa7gyLepFTr8DVkq6oBE%2Fimage.png?alt=media&amp;token=583bfbbc-13ec-45c5-ac03-f78ecf71d0b1" alt="" width="375"><figcaption></figcaption></figure></div>
* Click the **Enable SSO** button and enter your auth provider’s information in the Enable SSO dialog in the following way:
  * Identity service provider (ISP): **Azure Active Directory**
  * Authority: [**https://login.microsoftonline.com/YOUR\_DIRECTORY\_ID/v2.0**](https://login.microsoftonline.com/YOUR_DIRECTORY_ID/v2.0)
    * Replace **YOUR\_DIRECTORY\_ID** with the **Directory (Tenant) ID** from the **cubu** app registration
  * Audience: The **cubu** app registration’s **Application (Client) Id**
    * Or the **Application ID URI** from the **Expost an API blade** if you used a custom domain instead of the default api://GUID URL.
  * Client id: The **cubu** app registration’s **Application (Client) Id**
  * Organization owner email: The email of the organization user in your auth0 tenant that will be associated with the current application owner user’s cubu account.\ <br>

    <div align="left"><figure><img src="https://828786245-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFaQmpl3dnlIuuQovEhR8%2Fuploads%2FWlGqk6lszkPoYok5ACtb%2Fimage.png?alt=media&amp;token=125013ae-aaba-4ace-9c35-067bcae982f7" alt="" width="301"><figcaption></figcaption></figure></div>
* After clicking Enable SSO in the dialog, the page should refresh, prompting you to log in.

&#x20;
