Skip to content

Instantly share code, notes, and snippets.

@seanmcdonnellblog
Last active March 29, 2020 06:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seanmcdonnellblog/3752f7b256b36ac24b34febaecee97ac to your computer and use it in GitHub Desktop.
Save seanmcdonnellblog/3752f7b256b36ac24b34febaecee97ac to your computer and use it in GitHub Desktop.
[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