From 49aa2dd7baa979da1bac9ae87faba27307bd6258 Mon Sep 17 00:00:00 2001 From: StuartFerguson Date: Thu, 1 Oct 2026 12:37:25 +0100 Subject: [PATCH] fix: support older PowerShell certificate bypass --- .../Invoke-DailySettlementProcessing.ps1 | 34 ++++++++++++++----- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/ScheduledTasks/SettlementProcessing/Invoke-DailySettlementProcessing.ps1 b/ScheduledTasks/SettlementProcessing/Invoke-DailySettlementProcessing.ps1 index ae022e8..fb2e9ec 100644 --- a/ScheduledTasks/SettlementProcessing/Invoke-DailySettlementProcessing.ps1 +++ b/ScheduledTasks/SettlementProcessing/Invoke-DailySettlementProcessing.ps1 @@ -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') {