Connect-AzAccount command not executing in Sapien GUI Application

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Locked
ajkundna
Posts: 4
Last visit: Thu Aug 20, 2020 10:46 am

Connect-AzAccount command not executing in Sapien GUI Application

Post by ajkundna »

Hello

I am trying to convert my GUI application from AzureRm to Az module. I've re-compiled the code successfully. However, when GUI is executing step Connect-AzAccount, after login prompt it simply freezes. i.e. it prompts for Azure login/MFA but after successful authentication it just stays as-is.

If i use AzureContext.json file as login, then other Az commands work fine in application. So issue is specific to Connect-AzAccount. I found below issue over github which might be related.
https://github.com/Azure/azure-powershell/issues/8476

Is anyone else experiencing similar issue and if any workaround available?

Thank You
Ajay Kundnani

jvierra
Posts: 14704
Last visit: Sat Feb 27, 2021 5:46 am
Answers: 8
Has voted: 2 times
Been upvoted: 6 times

Re: Connect-AzAccount command not executing in Sapien GUI Application

Post by jvierra »

From GitHub the issue appears to be with the module and will have to wait for a fix to be released as noted in the bug report.

ajkundna
Posts: 4
Last visit: Thu Aug 20, 2020 10:46 am

Re: Connect-AzAccount command not executing in Sapien GUI Application

Post by ajkundna »

Thanks Jvierra

Checking if others might be facing similar issue or if any workaround available perhaps

salient
Posts: 5
Last visit: Wed Feb 03, 2021 1:30 pm

Re: Connect-AzAccount command not executing in Sapien GUI Application

Post by salient »

I am also seeing the hanging form issue when using Connect-AzAccount -Credentials $creds.
I am using Az 2.8.0 with Ac.Accounts 1.6.3 module.

Using Connect-AzAccount -UseDeviceAuthentication shows the url in the output which then works if the code is entered into the browser. Not really a solution but it shows that authentication is otherwise working.

jvierra
Posts: 14704
Last visit: Sat Feb 27, 2021 5:46 am
Answers: 8
Has voted: 2 times
Been upvoted: 6 times

Re: Connect-AzAccount command not executing in Sapien GUI Application

Post by jvierra »

According to GitHub project this appears to be being addressed, There have been a number of bug posts concerning this and other issues with the module hanging.

salient
Posts: 5
Last visit: Wed Feb 03, 2021 1:30 pm

Re: Connect-AzAccount command not executing in Sapien GUI Application

Post by salient »

I've come up with a crude workaround:

if (Test-Path -Path 'C:\temp\azcontext.json')
{
$null = Import-AzContext -Path 'C:\temp\azcontext.json'
}
else
{
$connectazaccount = { Save-AzContext -Profile (Connect-AzAccount -Credential $using:credentials) -Path 'C:\temp\azcontext.json' }
$null = Start-Job -ScriptBlock $connectazaccount -Name 'connectazaccount'
while ((Get-Job -Name 'connectazaccount').State -eq 'Running') { Start-Sleep -Seconds 1 }
$null = Import-AzContext -Path 'C:\temp\azcontext.json'
$null = Remove-Job -Name 'connectazaccount' -Force -ErrorAction SilentlyContinue
}

ajkundna
Posts: 4
Last visit: Thu Aug 20, 2020 10:46 am

Re: Connect-AzAccount command not executing in Sapien GUI Application

Post by ajkundna »

Thanks Salient, this will work for organizational account right, does it supports MFA as well?

I'll test it out from my side too. I am currently also testing -UseDeviceAuthentication along with Az.Accounts v2.0.0-preview. Will post results how it goes.

Thanks !

ajkundna
Posts: 4
Last visit: Thu Aug 20, 2020 10:46 am

Re: Connect-AzAccount command not executing in Sapien GUI Application

Post by ajkundna »

Hello

Quick update, i tested the scriptblock method with no luck. UseDeviceAuthentication I had very little hope either way since it generates code in Shell window which needs to be inserted then manually in browser.

Any additional thoughts please?

Thanks
Ajay

Locked