[ValidateNotNullOrEmpty()]
[Parameter(Position = 1)]
[Parameter(Position = 2)]
[ValidateNotNullOrEmpty()]
$ContentType = "application/x-www-form-urlencoded"
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$method = [Microsoft.PowerShell.Commands.WebRequestMethod]::"POST"
$URI = [System.Uri]::new($TokenUri)
$hostName = ($URI.Host) -replace '^www\.'
$maximumRedirection = [System.Int32] 0
$headers = [System.Collections.Generic.Dictionary[string,string]]::new()
$headers.Add("Host", $hostName)
$headers.Add("Accept", "application/json")
$response = (Invoke-WebRequest -Method $method -Uri $URI -MaximumRedirection $maximumRedirection -Headers $headers -ContentType $contentType -Body $Body)
catch [System.SystemException]
Write-Error $_ -ErrorAction Stop
$bearerToken = ($response.Content | ConvertFrom-Json).access_token
function Get-AuthenticatedResource
[ValidateNotNullOrEmpty()]
[ValidateNotNullOrEmpty()]
[Parameter(Position = 3)]
[ValidateNotNullOrEmpty()]
$ContentType = "application/x-www-form-urlencoded"
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$method = [Microsoft.PowerShell.Commands.WebRequestMethod]::"GET"
$URI = [System.Uri]::new($TargetUri)
$maximumRedirection = [System.Int32] 1
$hostName = ($URI.Host) -replace '^www\.'
$headers = [System.Collections.Generic.Dictionary[string,string]]::new()
$headers.Add("Host", $hostName)
$headers.Add("Authorization", "Bearer " + $Token)
$response = (Invoke-WebRequest -Method $method -Uri $URI -MaximumRedirection $maximumRedirection -Headers $headers -ContentType $ContentType)
catch [System.SystemException]
Write-Error $_ -ErrorAction Stop