Azure Cloud Shell | Extract Access token


Access tokens are used in token-based authentication to allow an application to access an API. The application receives an access token after a user successfully authenticates and authorizes access, then passes the access token as a credential when it calls the target API. The passed token informs the API that the bearer of the token has been authorized to access the API and perform specific actions specified by the scope that was granted during authorization. The Microsoft identity platform uses a variety of access token formats depending on the configuration of the API that accepts the token.

In this article, I will show you how you can extract the access token used in Cloud Shell.

curl http://localhost:50342/oauth2/token --data "resource=" -H Metadata:true -s | jq -r ".access_token"

Now you can use this access token in a bash script to call the Azure API:

subscription='put your Azure subscription ID here'
authtoken=`curl http://localhost:50342/oauth2/token --data "resource=" -H Metadata:true -s | jq -r .access_token`
curl -H "Authorization: Bearer $authtoken" -X GET "$subscription/resourceGroups?api-version=$apiversion" | jq


Démarrez une conversation

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *