# Azure Active Directory Integration

VirtualMetric supports Azure Active Directory authentication for user authentications.

You can allow access to your Azure Active Directory users by configuring "**App Registration**" in your Azure Active Directory, and enabling **azureStatus** in your `web.config` file.

1\. First, navigate to the `ControlPanel` directory and open `web.config`:

```
C:\Program Files\VirtualMetric\ControlPanel\Web.config
```

2\. Find `azureStatus` in the `appSettings` section and change it as `true`, and restart the **VirtualMetric API** from **IIS Manager**:

```
    <appSettings>
    <add key="primaryApiUrl" value="https://api.virtualmetric.com/API/" />
    <add key="failoverApiUrl" value="" />
    <add key="triggerId" value="3080487f-f3f6-43e2-bd27-7f1886a12816" />
    <add key="apiUser" value="vmapi" />
    <add key="apiPassword" value="727c9b3a51eb3407c7cc21c45d84bb28" />
    <add key="azureStatus" value="true" />
    </appSettings>
```

3\. After enabling `azureStatus`, you will see the **Sign in with Microsoft** button on the logon screen:

<div align="center"><figure><img src="https://3741708824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbhbshAPk7P4wdrLxisUn%2Fuploads%2F42mw2XxdRjoF6Sist565%2Fimage.png?alt=media&#x26;token=23529538-b586-43a9-80be-6792c3ab1912" alt=""><figcaption></figcaption></figure></div>

4\. Now you need to register the application in **Azure Portal**. You can follow the steps below to create an application registration.

5\. Click on **Microsoft Entra ID**

<div align="center"><figure><img src="https://3741708824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbhbshAPk7P4wdrLxisUn%2Fuploads%2Fi1ujsoJAtd3EWJq63JvR%2Fimage.png?alt=media&#x26;token=0c9a1f27-987d-46cb-9827-e4c2fb7163f7" alt=""><figcaption></figcaption></figure></div>

6\. Navigate to **App Registrations** and click the **New Registration** button.

<div align="center"><figure><img src="https://3741708824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbhbshAPk7P4wdrLxisUn%2Fuploads%2FX3azoHbbKW0go2pabRhM%2Fimage.png?alt=media&#x26;token=5f431631-5199-49ea-8523-9a36a0e783ae" alt=""><figcaption></figcaption></figure></div>

7\. Type your application name and select an account type. You need to type VirtualMetric API's address for **Redirect URI**. Complete the registration by clicking the **Register** button.

<div align="center"><figure><img src="https://3741708824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbhbshAPk7P4wdrLxisUn%2Fuploads%2FYDq5GltwbIFMGffe6Hz5%2Fimage.png?alt=media&#x26;token=9c46359f-7c4d-4500-b072-d6e6d735f21d" alt=""><figcaption></figcaption></figure></div>

