# Dynamics365 - Connection Settings

### Connect using Azure AD

#### 1 - Define an App in Azure and get your oAuth values

Use the values defined in the [Dynamics365 App Registration](/apprules-r-documentation/appendix/miscellaneous/dynamics365-app-registration.md) to get the OAuth client id and secret

#### 2 - Get the OAuth Access Token in appRules

#### 2.1 - Standard oAuth Flow

Use [Getting the oAuth Access and Refresh Tokens](/apprules-r-documentation/appendix/miscellaneous/getting-the-oauth-access-and-refresh-tokens.md)in order to get the proper connection properties

#### 2.2 - Client OAuth Flow

Client credentials refers to a flow in OAuth where there is no direct user authentication taking place. Instead, credentials are created for just the app itself. All tasks taken by the app are done without a default user context. This makes the authentication flow a bit different from standard.

All permissions related to the client oauth flow require admin consent.&#x20;

In your App Registration in portal.azure.com, navigate to API Permissions and select the Microsoft Graph permissions. There are two distinct sets of permissions - Delegated and Application permissions. The permissions used during client credential authentication are under Application Permissions. Select the applicable permissions you require for your integration.

In addition to setting the standard OAuth client id and secret, to use client credentials you must also set the following connection properties:

* OAuthGrantType: Set this to CLIENT.
* AzureTenant: Set this to the tenant you wish to connect to.

&#x20;When you authenticate using client credentials, there is no Web flow. Authentication with client credentials will take place automatically like any other connection, except there will be no window opened prompting the user. Because there is no user context, there is no need for a browser popup. Connections will take place and be handled internally.

### Connect using MSI Authentication

If you are running the source on an Azure VM, you can leverage Managed Service Identity (MSI) credentials to connect:

* AuthScheme: Set this to **AzureMSI**.

The MSI credentials will then be automatically obtained for authentication.


---

# 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.appstrategy.com/apprules-r-documentation/appendix/miscellaneous/oauth-authentication-azure-definition.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.
