In this blog post, we are going to use Postman to validate the configuration of the Authorisation Server (Microsoft Azure Active Directory) from Part 2 of this blog series.
Postman is a tool that allows developers to quickly create HTTP messages to test web services. Postman can be download from https://www.getpostman.com/.
Although not required until part 4 of this blog series, the source code for the demo ASP.NET MVC application can be found on Codeplex at https://crmdynamicsoauthwebapiexample.codeplex.com/.
Get New Access Token
This section provides instructions to generate an authentication token in Postman. To generate the token, the application ID (client ID) and client secret created in Part 2 of this blog series is required.
- Open Postman.
- Open a new Postman Tab.
- Set the URL to the Accounts Microsoft Dynamics CRM Web API Endpoint. My URL <WebAPI Endpoint>/Accounts.
This can be retrieved from the Microsoft Dynamics CRM in the Settings >Customizations > Developer Resources Section.
- Select the Authorization Tab.
- Set the Authorization Type to OAuth 2.0.
- Click on Get New Access Token Button.
- Set The following values in the Get New Access Token dialog
- Token Name: Token
- Auth URL: https://login.windows.net/common/oauth2/authorize?resource=<URL Encoded Url to Web API Endpoint>.
My econded Web API endpoint looks like this: https%3A%2F%2F11Nov201.api.crm6.dynamics.com%2f. You could potentially replace the 11Nov2016 with your own domain.
Example of complete Auth Url: https://login.windows.net/common/oauth2/authorize?resource=https%3A%2F%2F11 %2f
- Access Token URL: https://login.microsoftonline.com/common/oauth2/token
- Client Id: Application Id (Client Id) that was created in Part 2 of this blog series. Eg. 6a3622c4-8ba7-47a7-93e3-ebc0e1aa936f
- Client Secret: Client Secret that was created in Part 2 of this blog series. Eg. cytHrW+vFPyh+osZvvKZzlPds/PUKbEMIHcddHb2XRI=
- Grant Type: Authorization Code
- Click the Request Token button.
- A Microsoft Dynamics CRM login screen is displayed. Log in using the username and password created in Part 2 of this blog series when creating a trial of Microsoft Dynamics CRM.
- Select the token that will now be displayed in the list of existing tokens.
- Click on the use token button; the Authorization header will now exist under the headers tab.
- Click on the headers tab; notice there is already an authorization header.
- Add a new content type of application/json header.
- Click on the send button.
- A list of accounts will be returned. Note your Dynamics CRM instance may have zero accounts and you may get an empty list of accounts returned to Postman.
This blog post demonstrates how to use Postman to perform an OData query against the Dynamics CRM Web API endpoint, allowing developers to quickly validate third-party applications are configured with Dynamics CRM permissions in Azure Active Directory correctly.