Search code examples
azurepostmanauthorizationazure-storageazure-rest-api

Standard ways of generating the bearer token for authorization. - When sending the get request to azure blob storage list api in postman


Continuing from this Answer, how to generate the bearer token for passing to the REST API.

Normally, for a temporary testing I have clicked on Inspect element on the browser and browsed to Azure storage account and took the bearer token value from the Network tab from the browser developer tools (Edge browser).

enter image description here

I believe, this is not the way of acquiring the bearer token.

Can anyone help me of getting the bearer token in standard ways with its steps.


Solution

  • Better way to acquire a token that can be used to authorize requests against Azure Storage would be to make use of Azure CLI or Azure PowerShell.

    If you are using Azure CLI, the command would be:

    token=$(az account get-access-token --resource=https://storage.azure.com/ --query accessToken --output tsv)
    

    If you are using Azure PowerShell, the command would be:

    $token = (Get-AzAccessToken -ResourceUrl 'https://storage.azure.com/').Token
    

    Please ensure that you have proper storage related RBAC permissions assigned to the user for which you are acquiring token. To learn more about the permissions needed, please see this link: https://learn.microsoft.com/en-us/azure/storage/blobs/authorize-access-azure-active-directory.