Skip to content

Instantly share code, notes, and snippets.

@pjirsa
Last active April 22, 2022 11:35
Show Gist options
  • Save pjirsa/4318c662adaa93541bbb767eff1dd0f5 to your computer and use it in GitHub Desktop.
Save pjirsa/4318c662adaa93541bbb767eff1dd0f5 to your computer and use it in GitHub Desktop.
Use Azure CLI to acquire access token for custom API
$appId = "04b07795-8ddb-461a-bbee-02f9e1bf7b46" #global appId for az CLI
$apiId = "5d6db6cd-cce5-47c4-8700-000efa22e068" #appId of your custom API
$requestScope = "api://localhost/5d6db6cd-cce5-47c4-8700-000efa22e068/.default" #scope exposed by your custom API app registration
## First time only
az login
az ad sp create --id $appId
az ad app permission grant --id $appId --api $apiId --scope "access_as_user"
## Get new token
az account get-access-token --scope $requestScope --query accessToken
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment