Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,31 @@ function Get-AccessToken {
$tokenEndpoint = '{0}/connect/token' -f $SecurityServiceUrl.TrimEnd('/')
Write-Verbose "Requesting access token from [$tokenEndpoint]"

$tokenResponse = Invoke-RestMethod -Method Post `
-Uri $tokenEndpoint `
-SkipCertificateCheck `
-ContentType 'application/x-www-form-urlencoded' `
-Body @{
grant_type = 'client_credentials'
client_id = $ClientId
client_secret = $ClientSecret
}
$requestParameters = @{
Method = 'Post'
Uri = $tokenEndpoint
ContentType = 'application/x-www-form-urlencoded'
Body = @{
grant_type = 'client_credentials'
client_id = $ClientId
client_secret = $ClientSecret
}
}

if ((Get-Command Invoke-RestMethod -ErrorAction Stop).Parameters.ContainsKey('SkipCertificateCheck')) {
$requestParameters.SkipCertificateCheck = $true
$tokenResponse = Invoke-RestMethod @requestParameters
}
else {
$previousCertificateValidationCallback = [System.Net.ServicePointManager]::ServerCertificateValidationCallback
try {
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = { $true }
$tokenResponse = Invoke-RestMethod @requestParameters
}
finally {
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = $previousCertificateValidationCallback
}
}

if ($tokenResponse -is [hashtable]) {
foreach ($propertyName in 'access_token', 'AccessToken', 'token', 'Token') {
Expand Down
Loading