Posted on Leave a comment

Authenticate to Azure management API using az cli

A quick an easy way to authenticate on Azure management API is to use az cli get-access-token command and use this as a Bearer token on your API calls.

Given that you want to access https://management.azure.com/subscriptions/api you can use:

$token =  az account get-access-token | ConvertFrom-Json

You can then get the access token with $token.accesstoken

Finally you can use this token as a Bearer token on your API calls

$headers = @{ Authorization = "Bearer $token.accesstoken" }
Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.