If you work at all with REST APIs you’ll no doubt be familiar with Postman. Postman provides a super simple UI for developing and testing APIs and has a built-in feature for requesting OAuth 2.0 Access Tokens. The procedure below describes how to make a request to the Azure REST API to list the available Azure subscriptions. The documentation for the Azure REST API is available here and provides ample detail on how to build a request to the Azure API.
- Open Postman and create a new GET request to https://management.azure.com/subscriptions?api-version=2016-09-01.
- Click Send
- The request should fail but that’s ok for now.
- Click on the Authorization section and change the Type to OAuth 2.0.
- Click the button that appears entitled Get new Access Token.
- Give the Token a meaningful name.
- Set Auth URL to https://login.microsoftonline.com/common/oauth2/authorize?resource=https://management.azure.com/. Please keep in mind that this ‘resource’ parameter is what’s required to talk to the Azure Resource Manger API.
- Set Access Token URL to https://login.microsoftonline.com/common/oauth2/token.
- ClientID and Client Secret are required and you can obtain them by registering an Azure AD Application. Make sure you grant access to the ‘Windows Azure Service Management API’ on the ‘Required Permissions’ tab.
- You will also need to ensure that https://www.getpostman.com/oauth2/callback is set as one of your Reply URLs.
- Leave Scope empty .
- Set Grant Type to Authorization Code
- You should have something like this:
- Click request token.
- You should now be presented with the usual sign-in screen for Azure.
- After you’ve signed in a new token should appear.
- Select the new token and change the Add token drop down to Header and then select Use Token
- You will notice that there is now an Authorization header added to the request.
You should now be able to click ‘Send’ and get a response back from the Azure API. Enjoy!