Authenticate to Azure Deployment Environments REST APIs

Tip

Before authenticating, ensure that the user or identity has the appropriate permissions to perform the desired action. For more information, see Provide access for dev team leads and Provide access for developers.

Use Microsoft Entra ID authentication for REST APIs

Use the following procedures to access Azure Deployment Environments REST APIs by using Microsoft Entra ID. You can follow along in Azure Cloud Shell, on an Azure virtual machine, or on your local machine.

Sign in to your Azure subscription

Start by authenticating with Microsoft Entra ID by using the Azure CLI. This step isn't required in Azure Cloud Shell.

az login

The command opens a browser window to the Microsoft Azure authentication page, where you can choose an account. The page requires you to give your Microsoft Entra ID username and password.

Next, set the correct subscription context. If you authenticate from an incorrect subscription or tenant, you might receive unexpected 403 Forbidden errors.

az account set --subscription <subscription_id>

Retrieve the Microsoft Entra ID access token

Use the Azure CLI to acquire an access token for the Microsoft Entra ID authenticated user. The resource ID is different depending on if you access administrator (control plane) APIs or developer (data plane) APIs.

For administrator APIs, use the following command:

az account get-access-token

For developer APIs, use the following command:

az account get-access-token --resource https://devcenter.azure.com

After authentication is successful, Microsoft Entra ID returns an access token for the current Azure subscription:

{
  "accessToken": "[TOKEN]",
  "expiresOn": "[expiration_date_and_time]",
  "subscription": "[subscription_id]",
  "tenant": "[tenant_id]",
  "tokenType": "Bearer"
}

The token is a Base64 string. The token is valid for at least five minutes. The maximum duration is 90 minutes. The expiresOn defines the actual token expiration time.

Tip

Developer API tokens for the service are encrypted and can't be decoded using JWT decoding tools. They can only be processed by the service.

Use a bearer token to access REST APIs

To access REST APIs, you must set the authorization header on your request. The header value should be the string Bearer followed by a space and the token you received in the previous step.

Next steps