Private/Curanet/Get-CuranetAccessToken.ps1
function Get-CuranetAccessToken { param ( [Parameter(Mandatory)] [ValidateSet("3370", "3850")] [string]$Account ) try { $secret = Get-CuranetAPIKey -Account $Account if($Account -eq "3370") { $body = @{ grant_type = 'client_credentials' client_id = '5e37d077-36ad-4532-928b-7a4eb015009b' client_secret = $secret scope = 'dns' } } elseif($Account -eq "3850") { $body = @{ grant_type = 'client_credentials' client_id = '6df37143-c67b-4e7e-9715-b375d21141d5' client_secret = $secret scope = 'customers orders subscriptions microsoft365 microsoft365backup invoicing' } } $contentType = 'application/x-www-form-urlencoded' $reqToken = Invoke-WebRequest -Method POST -Uri "https://apiauth.dk.team.blue/auth/realms/Curanet/protocol/openid-connect/token" -body $body -ContentType $contentType $tokenJSON = ConvertFrom-Json $reqToken.Content Set-Variable -Name "$($Account)AccessToken" -Scope Global -Value $tokenJSON Set-Variable -Name "$($Account)AccessTokenExpire" -Scope Global -Value (Get-Date).AddSeconds($tokenJSON.expires_in) } catch { Write-Error "Error getting token - $($_)" return $false } } |