@@ -35,36 +35,45 @@ function Get-ServiceNowAuth {
3535 $hashOut.Headers = @ {
3636 ' Authorization' = ' Bearer {0}' -f $ServiceNowSession.AccessToken.GetNetworkCredential ().password
3737 }
38- } else {
39- $hashOut.Credential = $ServiceNowSession.Credential
38+ }
39+ else {
40+ # issue 248
41+ $pair = ' {0}:{1}' -f $ServiceNowSession.Credential.UserName , $ServiceNowSession.Credential.GetNetworkCredential ().Password
42+ $hashOut.Headers = @ { Authorization = ' Basic ' + [System.Convert ]::ToBase64String([System.Text.Encoding ]::ASCII.GetBytes($pair )) }
4043 }
4144
4245 if ( $ServiceNowSession.Proxy ) {
4346 $hashOut.Proxy = $ServiceNowSession.Proxy
4447 if ( $ServiceNowSession.ProxyCredential ) {
4548 $hashOut.ProxyCredential = $ServiceNowSession.ProxyCredential
46- } else {
49+ }
50+ else {
4751 $hashOut.ProxyUseDefaultCredentials = $true
4852 }
4953 }
50- } elseif ( $Connection ) {
54+ }
55+ elseif ( $Connection ) {
5156 Write-Verbose ' connection'
52- $SecurePassword = ConvertTo-SecureString $Connection .Password - AsPlainText - Force
53- $Credential = New-Object System.Management.Automation.PSCredential ( $Connection.Username , $SecurePassword )
54- $hashOut.Credential = $Credential
57+ # issue 248
58+ $pair = ' {0}:{1} ' -f $Connection.Username , $Connection .Password
59+ $hashOut.Headers = @ { Authorization = ' Basic ' + [ System.Convert ]::ToBase64String([ System.Text.Encoding ]::ASCII.GetBytes( $pair )) }
5560 $hashOut.Uri = ' https://{0}/api/now/v1' -f $Connection.ServiceNowUri
56- } elseif ( $env: SNOW_SERVER ) {
61+ }
62+ elseif ( $env: SNOW_SERVER ) {
5763 $hashOut.Uri = ' https://{0}/api/now' -f $env: SNOW_SERVER
5864 if ( $env: SNOW_TOKEN ) {
5965 $hashOut.Headers = @ {
6066 ' Authorization' = ' Bearer {0}' -f $env: SNOW_TOKEN
6167 }
62- } elseif ( $env: SNOW_USER -and $env: SNOW_PASS ) {
68+ }
69+ elseif ( $env: SNOW_USER -and $env: SNOW_PASS ) {
6370 $hashOut.Credential = New-Object System.Management.Automation.PSCredential($env: SNOW_USER , ($env: SNOW_PASS | ConvertTo-SecureString - AsPlainText - Force))
64- } else {
71+ }
72+ else {
6573 throw ' A ServiceNow server environment variable has been set, but authentication via SNOW_TOKEN or SNOW_USER/SNOW_PASS was not found'
6674 }
67- } else {
75+ }
76+ else {
6877 throw " You must authenticate by either calling the New-ServiceNowSession cmdlet or passing in an Azure Automation connection object"
6978 }
7079 }
0 commit comments