Last active
April 9, 2019 08:25
-
-
Save leeford/de7dd733161c3b37bca7f2c4ac45fc33 to your computer and use it in GitHub Desktop.
Azure AD OAuth Application Token for Graph API
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
# Azure AD OAuth Application Token for Graph API | |
# Get OAuth token for a AAD Application (returned as $token) | |
# Application (client) ID, tenant ID and secret | |
$clientId = "<client id>" | |
$tenantId = "<tenant id>" | |
$clientSecret = '<secret>' | |
# Construct URI | |
$uri = "https://login.microsoftonline.com/$tenantId/oauth2/v2.0/token" | |
# Construct Body | |
$body = @{ | |
client_id = $clientId | |
scope = "https://graph.microsoft.com/.default" | |
client_secret = $clientSecret | |
grant_type = "client_credentials" | |
} | |
# Get OAuth 2.0 Token | |
$tokenRequest = Invoke-WebRequest -Method Post -Uri $uri -ContentType "application/x-www-form-urlencoded" -Body $body -UseBasicParsing | |
# Access Token | |
$token = ($tokenRequest.Content | ConvertFrom-Json).access_token |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment