Setting up the Microsoft Dynamics365 Environment with Azure¶
The Microsoft Dynamics 365 (Microsoft Dynamics CRM) Connector allows you to access the Microsoft Dynamics 365 Web API through WSO2 Enterprise Integrator. The Microsoft Dynamics CRM system (now known as Microsoft Dynamics 365) is a standalone CRM product from Microsoft that provides sales, marketing, and service management capabilities only via individual modules.
To use the Microsoft Dynamics 365, you must have folowing accounts.
- A Microsoft Dynamics 365 (online) system user account with administrator role for the Microsoft Office 365 subscription
- A Microsoft Azure subscription for application registration
Authentication to Dynamics 365 using Azure Apps¶
Dynamics 365 authentication is recommended only through Azure AD (for online instances). To achieve this,
- Create and configure the app in Azure Active Directory.
- Create a user in Azure AD and configure it as an application user in Dynamics 365
Generate the Access Token and make requests to Dynamics 365 with the above-generated Access Token.
Setting Up an App in Azure¶
Navigate to the Azure portal and select Create an Azure Account.
Note: If you creating a Azure account you should get a Microsoft Azure subscription for application registration. Purchase Azure services directly from Microsoft with pay-as-you-go-pricing. This offer is billed at the standard Pay-As-You-Go rates.
Log in to the created Azure account.
- Navigate to Azure Active Directory –> App Registration –> New Application registration.
- Now fill in the required fields as shown below and hit Register.
Note:Note that the sign-on URL only matters for something like a single page application – otherwise just putting a localhost URL is just fine.
- Select created Application.
- Now you have successfully created an Azure app. Double click the app and you will see its details as shown below. Copy the value of the Application (client) ID and Directory (tenant) ID.
- You need to give permission to the app to access Dynamics 365. Navigate to View API permissions.
- Click Add a permission.
- Then select Dynamics CRM.
Make sure to check the Delegated Permissions checkboxes as shown below. Select permissions and click Add permission.
Click on Grant Permissions and click Yes.
After setting up CRM permissions you will see following console.
Now you need to create secret keys. Navigate to Certificates & secrets.
Click New client secrets.
Add Description and Expires values. Click Add and copy the value.
Search Users inside the Azure Active Directory and Create New user (this user would be linked to the Application User, which is created in the Dynamics 365 CRM).
Fill all mandatory fields and click Create.
Setting Up the Application user in Microsoft Dynamics 365 CRM¶
Navigate to Microsoft Dynamics 365 account and select Create a Dynamics 365 Account.
Log in to the created Dynamics 365 account. Click the Admin icon.
- Click Show all from the dropdown in the left corner scroll bar.
- Click All admin centers and click Dynamics 365 icon. It will navigate to the Power Platform admin center.
- Select the created environment and click Open environment.
- Navigate to Settings.
- Click Security -> Users.
- Choose Application Users in the view filter.Select -> New.
- In the Application User form, enter the required information.
The user name information must not match a user that exists in the Azure Active Directory. In the Application ID field, enter the application ID of the app you registered earlier in the Azure AD.
If all goes well, after selecting SAVE, the Application ID URI and Azure AD Object Id fields will auto-populate with correct values.
Before exiting the user form, choose MANAGE ROLES and assign a security role to this application user so that the application user can access the desired organization data.
Generate Access Token¶
After setting up Azure and Microsoft Dynamics 365 CRM, you can get the access token by invoking the following HTTP request.
POST URL: https://login.microsoftonline.com/
Header: Content-Type: application/json
|client_id||Application ID of the registered app in Azure.|
|resource||https://trial.crm.dynamics.com (Dynamics 365 Online Insance URL|
|Client_secret||Key value from the registered app in Azure|
Please note you need to replace the
Make a request using Postman as below.
You need to copy and save the following parameter values to proceed with configuring the WSO2 Microsoft Dynamics 365 Connector.
|apiUrl||The instance URL for your organization.|
|accessToken||Value of the Access Token to access the Microsoft Dynamic CRM Web API via request.|
|clientSecret||The secret key of the application that is registered in the Azure AD.|
|resource||The App ID URI of the web API (E.g "https://kavi859.crm5.dynamics.com/).|