Search code examples
azureauthenticationlocalhostazure-powershell

Connect-AzAccount "The connection for this site is not secure" error


I am using Connect-AzAccount to login with Azure PowerShell. First I am brought to this page with a URL like this. I then select my account and continue. It does not prompt me for my password because of what I assume is SSO.

https://login.microsoftonline.com/organizations/oauth2/v2.0/authorize?scope=https%3a%2f%2fmanagement.core.windows.net%2f%2f.default+openid+profile+offline_access&response_type=code&
client_id=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX&
redirect_uri=http%3a%2f%2flocalhost%3a8400%2f&
claims=%7b%22access_tokenXXXXXXXXXXXXXXXXXXXXXXXXvaluesXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX&
client-request-id=XXXXXXXXXXXXXXXXXXXXXXX&
x-client-SKU=MSAL.NetCore&
x-client-Ver=4.49.1.0&
x-client-CPU=x64&
x-client-OS=Microsoft+Windows+10.0.22621&
prompt=select_account&
code_challenge=XXXXXXXXXXXXXXXXXXXXX&
code_challenge_method=S256&
state=XXXXXXXXXXXXXXXXXXX&client_info=1&sso_nonce=XXXXXXXXXXXXXXXXXXXXXXXXXXXXX&mscrid=XXXXXXXXXXXXXXXXXXXXXXX&login_hint=MYNAME%40EMAIL.com

enter image description here

Then I brought to this page where I am facing the error.

https://localhost:8400/?code=XXXXXXXXXXX
&client_info=XXXXXX
&state=XXXXXXXXXXXXX
&session_state=XXXXXXXXXXXXX

enter image description here


Solution

  • Need to check below:

    • Before attempting to authenticate again, clear your browser's cache and cookies.
    • Update the Az module using Update-Module -Name Az.
    • Check to see if any firewalls are preventing access to the redirect URL or the local host that you are using.
    • The redirect URI in your App registration should match the redirect_uri argument in your PowerShell authentication request (http/https and port number, if appropriate).
    • Try authenticating using different browser if Edge is not working.

    After checking all the above, I tried connecting to Az account with the relevant
    connect-AzAccount command and it worked as shown.

    enter image description here

    enter image description here