Justin's Developer Notes logo Justin's Developer Notes

Using Azure AD from Bash

Navigate to https://login.microsoftonline.com/[tenant-id]/oauth2/authorize?client_id=[client-id]&response_type=code

Replacing [tenant-id] and [client-id]

Get code from response like: https://localhost:44341/signin-oidc?code=AQABAAIAAAA9kTklhVy7SJTGAzR-p1BcQn__M38KdNCdhagAfbE0rikab8J-N_W9KSXQJWORm9ggiQVDauGkuHlULHC2glmfs27RTJeyhfXvfnDbB9yY43KwaGdBpcx-PCfaP7V9SfrNA_RfTwy14RetENLD98uQUxEIv6cb7MvjHzHsHN4vmd3Ie3h43Kgu6ghDW5jxSDS9J27nMl2xN31vj529EUeyr0EeBG9uSd4v4F1HZ3sszUsF00sICFPjuVTAA1yDFyVS5xfg2YgONa1MT2jHfLZqI2LxTlkzc6cFzqks496n4WomQleSxoR6Qt7TiulpVfV4_2Dm5UfMDd7lMGNmfn_qTq1EcSvWXnnP9_U5r_WK6PSIn_ztru46cDTk0qORjT7i4fg8OGj1BG2bkR-jhm3Oy_mDaIowLoCqmobMEbA6LMMLjy3gkkBPkqIF7VlIjzVadazcqmL2FbwP5O0N7AuA9TFDRF6WoqnpgHonALGpiFIyESyFj4yil5TfmstrB2Y8GPhqOInLyA-QtmGMgHxv2_wUXilX6hjP2LkBPvFmyau3DRijTHD0PPQQDpfMmsOU9ZQKNc2x2erGBLnm49Z0h9kZDIbqyTR1c7es_ziOosOeGpmjGtXV58fWjiHTvbPtNnhSJnZrlC6ChMoxi_1b-5Ea4Ax49-43xSKoTw2VlrRxApy65-EbK8pgM-XpKKUgAA&session_state=56151aae-8194-4775-8300-627144292866

Use the code in the following request

curl "https://login.microsoftonline.com/[tenant-id]/oauth2/token" \
  -F "redirect_uri=https://localhost:44341/signin-oidc" \
  -F "grant_type=client_credentials" \
  -F "resource=https://management.azure.com/" \
  -F "client_id=[client-id]" \
  -F "client_secret=CRe01LSBR8pku0CVVQ0bd9KztSf3cVn/sKfnGbT7lv4=" \
  -F "code=AQABAAIAAAA9kTklhVy7SJTGAzR-p1BcQn__M38KdNCdhagAfbE0rikab8J-N_W9KSXQJWORm9ggiQVDauGkuHlULHC2glmfs27RTJeyhfXvfnDbB9yY43KwaGdBpcx-PCfaP7V9SfrNA_RfTwy14RetENLD98uQUxEIv6cb7MvjHzHsHN4vmd3Ie3h43Kgu6ghDW5jxSDS9J27nMl2xN31vj529EUeyr0EeBG9uSd4v4F1HZ3sszUsF00sICFPjuVTAA1yDFyVS5xfg2YgONa1MT2jHfLZqI2LxTlkzc6cFzqks496n4WomQleSxoR6Qt7TiulpVfV4_2Dm5UfMDd7lMGNmfn_qTq1EcSvWXnnP9_U5r_WK6PSIn_ztru46cDTk0qORjT7i4fg8OGj1BG2bkR-jhm3Oy_mDaIowLoCqmobMEbA6LMMLjy3gkkBPkqIF7VlIjzVadazcqmL2FbwP5O0N7AuA9TFDRF6WoqnpgHonALGpiFIyESyFj4yil5TfmstrB2Y8GPhqOInLyA-QtmGMgHxv2_wUXilX6hjP2LkBPvFmyau3DRijTHD0PPQQDpfMmsOU9ZQKNc2x2erGBLnm49Z0h9kZDIbqyTR1c7es_ziOosOeGpmjGtXV58fWjiHTvbPtNnhSJnZrlC6ChMoxi_1b-5Ea4Ax49-43xSKoTw2VlrRxApy65-EbK8pgM-XpKKUgAA"

Call endpoint with token from above

curl --header "Accept: application/json" --header "Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6IkhIQnlLVS0wRHFBcU1aaDZaRlBkMlZXYU90ZyIsImtpZCI6IkhIQnlLVS0wRHFBcU1aaDZaRlBkMlZXYU90ZyJ9.eyJhdWQiOiJodHRwczovL21hbmFnZW1lbnQuYXp1cmUuY29tLyIsImlzcyI6Imh0dHBzOi8vc3RzLndpbmRvd3MubmV0LzFlMWE1ZTNhLWYwZWEtNDVjOS05ZDgwLWQ4OGU0ZDhlZDM3OC8iLCJpYXQiOjE1MDQ3NjQ2ODEsIm5iZiI6MTUwNDc2NDY4MSwiZXhwIjoxN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