Registering an app in Azure AD

This post describes:

  1. Registering an OAuth2 app in Azure AD to control access to the app (the Web API of Dynamics 365 / Dataverse in this case)
  2. Creating an non-interactive application user in Dynamics 365
  3. Developing an Azure Function to connect to Dynamics 365

Assumption:

The Azure & Dynamics 365 subscriptions belong to the one account

Registering an app in Azure AD

Click on ‘App Registrations’ & then ‘New registration’

Click on ‘View API permissions’

Select ‘Dynamics 365’

Creating an application user in Dynamics 365

Select the ‘Application Users’ view

Enter the Application Id which was generated earlier

Select the required role (not System Administrator as this would be a security risk)

Developing an Azure Function to connect to Dynamics 365

This function connects to Dynamics 365 via Azure AD

Azure Function example

Consider the example described in the blog post XRM.Navigation.navigateTo() launching a html web resource

To meet the requirements of this example, an Azure function could be built to implement the following functionality:

1.) When the ‘Generate Token’ button is pressed on the command bar of a form, the Azure function is called with it’s URL query parameters containing the credit card name, number etc

2.) Within the Azure function, a connection is made to Dynamics 365 / Dataverse and the merchant details are retrieved from a table within Dataverse

3.) Within the Azure function, a call is made to the payment gateway with the required details and a token (used to make payments) is returned by the payment gateway

4.) The Azure function triggers a Power Automate flow to write a transaction log message to Dynamics 365

References

OAuth Application Users in Dynamics 365