How to get an AzureAD JWT for service authentication on command line

Viewed 224

I have some company website providing some information protected by azure AD. This works fine in the browser, but I would like to create some automation on command line.

If I copy the JWT from the browser and use it in the Authorization: Bearer header, I can also access that information perfectly fine.

I was also able to use az login to prove my identity on the command line.

What is the correct way to get a suitable JWT on command line in order to access the information?

I was thinking of something like:

az login
token=$(az ad get-new-jwt-token)
curl -H "Authorization: Bearer $token" myinfosite.company.com

If there is a better/different solution, I am open to that, too.

1 Answers

You are almost there. If you want to do this via CLI then it would be like below

  1. login

  2. set the subscription

  3. get the access token

     az login        
     az account set  -s "<your-subscription-id>"        
     az account get-access-token
    

After that you would get your Bearer token enter image description here

Related