Private/WhatsUpGold/_GetSTTWUGAccessToken.ps1
function _GetSTTWUGAccessToken { [CmdletBinding()] param ( [Parameter(Mandatory = $true)] [string]$ServerHostname, [Parameter(Mandatory = $true)] [string]$Port ) begin { _SetIgnoreSSLCert try { $UserName = $WUGCredential.username $Password = [System.Net.NetworkCredential]::new('', $WUGCredential.Password).Password } catch { # TODO show error on getting WUG creds. } $Body = @{ grant_type = 'password' username = $UserName password = $Password } $URL = "https://${ServerHostname}:${Port}/api/v1/token" $InvokeSplat = @{ Method = 'Post' Uri = $Url Body = $Body } } process { $Token = Invoke-RestMethod @InvokeSplat } end { $Header = @{ 'Accept' = 'application/json' # TODO - Specified value has invalid non-ASCII characters. # 'Çontent-Type' = 'application/x-www-form-urlencoded' Authorization = "Bearer $($Token.access_token)" } $Connection = @{ BaseURL = "https://$($ServerHostname):$($Port)/api/v1" Header = $Header Token = $Token } return $Connection } } |