azureazure-active-directorydynamics-crmmicrosoft-dynamics

How to create an authentication token for Dynamics CRM


I have to migrate my data to Dynamics CRM using Mulesoft as an integration tool. I need to use integration APIs for this. The documentation of these APIs can be found here: https://cloud-elements.github.io/docs/elements/dynamicscrm/ko/api-documentation.html?elementId=190#!/accounts/createAccount But there is no API available here for the authentication. Also, I couldn't find any method to create token from any UI. I have created a free trial account on Azure and hence I am unable to create any permissions, previliges, users etc within my account. Can someone share some information about how I can create an authentication token, in order to use the integration APIs to migrate data from my DB to Dynamics.

I tried following this article: https://www.c-sharpcorner.com/article/generate-access-token-for-dynamics-365-single-tenant-server-to-server-authentica/ to somehow create a token etc but failed.

I can not add any user or permission in Azure and get this error every time.


Solution

  • I tried to reproduce the same in my environment and got below results:

    I registered one Azure AD application and added API permissions as below:

    enter image description here

    To generate access token for Dynamics CRM, I used below parameters in Postman like this:

    POST https://login.microsoftonline.com/<tenantID>/oauth2/v2.0/token
    grant_type:client_credentials
    client_id:<appID>
    client_secret:<secret>
    scope: https://admin.services.crm.dynamics.com/.default
    

    Response:

    enter image description here

    To confirm that, I decoded the above token in jwt.ms and got aud claim successfully like below:

    enter image description here

    In your case, the error usually occurs if you don't create Azure Free trial account properly.

    When I signed in with my personal email account to Azure Portal directly without creating Free Trial, I got same error as you like below:

    enter image description here

    Go through below link to create Free Trial account.

    Reference: How To Create Azure Free Account by Onkar Sharma