Registering an app in Azure AD
This post describes:
- Registering an OAuth2 app in Azure AD to control access to the app (the Web API of Dynamics 365 / Dataverse in this case)
- Creating an non-interactive application user in Dynamics 365
- 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’
![](https://dustinminer.com/wp-content/uploads/2022/08/1.png)
![](https://dustinminer.com/wp-content/uploads/2022/08/2.png)
Click on ‘View API permissions’
![](https://dustinminer.com/wp-content/uploads/2022/08/3.png)
![](https://dustinminer.com/wp-content/uploads/2022/08/4.png)
Select ‘Dynamics 365’
![](https://dustinminer.com/wp-content/uploads/2022/08/5.png)
![](https://dustinminer.com/wp-content/uploads/2022/08/6.png)
![](https://dustinminer.com/wp-content/uploads/2022/08/7.png)
![](https://dustinminer.com/wp-content/uploads/2022/08/8.png)
Creating an application user in Dynamics 365
Select the ‘Application Users’ view
![](https://dustinminer.com/wp-content/uploads/2022/08/9.png)
Enter the Application Id which was generated earlier
![](https://dustinminer.com/wp-content/uploads/2022/08/10.png)
Select the required role (not System Administrator as this would be a security risk)
![](https://dustinminer.com/wp-content/uploads/2022/08/11.png)
Developing an Azure Function to connect to Dynamics 365
This function connects to Dynamics 365 via Azure AD
![](https://dustinminer.com/wp-content/uploads/2022/08/12.png)
![](https://dustinminer.com/wp-content/uploads/2022/08/13.png)
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