By Sahil Malik
My friends and buddies taught me these, and I know I’ll forget them, so writing them up here.
Azure is full of amazing REST APIs, but sometimes getting an access token requires you to jump through hoops. Here is a way to make it all hella easy!
First, for Microsoft Graph, you just go to graph explorer, open dev tools, and write
tokenPlease() and it writes out the token for you.
For more generic, i.e., tokens for any resource protected by Azure AD, do this,
az account get-access-token --resource https://graph.microsoft.com
.. basically just substitute resource for whatever you wish, and you’ll get a shiny new access token. Easy huh?
- For an AAD account not connected with any azure subscription, simply use
az login --allow-no-subscriptions
- You can grab the access token directly into clipboard with this,
az account get-access-token --resource https://graph.microsoft.com | jq .\accessToken | pbcopy
This requires you to install jq
brew install jq.
3. You can also omit the resource — that gives you an access token for the management api by default, which is kinda cool, because now u can manage Azure via rest calls (CURL for instance!)