How to generate a bearer token on Azure container instance to access https://management.azure.com/subscriptions/xxx/resourceGroups/xxxx/providers/Microsoft.ContainerInstance/containerGroups/xxx

NS 40 Reputation points
2023-10-05T05:00:04.11+00:00

I need to access public API https://management.azure.com/subscriptions/xxx/resourceGroups/xxxx/providers/Microsoft.ContainerInstance/containerGroups/xxx from the Azure Container Instance.
It appears that this API needs a Bearer Token.

How can we generate the bearer token for this API from the ACI container.

Azure Container Instances
Azure Container Instances
An Azure service that provides customers with a serverless container experience.
700 questions
0 comments No comments
{count} votes

Accepted answer
  1. TP 94,306 Reputation points
    2023-10-05T07:28:40.57+00:00

    Hi,

    The access token is the Bearer token. For example, in your previous question I showed how to retrieve access token via IMDS. Once you have this access token, you can add it in the Authorization header in the request to management.azure.com REST API.

    GET https://management.azure.com/subscriptions/<subscriptionId>/providers/Microsoft.ContainerInstance/containerGroups?api-version=2023-05-01
    Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6Ii1LSTNROW5OUjdiUm9meG1lWm9YcWJIWkdldyIsImtpZCI6Ii1LSTNROW5OUjdiUm9meG1lWm9YcWJIWkdldyJ9.eyJhdWQiOiJodHRwczovL21hbm
    
    

    Curl command would be similar to below:

    curl -v -s -H "Authorization: Bearer ${access_token}" -H "Content-Type: application/json" https://management.azure.com/subscriptions/${subscription_id}/providers/Microsoft.ContainerInstance/containerGroups?api-version=2023-05-01
    
    

    Please click Accept Answer and upvote if the above was helpful.

    Thanks.

    -TP


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.