# Setup Azure Active Directory

In this article you'll read how to setup user authentication via Azure Active Directory. Configuring this correctly consists of the following steps:

* [Registering an application within the Azure Portal.](#registering-an-application-within-the-azure-portal)
* [Obtaining the Client ID and Tenant ID.](#obtaining-the-client-id-and-tenant-id)
* [Creating a Client Secret within the Azure app.](#creating-a-client-secret-within-the-azure-app)
* [Enabling Azure Active Directory authentication in AppMachine.](#enabling-azure-active-directory-authentication-in-appmachine)

### Registering an application within the Azure Portal

1. **Navigate** to the [registered apps page of the Azure Portal](https://portal.azure.com/#view/Microsoft_AAD_IAM/ActiveDirectoryMenuBlade/~/RegisteredApps) and login.
2. **Click +New registration** to create a new app.<br>

   <figure><img src="https://2636455530-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2wzy1sO41plYrfJfaAhN%2Fuploads%2Fk2LWBYfYmcya1Gnfk7FE%2FPasted_Image_21_02_2023__13_59.png?alt=media&#x26;token=4282dd6e-d32a-4544-a557-ba2d6f49a470" alt=""><figcaption><p>Azure Portal - App registrations</p></figcaption></figure>
3. **Enter the name** of your app.
4. **Select** the **Single tenant** option as the supported account type.
5. **Set the Redirect URI** to type **Web** and enter the following **value**: \
   &#x20;`https://app-services.cmsappbuilder.com/api/application-users/v1/social/callback/microsoft`
6. **Click Register** to create the Azure application.<br>

   <figure><img src="https://2636455530-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2wzy1sO41plYrfJfaAhN%2Fuploads%2FUfMZXucsucjRw2HdgvKp%2Fimage__3_.png?alt=media&#x26;token=2cbd2da5-92d6-4423-b533-27ce279cb070" alt=""><figcaption><p>Azure Portal - Register application </p></figcaption></figure>

### Obtaining the Client ID and Tenant ID

7. **Open** the **Overview page** of your Azure application.
8. **Copy** the **Application (client) ID** and the **Directory (tenant) ID**. These values will be required during the setup in AppMachine.\
   &#x20;

   <figure><img src="https://2636455530-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2wzy1sO41plYrfJfaAhN%2Fuploads%2FzLFRxtEozR9x1j9eQbFX%2FPasted_Image_21_02_2023__14_25.png?alt=media&#x26;token=59a0917a-cf4b-41c1-88ec-222c1b86a5f9" alt=""><figcaption><p>Azure Portal - App overview</p></figcaption></figure>

### Creating a Client Secret within the Azure app

9. **Open** the **Certificates & secrets** page.

10. **Click +New client secret**.<br>

    <figure><img src="https://2636455530-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2wzy1sO41plYrfJfaAhN%2Fuploads%2F1JZ0wqNYDL6ze7qsAr4y%2Fimage__4_.png?alt=media&#x26;token=2ba49db4-e8e6-41c6-bdba-328420786dc3" alt=""><figcaption><p>Azure Portal - Certificates &#x26; secrets</p></figcaption></figure>

11. **Enter** a **description** and **set** the client secret's **expiration** time.\
    \
    \&#xNAN;***Note:** AppMachine is not able to track the client secret expiration date. When the client secret expires users will no longer be able to login to the app. To prevent this from happening, the client secret will have to be renewed and updated in AppMachine before the secret expires.* <br>

    <figure><img src="https://2636455530-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2wzy1sO41plYrfJfaAhN%2Fuploads%2FlyDIAD67jYQMLYjSOe4Z%2Fimage__5_.png?alt=media&#x26;token=c8fb389d-963c-4274-8fe3-84d03237edd7" alt=""><figcaption><p>Azure Portal - Add a client secret</p></figcaption></figure>

12. **Click** the **Add** button to create the client secret.

13. **Copy** the **value** of the client secret displayed on the screen. This value will be required during the setup in AppMachine.\
    \
    \&#xNAN;***Note:** The Client Secret value can only be viewed once, directly after creating it.*

### Enabling Azure Active Directory authentication in AppMachine

14. **Open** the [**Login Settings**](https://app-home.appmachine.com/user-access/authentication) page of your AppMachine app and **enable User login**.

15. **Enable** the options **Azure Active Directory** and **Users can register a new account for this app**.<br>

    <figure><img src="https://2636455530-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2wzy1sO41plYrfJfaAhN%2Fuploads%2FL2So4k52AgrJXlUhPkVk%2FPasted_Image_21_02_2023__16_01.png?alt=media&#x26;token=46026a50-0046-413d-94f0-53d2925f2ee7" alt=""><figcaption><p>AppMachine - Login Settings</p></figcaption></figure>

16. **Click Configure** and **enter the Client ID, Tenant ID, and Client Secret** obtained via the steps above, and click Save to complete the setup.<br>

    <figure><img src="https://2636455530-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2wzy1sO41plYrfJfaAhN%2Fuploads%2FJTrI7C3J8uNMtfkXGSIC%2Fimage.png?alt=media&#x26;token=8aaf7660-7892-413f-816d-d104d6812e30" alt=""><figcaption><p>AppMachine - Configure Azure Active Directory</p></figcaption></figure>

17. Finally, **Save your changes on the Login Settings page** to complete the setup.
