Dynamics 365 Online – API Access Token with OAuth 2.0


In this post, I’m going to demonstrate how to generate Access Tokens using OAuth 2.0, Implicit Grant for Microsoft Dynamics 365 CE.

This is a two-step process. Firstly, you must register the App with Azure Active Directory. Secondly, setup Postman to make HTTP calls.

Register Azure Active Directory App

Register a new App in Azure Active Directory. In my example, I’m using the Redirect URI: https://eax360.com/callback

Take note of the Application ID (client ID). In my example this is:

Display name: Dynamics 365 App Registration
Application (client) ID:a27d5fd4-ffa4-4825-aa06-9bca50499d77

Also, ensure that Access Token has been enabled under the Implicit Grant heading in the Platform configurations section.

This completes the App configuration.

Add API Permissions

Once the above is complete, go to API Permissions and add Dynamics CRM.

On completion of the step above, ensure that you have selected ‘Grant admin consent for {oganisation name}’.

Create a new Client Secret

Once the step above is completed, it’s now time to create a new Client secret. Under Certificate & secrets, create a new secret and take note of the value.

In the example above, my secret is ‘Wsj8[a@16.fA]TXSAp71u=sTw0dDbx8x

This completes the App registration.

Postman Environment Setup

In Postman, create a new Environment by clicking on the cog icon. The settings required are as follows:

Variable nameValue
urlhttps://<add your environment name, like 'myorg.crm'>.dynamics.com

In my example, I will be using the following settings:

Variable nameValue

This completes the Postman environment setup.

Generate Access Token

The final step is to retrieve the Access Token. To do this, select the environment, and under Authorisation, select OAuth 2.0.

Under Grant type, select Implicit. The fields that must be completed here are:

  1. Auth URL
  2. Client ID
  3. Callback URL

Enter these values and click Request Token.

At this point, you should be prompted to sign-in. Once the Sign-in stage has been completed, you will be presented with the Access Token. Click on Use Token.

If everything is successful, you should be able to make HTTP requests.

This completes the setup for Postman.

Final Thoughts

Microsoft has a very nicely documented setup here: https://docs.microsoft.com/en-us/powerapps/developer/common-data-service/webapi/setup-postman-environment#connect-with-your-common-data-service-environment

Of course, if you would then like to register the application with Azure Active Directory, the steps can be found here: https://docs.microsoft.com/en-us/powerapps/developer/common-data-service/walkthrough-register-app-azure-active-directory

Leave a comment