Last active
April 23, 2020 12:35
-
-
Save JeffBrownTech/9c65a8e2296efa97ccbff18404fe626d to your computer and use it in GitHub Desktop.
Creating OAuth Token for Graph API
This file contains hidden or 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
$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