Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
[CmdletBinding()]
Param(
[Parameter(Mandatory=$true, ValueFromPipeline=$true)]
[String] $appID,
[Parameter(Mandatory=$true, ValueFromPipeline=$true)]
[string] $appSecret,
[Parameter(Mandatory=$true, ValueFromPipeline=$true)]
[string] $subID
)
# Define API Token details for Service Principal
$ReqTokenBody = @{
Grant_Type = "client_credentials"
client_Id = $appID
Client_Secret = $appSecret
Scope = "https://graph.microsoft.com/.default"
Tenant_Name = $subID
}
# Obtain API Bearer Token
$TokenResponse = Invoke-RestMethod -Uri "https://login.microsoftonline.com/$($ReqTokenBody.Tenant_Name)/oauth2/v2.0/token" -Method POST -Body $ReqTokenBody
$TokenResponse
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment