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.
This topic is 4 years and 4 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
ajkundna
Posts: 7
Last visit: Fri Jul 30, 2021 12:47 pm

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: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 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: 7
Last visit: Fri Jul 30, 2021 12:47 pm

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
b_warren
Posts: 11
Last visit: Tue Jan 09, 2024 9:48 am

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

Post by b_warren »

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: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 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.
b_warren
Posts: 11
Last visit: Tue Jan 09, 2024 9:48 am

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

Post by b_warren »

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: 7
Last visit: Fri Jul 30, 2021 12:47 pm

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: 7
Last visit: Fri Jul 30, 2021 12:47 pm

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
This topic is 4 years and 4 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked