azureoauth-2.0bearer-token

How access Azure APIs


I am trying to access the Azure APIs, using postman, for example https://management.azure.com/tenants?api-version=2022-12-01 but completely lost with MS documentation. I went through some threads here and they talk about sending some parameters in the body, such as:

client_id= &client_secret= &grant_type=client_credentials &resource=

How/Where can I get those details. Is it somewhere in Azure portal?


Solution

  • To access this API query GET https://management.azure.com/tenants?api-version=2022-12-01

    Initially, I registered Single Tenant Microsoft Entra ID application

    Go to portal --> Microsoft Entra ID -->App registration

    enter image description here

    Added and granted API permission of Azure Service Management like below:

    enter image description here

    Also, I added RBAC role of Reader to Service Principal at Subscription level:

    enter image description here

    Now, Added Client Secret:

    enter image description here

    Now, Generate access token using Postman or ThunderClient(VS Code Extension) with below parameters:

    POST https://login.microsoftonline.com/<tenant_id>/oauth2/v2.0/token
    
    client_id = <client_id>
    client_secret= <client secret>
    grant_type = client_credentials
    scope = https://management.azure.com/.default
    
    

    enter image description here

    Now use this generated access token to fetch the below query:

    GET https://management.azure.com/tenants?api-version=2022-12-01

    enter image description here

    Reference:

    Tenants-List

    Azure-RBAC Roles