Private/Curanet/Get-AccessToken.ps1
function Get-AccessToken() { if (!$SAMTokens) { #$SAMTokens = Get-SAMTokens } Write-Host $SAMTokens $RequestBody = @{ grant_type = "client_credentials" client_id = "f47c5eab-b7f7-48c7-89a0-6fcf4bcffa33" client_secret = "cHAc1GdGKtIA02SRjWpif2ncAdNEhtFo" #client_secret = $SAMTokens.Curanet3850APISecret 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 } |