Skip to content

Instantly share code, notes, and snippets.

@bruceharrison1984
Last active May 19, 2020 12:30
Show Gist options
  • Save bruceharrison1984/019e972405c03c61b9a99c3c5c7312be to your computer and use it in GitHub Desktop.
Save bruceharrison1984/019e972405c03c61b9a99c3c5c7312be to your computer and use it in GitHub Desktop.
$Fields = @{
grant_type = "client_credentials"
client_id = "<service-principal-id>"
resource = "<resource-id-to-auth-for-or-url>"
client_secret = "<service-principal-secret>"
};
$response = Invoke-RestMethod `
-Uri "https://login.microsoftonline.com/<azure-tenant-id>/oauth2/token" `
-ContentType "application/x-www-form-urlencoded" `
-Method POST `
-Body $Fields;
Write-Output $tokenResponse.access_token
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment