Skip to content

Instantly share code, notes, and snippets.

@darrenjrobinson
Created September 12, 2016 12:36
Show Gist options
  • Save darrenjrobinson/917397a422126bcc80f4a21177a7082d to your computer and use it in GitHub Desktop.
Save darrenjrobinson/917397a422126bcc80f4a21177a7082d to your computer and use it in GitHub Desktop.
#get Access Token
$body = "grant_type=authorization_code&redirect_uri=$redirectUri&client_id=$clientId&client_secret=$clientSecretEncoded&code=$authCode&resource=$resource"
$Authorization = Invoke-RestMethod https://login.microsoftonline.com/common/oauth2/token `
-Method Post -ContentType "application/x-www-form-urlencoded" `
-Body $body `
-ErrorAction STOP
Write-output $Authorization.access_token
$accesstoken = $Authorization.access_token
$me = Invoke-RestMethod -Headers @{Authorization = "Bearer $accesstoken"} `
-Uri https://graph.microsoft.com/v1.0/me `
-Method Get
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment