Created
October 29, 2015 20:56
-
-
Save astaykov/756d879415a3af911c78 to your computer and use it in GitHub Desktop.
Get access token from Azure AD OAuth 2.0 endpoint
This file contains 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
Function GetToken | |
{ | |
param( | |
[String] $authority = "https://login.microsoftonline.com/lab09.onmicrosoft.com/oauth2/token", | |
[String] $clientId = "<your_client_id_here>", | |
[String] $clientSecret = "<client_secret>", | |
[String] $resourceId = "https%3a%2f%2fgraph.windows.net" | |
) | |
$body = "grant_type=client_credentials&resource=$($resourceId)&client_id=$($clientId)&client_secret=$($clientSecret)" | |
$res = Invoke-WebRequest -Uri $authority -Body $body -Method Post | |
$authResult = $res.Content | ConvertFrom-Json | |
return $authResult.access_token | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment