Last active
September 21, 2022 00:22
-
-
Save markarnott/95cfafbc7ac475930a95ebb72b19c3bf to your computer and use it in GitHub Desktop.
Get an Access Token for Azure
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# ==== Using the Az CLI ==== | |
az login | |
accessToken=$(az account get-access-token --query accessToken | tr -d \") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ==== Using the Az CLI ==== | |
az login | |
$accessToken = (az account get-access-token --query accessToken).Trim('"') | |
# ==== Using PwSH Az Modules ==== | |
Import-Module Az.Accounts | |
Connect-AzAccount | |
$accessToken = (Get-AzAccessToken).Token |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$clientId = "6731de76-14a6-49ae-97bc-6eba6914391e" | |
$Resp = (curl -X POST ` | |
-d client_id=$clientID ` | |
-d 'scope=user.read%20openid%20profile' ` | |
https://login.microsoftonline.com/common/oauth2/v2.0/devicecode | |
) | ConvertFrom-Json | |
Start-Process $Resp.verification_uri | |
$devCodeData = "device_code=$($Resp.device_code)" | |
$Resp2 = (curl -X POST ` | |
-d grant_type=urn:ietf:params:oauth:grant-type:device_code ` | |
-d $devCodeData ` | |
-d client_id=$clientID ` | |
https://login.microsoftonline.com/common/oauth2/v2.0/token | |
) | ConvertFrom-Json |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment