# Azure AD (OAuth) with Squidex

[Azure AD](https://azure.microsoft.com/en-us/products/active-directory) is a fully-managed Cloud-based identity service from Microsoft providing SSO, MFA and conditional access, amongst many other features.&#x20;

Azure AD provides lots of authentication mechanisms such as OAuth, OIDC and Graph etc. This article uses the plain OAuth method. It shows you how to use Azure AD as an identity provider with a **self-hosted Squidex installation**. Azure AD provides authentication and authorization to users in the Azure AD tenant for your App.

{% hint style="info" %}
A basic understanding of Azure AD is highly recommended as the article does not explain what Azure AD is and how it works. Microsoft Learn has excellent [documentation](https://learn.microsoft.com/en-us/azure/active-directory/) for this.
{% endhint %}

## Prerequisites

These prerequisites should be in place to successfully follow this article:

* An Azure Active Directory tenant (FREE tier will work).
  * It is assumed that the Azure AD has a domain associated with it, e.g. *example.com*.
* An installation of Squidex. See [instructions](https://docs.squidex.io/id-01-getting-started/installation) available for various platforms.

{% hint style="info" %}
An Azure subscription is NOT required for this setup
{% endhint %}

## Azure AD Configuration

### Register an Azure AD App

During this step, you will register an application with Azure AD and gather a few details that will be required to configure Squidex.

1. Start by navigating to <https://portal.azure.com>.
2. In the top search box, type **Active Directory** (1) and select **Azure Active Directory** (2) from the list.

   <figure><img src="https://2730255609-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LrL94QfeasZ0wF6YAvB%2Fuploads%2FhWLEIB1DZh4MyKtzZWoU%2F2023-01-11_01-41.png?alt=media&#x26;token=a950b72e-420c-465d-8cc8-1e124b643cce" alt=""><figcaption><p>Navigate to Azure Active Directory</p></figcaption></figure>
3. On the Azure AD page, select **App registrations** (3) from the left blade and then click **+ New registration** (4).

   <figure><img src="https://2730255609-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LrL94QfeasZ0wF6YAvB%2Fuploads%2FW2SuDn9HW0CfUdetoR1l%2F2023-01-11_01-44.png?alt=media&#x26;token=a0a8578d-c453-4af3-9798-80665839982b" alt=""><figcaption><p>Start registration of a new app</p></figcaption></figure>
4. On the *Register an application* screen enter a **Name** (5) for the App, select **Accounts in this organizational directory only** (6).\
   Under the **Redirect URI (optional)** section, set the following values:

   1. Choose **Web** (7) from the drop down
   2. Then enter your Squidex domain URL followed by `/signin-microsoft`.\
      The URI must have `/signin-microsoft` else it will fail.

   Click **Register** (8) when done.

   <figure><img src="https://2730255609-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LrL94QfeasZ0wF6YAvB%2Fuploads%2FmLWO1gv0ziPR1u4EdLVf%2F2023-01-13_01-26.png?alt=media&#x26;token=193fb84a-63b7-430f-81f7-6f34a535cc9c" alt=""><figcaption><p>Register an app</p></figcaption></figure>
5. In the Azure AD app details page, copy the **Application (client) ID** (9) and **Directory (tenant) ID** (10) values as they will be needed later.

   <figure><img src="https://2730255609-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LrL94QfeasZ0wF6YAvB%2Fuploads%2FyGaeokdy4hBmEVoI3tx4%2F2023-01-13_01-35.png?alt=media&#x26;token=8a17ac6b-ce29-4057-918c-80276fec0188" alt=""><figcaption><p>Note down App ID and Tenant ID</p></figcaption></figure>
6. Select **Certificates & Secrets** (11) from the left, next click **+ New client secret** \
   (12). Give a **Description** (13) for the secret and click **Add** (14).

   <figure><img src="https://2730255609-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LrL94QfeasZ0wF6YAvB%2Fuploads%2FZPFGdLI4bREdBGWpHJGT%2F2023-01-13_01-38.png?alt=media&#x26;token=86510778-abed-40be-addf-b8c7271304bc" alt=""><figcaption><p>Generate client secret</p></figcaption></figure>
7. Copy the secret **Value** (15) shown in this step.

   <figure><img src="https://2730255609-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LrL94QfeasZ0wF6YAvB%2Fuploads%2FDBmtyrSbj72RNk8qv2d9%2F2023-01-13_01-53.png?alt=media&#x26;token=086c7f92-8de6-4efb-8e6e-95d66e09ed60" alt=""><figcaption><p>Note down client secret value</p></figcaption></figure>
8. Finally click on **Authentication** (16), check **ID tokens** (17) and click **Save** (18).

   <div align="left"><figure><img src="https://2730255609-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LrL94QfeasZ0wF6YAvB%2Fuploads%2FhJeGGQtR52AzGadxbsPG%2F2023-01-13_02-52.png?alt=media&#x26;token=2391d451-8c0d-4e15-afd5-d18788bf2079" alt=""><figcaption><p>Enable ID token</p></figcaption></figure></div>

## Configure Squidex for Azure AD&#x20;

In the next set of steps you will configure Squidex to use Azure AD. Depending on how Squidex is installed / running the steps to add these values will be different and unfortunately we cannot cover everything but in a nutshell, you want the following variables configured with the values collected earlier.&#x20;

When the values are `null`, Microsoft authentication is disabled.

| Variable                    | Description             |
| --------------------------- | ----------------------- |
| `IDENTITY__MICROSOFTCLIENT` | Application (client) ID |
| `IDENTITY__MICROSOFTSECRET` | Client Secret Value     |
| `IDENTITY__MICROSOFTTENANT` | Directory (tenant) ID   |

### Kubernetes / Helm Example

For example, if using Kubernetes Helm charts, these variables should be updated with the values in the `values.yaml` file.

<div align="left"><figure><img src="https://2730255609-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LrL94QfeasZ0wF6YAvB%2Fuploads%2FQ99ORasS18sBvcJIuGPh%2F2023-01-13_19-03.png?alt=media&#x26;token=cb827fdb-56e7-4efd-992b-87856dd9bebe" alt=""><figcaption><p>Sample helm values.yaml configuration for enabling Microsoft authentication </p></figcaption></figure></div>

### Azure App Service Example

Similarly, if Squidex is running on an Azure App Service, they are added to the *Configuration* of the app service. An example is provided below.

<div align="left"><figure><img src="https://2730255609-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LrL94QfeasZ0wF6YAvB%2Fuploads%2FUwr7ptPsezdVbhWltj9y%2F2023-01-13_18-50.png?alt=media&#x26;token=9e8b2e1e-7cf5-40f8-ad18-5efe102328d5" alt=""><figcaption><p>Sample app service configuration for enabling Microsoft authentication </p></figcaption></figure></div>

### Docker Example

When running it using Docker Compose (or Docker) they are updated in a `.env` file that is used by the `docker-compose.yml` file or you can update the values directly in the `docker-compose.yml` file itself (not recommended).&#x20;

The rest of the steps here refer to a Docker based containerized installation that uses the code/resources provided at <https://github.com/Squidex/squidex-hosting/tree/master/docker-compose>  and uses a `.env` file.

1. In the `.env` file set the values. Note that these variables are only used in the context of Docker, they are referenced by the actual variables in the `docker-compose.yml` file.\
   \
   A sample screenshot is provided below.

   <figure><img src="https://2730255609-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LrL94QfeasZ0wF6YAvB%2Fuploads%2FhYLYz0sjSbkDmtAA0Icm%2F2023-01-13_02-15.png?alt=media&#x26;token=99f3d9f9-e1bc-45c6-86c1-42d7c235c732" alt=""><figcaption><p>Sample docker environment values for enabling Microsoft authentication </p></figcaption></figure>
2. Next update the Squidex container by recreating it. Run the following command to do so:\
   \
   `docker-compose up -d --force-recreate squidex_squidex`\
   \
   `squidex_squidex` is the default name of the container if you are running the `docker-compose.yml` file provided by us.&#x20;

## Test the Configuration

1. Reload the Squidex page and click **Login to Squidex**.
2. You should see a **Login with Microsoft** button. In the Signup section, you can also **Signup with Microsoft**.

   <div align="left"><figure><img src="https://2730255609-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LrL94QfeasZ0wF6YAvB%2Fuploads%2FgB05LwXn50uCPJNqKZk0%2F2023-01-13_02-25.png?alt=media&#x26;token=72ba6ade-202a-4776-bc9f-5dbf0834b405" alt=""><figcaption><p>Signin with Microsoft</p></figcaption></figure> <figure><img src="https://2730255609-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LrL94QfeasZ0wF6YAvB%2Fuploads%2FcXiXwGF09JMVWC1min3K%2F2023-01-13_02-38.png?alt=media&#x26;token=8b83a956-9c33-4831-b797-cefa187769f6" alt=""><figcaption><p>Signup with Microsoft</p></figcaption></figure></div>
3. On the next screen, enter a username and password from the Azure AD tenant.
4. When prompted for permissions, click **Accept**.

   <div align="left"><figure><img src="https://2730255609-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LrL94QfeasZ0wF6YAvB%2Fuploads%2F7SfjcPQUagTHVFZdMqzM%2F2023-01-13_02-33.png?alt=media&#x26;token=1b14fabb-9671-4be1-9fd1-57b877f7ff75" alt=""><figcaption><p>Accept permissions</p></figcaption></figure></div>
5. You should be now be able to Signup or Login with a Microsoft account from the configured Azure AD tenant using OAuth.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.squidex.io/id-01-getting-started/installation/external-identity-providers/azure-ad-oauth-with-squidex.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
