Uredi

Register an app to request authorization tokens and work with APIs

To access Azure REST APIs such as the Log Analytics API, or to send custom metrics, generate an authorization token based on a client ID and secret. Pass the token in your REST API request. This article shows you how to register a client app and create a client secret to generate a token.

Prerequisites

Register an app

Create a service principal and register an app by using the Azure portal, Azure CLI, or Azure PowerShell.

  1. To register an app, open the Microsoft Entra ID Overview page in the Azure portal.

  2. Select App registrations from the side bar. A screenshot showing the Microsoft Entra overview page.

  3. Select New registration

  4. On the Register an application page, enter a Name for the application.

  5. Select Register

  6. On the app's overview page, select Certificates and Secrets

  7. Note the Application (client) ID. It's used in the HTTP request for a token. A screenshot showing the App registrations overview page in Microsoft Entra ID.

  8. In the Client secrets tab Select New client secret

  9. Enter a Description and select Add A screenshot showing the Add client secret page.

  10. Copy and save the client secret Value.

    Note

    Client secret values can only be viewed immediately after creation. Be sure to save the secret before leaving the page.

    A screenshot showing the client secrets page.

Assign a role to the app for the resources that you want to access with the API:

  1. In the Azure portal, go to the resource, resource group, or subscription where you want to grant access, and select Access control (IAM).
  2. Select Add > Add role assignment.
  3. On the Role tab, select the Reader role, and then select Next.
  4. On the Members tab, select Assign access to > User, group, or service principal, then select Select members and choose your app.
  5. Select Review + assign.

Next steps

You registered an app and assigned it a role. Next, use your app, client ID, and client secret to generate a bearer token to access the REST API.

The role you assign depends on the resource type and the API that you use. For example:

For more information about assigning roles, see Assign Azure roles using the Azure portal.

Note

When using Microsoft Entra authentication, it might take up to 60 minutes for the Azure Application Insights REST API to recognize new role-based access control (RBAC) permissions. While permissions are propagating, REST API calls might fail with error code 403.