{% hint style="info" %}
Please make sure to enable SSL on VirtualMetric API, and use an HTTPS FQDN in the **RedirectURI Parameter**. You can check the [Setup SSL Certificate on VirtualMetric](https://docs.virtualmetric.com/installation/maintenance#setup-ssl-certificate) section to learn how to activate SSL.
{% endhint %}

8\. After registering the application, enable **Access Token** and **ID Token** grants under the **Authentication** options.

<div align="center"><figure><img src="https://3741708824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbhbshAPk7P4wdrLxisUn%2Fuploads%2FDLe4eURWFUXSTmgrFRc9%2Fimage.png?alt=media&#x26;token=55c598d6-c6a8-48f2-8ef8-1f3ee324f7b5" alt=""><figcaption></figcaption></figure></div>

9\. Add an optional email claim under **token configuration**.

<div align="center"><figure><img src="https://3741708824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbhbshAPk7P4wdrLxisUn%2Fuploads%2Fy6Vzovb8D4ic7lMmyiq3%2Fimage.png?alt=media&#x26;token=a10b8845-78ad-4a42-911d-4ede4351aee0" alt=""><figcaption></figcaption></figure></div>

10\. Add your role configuration under the `appRoles` section, and save the manifest file.

<div align="center"><figure><img src="https://3741708824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbhbshAPk7P4wdrLxisUn%2Fuploads%2FYIe1gbqRuHF4SMIuYfFD%2FAzureADManifestRoleBased.png?alt=media&#x26;token=aefd3652-e971-44d6-aa93-819f0d9cbf7a" alt=""><figcaption></figcaption></figure></div>

The completed configuration should look like this:

```json
"appRoles": [
	{
		"allowedMemberTypes": [
			"User"
		],
		"description": "Users with readonly access",
		"displayName": "VirtualMetricUserRole",
		"id": "18d14569-c3bd-439b-9a66-3a2aee01d14c",
		"isEnabled": true,
		"lang": null,
		"origin": "Application",
		"value": "VirtualMetricUserRole"
	},
	{
		"allowedMemberTypes": [
			"User"
		],
		"description": "Users with admin access",
		"displayName": "VirtualMetricAdminRole",
		"id": "18d14569-c3bd-439b-9a66-3a2aee01d14f",
		"isEnabled": true,
		"lang": null,
		"origin": "Application",
		"value": "VirtualMetricAdminRole"
	},
	{
		"allowedMemberTypes": [
			"User"
		],
		"description": "msiam_access",
		"displayName": "msiam_access",
		"id": "b9632174-c057-4f7e-951b-be3adc52bfe6",
		"isEnabled": true,
		"lang": null,
		"origin": "Application",
		"value": null
	}
],

```

11\. Note the **Application (client) ID**, **Directory (tenant) ID**, and **RedirectURI** parameters. You will update the appropriate fields in **Advanced Settings**.

<div align="center"><figure><img src="https://3741708824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbhbshAPk7P4wdrLxisUn%2Fuploads%2FEHe0JtoLBLMWGQmn0ewR%2Fimage.png?alt=media&#x26;token=391b0d64-a062-4894-b8fc-efcfb4c66ff6" alt=""><figcaption></figcaption></figure></div>

12\. In **Advanced Settings**, search for **Azure** and you will see the **Azure Active Directory** settings. Set **Azure Active Directory Client ID**, **Azure Active Directory Tenant ID**, and **Azure Active Directory Redirect Uri** variables as per the table below.

| Advanced Settings Title             | Mapping Title           |
| ----------------------------------- | ----------------------- |
| Azure Active Directory Client ID    | Application (client) ID |
| Azure Active Directory Tenant ID    | Directory (tenant) ID   |
| Azure Active Directory Redirect Uri | RedirectURI             |

{% hint style="info" %}
When a user wants to authenticate via **Azure Active Directory**, VirtualMetric looks for their email address. If the AzureAD user and the VirtualMetric user has the same email address, the user will be authenticated automatically. See the [Adding New User to VirtualMetric](https://docs.virtualmetric.com/settings/users/user-operations) section for further details.
{% endhint %}

{% hint style="info" %}
**Visibility of Azure Active Directory Elements** should be **Active**
{% endhint %}

<div align="center"><figure><img src="https://3741708824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbhbshAPk7P4wdrLxisUn%2Fuploads%2F9twMcjMQCSW3nOSao1SQ%2Fimage.png?alt=media&#x26;token=c8a351c2-b8cf-49dd-8ae2-6e53b283f702" alt=""><figcaption></figcaption></figure></div>

{% hint style="warning" %}
After setting the parameters, you should reset **IIS** with **iisreset** on the dashboard servers.
{% endhint %}

13\. Create the user groups for VirtualMetric under **Microsoft Azure -> User Groups**.

<div align="center"><figure><img src="https://3741708824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbhbshAPk7P4wdrLxisUn%2Fuploads%2FXuE085kncrdR3k1LHOM8%2Fimage.png?alt=media&#x26;token=90e19f9f-a7a2-46c4-83dd-d1e8e5cd214f" alt=""><figcaption></figcaption></figure></div>

14\. Add the roles you have written to the manifest file.

<div align="center"><figure><img src="https://3741708824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbhbshAPk7P4wdrLxisUn%2Fuploads%2Fgwx3QAaN2tkdKnP2V23O%2Fimage.png?alt=media&#x26;token=03242ff3-7497-4a9d-bff7-c41bb94118b6" alt=""><figcaption></figcaption></figure></div>

15\. Now go back to **Azure** and click on **Enterprise Applications**.

<div align="center"><figure><img src="https://3741708824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbhbshAPk7P4wdrLxisUn%2Fuploads%2FQ3CI3W4FjkqZePx9WAjl%2Fimage.png?alt=media&#x26;token=d7880140-f622-40c1-92f0-303ff639eacd" alt=""><figcaption></figcaption></figure></div>

15\. Under **All Applications**, search for and click on the application related to VirtualMetric.

<div align="center"><figure><img src="https://3741708824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbhbshAPk7P4wdrLxisUn%2Fuploads%2FzAPwv7ZbyEyymN9w8bPJ%2Fimage.png?alt=media&#x26;token=af10a38e-5406-4438-92f3-93ba3fe2e86b" alt=""><figcaption></figcaption></figure></div>

16\. Now you can add a user to the group and test it.

<div align="center"><figure><img src="https://3741708824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbhbshAPk7P4wdrLxisUn%2Fuploads%2FCDQ6XODYEz6rfnq9IYSZ%2Fimage.png?alt=media&#x26;token=5d1178d5-c9be-41c4-ae76-54dc691e1c6a" alt=""><figcaption></figcaption></figure></div>

16\. Add your user and role, and then click on **assign**.

<div align="center"><figure><img src="https://3741708824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbhbshAPk7P4wdrLxisUn%2Fuploads%2F2hNU71hg5DHPylWPYQI5%2Fimage.png?alt=media&#x26;token=31a86733-f5eb-4928-9fc6-664250389da3" alt=""><figcaption></figcaption></figure></div>

17\. Now you can navigate to the **Logon Screen** to test your Azure Active Directory authentication. Click the **"Sign in with Microsoft"** button to redirect to the Azure Active Directory authentication page.

<div align="center"><figure><img src="https://3741708824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbhbshAPk7P4wdrLxisUn%2Fuploads%2FMCmM4OKYLX73fK5JxOxW%2FAzureAppRegistration06.png?alt=media&#x26;token=e26d18a8-6c9f-4d60-a718-e205e6eb1949" alt=""><figcaption></figcaption></figure></div>

18\. On your first login, you can grant access and start a VirtualMetric session.

<div align="center"><figure><img src="https://3741708824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbhbshAPk7P4wdrLxisUn%2Fuploads%2FDlypNkG7hAq9lJkepLwT%2Fimage.png?alt=media&#x26;token=d32ed072-b88b-45b4-9dfd-801a3bfa1b8b" alt=""><figcaption></figcaption></figure></div>

19\. Under the **Microsoft Azure -> User** section, you can see the users created with Azure.

<div align="center"><figure><img src="https://3741708824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbhbshAPk7P4wdrLxisUn%2Fuploads%2FNbIriNAyNCoS6dEp8JQU%2Fimage.png?alt=media&#x26;token=b1cbe629-99de-4e7c-84ba-de54fc32eaef" alt=""><figcaption></figcaption></figure></div>
