User Tools

Site Tools


wiki:connect_azure_rest_api

Connect to Azure REST API

This uses so-called client credentials grant for accessing the API. There are also authorization via code to get the token mentioned below.

In your account open the azure shell. After connecting create the principal

az ad sp create-for-rbac --role Contributor --scope /subscriptions/<your subscription id>

Subscription id can be obtained from URL when you are logged in to portal.azure.com or with this command

az account show --query id -o tsv

You should get the following similar info

{
  "appId": "257xxxxxxxxxxxxxxxxxxxxxx",
  "displayName": "azure-cli-2022-08-30-10-52-10",
  "password": "xxxxxxxxxxxxxxxxxxxxx",
  "tenant": "4aedxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
}

This data can now be used to get query the API but you still need the BearerToken which can be obtained via this script, which can be used in Postman as a “Pre-request Script”

You can also get the token via curl see this

Renew/generate new token i.e. client secret

  1. In the Azure portal, in App registrations, select your application.
  2. Select Certificates & secrets > Client secrets > New client secret.
  3. Add a description for your client secret.
  4. Select an expiration for the secret or specify a custom lifetime. Client secret lifetime is limited to two years (24 months) or less. You can't specify a custom lifetime longer than 24 months. Microsoft recommends that you set an expiration value of less than 12 months.
  5. Select Add.
  6. Record the secret's value for use in your client application code. This secret value is never displayed again after you leave this page.

Tested on

  • Microsoft Azure accessed on 2022-08-30

See also

References

wiki/connect_azure_rest_api.txt · Last modified: 2023/09/05 11:29 by antisa

Except where otherwise noted, content on this wiki is licensed under the following license: CC0 1.0 Universal
CC0 1.0 Universal Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki