Skip to content

Instantly share code, notes, and snippets.

@JeffBrownTech
Last active April 23, 2020 12:35
Show Gist options
  • Save JeffBrownTech/9c65a8e2296efa97ccbff18404fe626d to your computer and use it in GitHub Desktop.
Save JeffBrownTech/9c65a8e2296efa97ccbff18404fe626d to your computer and use it in GitHub Desktop.
Creating OAuth Token for Graph API
$env:graphApiDemoAppId = "12345678-abcd-efgh-jklm-123456789abc" # Replace with your Azure AD app id
$env:graphApiDemoAppSecret = "1234567890asdfjk;l54321" # Replace with your Azure AD app secret
$env:tenantId = "12345678-abcd-efgh-ijkl-987654321wxyz" # Replace with your Azure AD tenant ID
$oauthUri = "https://login.microsoftonline.com/$env:tenantId/oauth2/v2.0/token"
# Create token request body
$tokenBody = @{
client_id = $env:graphApiDemoAppId
client_secret = $env:graphApiDemoAppSecret
scope = "https://graph.microsoft.com/.default"
grant_type = "client_credentials"
}
# Retrieve access token
$tokenRequest = Invoke-RestMethod -Uri $oauthUri -Method POST -ContentType "application/x-www-form-urlencoded" -Body $tokenBody -UseBasicParsing
# Save access token
$accessToken = ($tokenRequest).access_token
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment