Skip to content

Instantly share code, notes, and snippets.

@ievgen-pavlenko
Created November 22, 2022 14:02
Show Gist options
  • Save ievgen-pavlenko/c86966e116534b489ae038a7fd334847 to your computer and use it in GitHub Desktop.
Save ievgen-pavlenko/c86966e116534b489ae038a7fd334847 to your computer and use it in GitHub Desktop.
Get access token from KuDu shell
#User Assigned Managed Identity
$ProgressPreference = "SilentlyContinue"
$clientId = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'
$headers=@{"X-IDENTITY-HEADER"=$env:IDENTITY_HEADER}
$resourceUri = ‘https://management.azure.com/'
$uri = "$($env:IDENTITY_ENDPOINT)?api-version=2019-08-01&client_id=$clientId&resource=$resourceUri"
$response = Invoke-WebRequest -UseBasicParsing -Uri $uri -Headers $headers
$content = $response.Content | ConvertFrom-Json
$content.access_token
#System Assigned Managed Identity
$ProgressPreference = "SilentlyContinue"
$headers=@{"X-IDENTITY-HEADER"=$env:IDENTITY_HEADER}
$resourceUri = 'https://management.azure.com/'
$uri = "$($env:IDENTITY_ENDPOINT)?api-version=2019-08-01&resource=$resourceUri"
$response = Invoke-WebRequest -UseBasicParsing -Uri $uri -Headers $headers
$content = $response.Content | ConvertFrom-Json
$content.access_token
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment