Private/Curanet/Get-CuranetAccessToken.ps1
function Get-CuranetAccessToken() { if (!$CuranetAPIKey) { $CuranetAPIKey = Get-CuranetAPIKey } $RequestBody = @{ grant_type = "client_credentials" client_id = "f47c5eab-b7f7-48c7-89a0-6fcf4bcffa33" client_secret = $CuranetAPIKey scope = "customers orders subscriptions" } try { $AccessToken = ((Invoke-WebRequest -Uri "https://apiauth.dk.team.blue/auth/realms/Curanet/protocol/openid-connect/token" -Method POST -Body $RequestBody -ContentType 'application/x-www-form-urlencoded').Content | ConvertFrom-Json).access_token } catch { Write-Error "Failed to retreive access token: $_" } return $AccessToken } |