PrivateFunctions/New-Context.ps1
Function New-Context { [OutputType([DqConnectionContext])] [CmdletBinding()] Param( [Parameter(Mandatory=$True)] [ValidateNotNull()] [DqConnection] $DqConnection, [Parameter(Mandatory=$False)] [System.Management.Automation.PSCredential] $Credential = $Null ) Try { Write-Verbose "Authenticeren met de Secure Token Service van DQ Monitor..." If ($Credential) { $StsResponse = Invoke-WebRequest -UseBasicParsing -Uri $DqConnection.StsUrl -Credential $Credential -Method Get -ErrorAction Ignore } Else { $StsResponse = Invoke-WebRequest -UseBasicParsing -Uri $DqConnection.StsUrl -UseDefaultCredentials -Method Get -ErrorAction Ignore } $JsonObject = $StsResponse.Content | ConvertFrom-Json $Token = $JsonObject.id_token $TokenType = $JsonObject.token_type Return [DqConnectionContext]::new($DqConnection, $TokenType, $Token); } Catch { $ErrorMessage = @" Fout opgetreden bij het opvragen van een token bij Secure Token Service (STS) van DQ Monitor. Foutmelding: $($_.Exception.Message) "@ Write-Error $ErrorMessage; Return; } } |