Azure / Azure/azure-powershell

Connect-azaccount using SP giving an error when running with proxy

Open
#27,221 11 comments 0 reactions 0 assignees View on GitHub
customer-reported needs-team-attention question
Dominant language
C#
Stars
4.8k
Forks
4.3k
Avg merge
2d 17h
Merged PRs (30d)
51

Description

### Description

here is the command cx running - Connect-AzAccount -ServicePrincipal -TenantId $TenantId -Credential $Credential -Subscription $subscriptionId -debug

Cx running on a machine (WS 2016) which are behind proxy.
Before running the above command, he is setting the proxy on PS 7.4 as below.

```powershell
$proxyurl = 'proxyurl:8080'
$proxyuser = 'corpau\accountname'
# $proxyuser = 'accountname'
$proxypassword = 'password'

$proxy_ps7 = "http://$proxyuser" +":"+"$proxypassword"+"@"+"$proxyurl"
$env:HTTP_PROXY=$proxy_ps7
$env:HTTPS_PROXY=$proxy_ps7
```

It seems token retrieval is successful but it failed with the following error.
Connect-AzAccount: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. (management.azure.com:443)

But same command works fine in PS 5.1 on another WS 2016 server behind the same proxy and same version of Az module. here is the sample script for setting proxy on PS 5.1.

```powershell
$proxyurl = ''
$proxyuser = ''
$proxypassword = $password
$proxysecrepw = ConvertTo-SecureString -String $proxypassword -AsPlainText -Force
$proxycredential = New-Object System.Management.Automation.PSCredential($proxyuser, $proxysecrepw)
$proxy = New-Object System.Net.WebProxy($proxyurl)
$proxy.Credentials = $proxycredential
[System.Net.WebRequest]::defaultWebProxy = $proxy
```

From the debug log, i noticed the only different is .net version is different in both scenarios.

Please help how to resolve this issue in PS 7.4 with proxy.

Non-working scenario: [AzAccountConnect_2.log](https://github.com/user-attachments/files/18959800/AzAccountConnect_2.log)

Working scenario: [goodnode_ps5.1.txt](https://github.com/user-attachments/files/18959814/goodnode_ps5.1.txt)

### Script or Debug output

```PowerShell

```

### Environment data

```PowerShell
PSVersion: 7.4.0
```

### Module versions

```PowerShell
Az.Accounts:4.0.1
```

### Error output

```PowerShell

```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.