azure-powershell icon indicating copy to clipboard operation
azure-powershell copied to clipboard

Improve error message when live id credentials are used with non-interactive login Add-AzureAccount : Sequence contains no elements

Open mwassell opened this issue 10 years ago • 11 comments

Cmdlet(s)

Add-AzureAccount

PowerShell Version

5.1.14393.103

Module Version

2.0.1

OS Version

10.0.14393.103

Description

Using the "Add-AzureAccount" cmdlet with the "-Credential" parameter returns an error.

Debug Output

add-azureaccount : Sequence contains no elements At line:1 char:1

  • add-azureaccount -Credential ( Get-Credential )
  • - CategoryInfo          : CloseError: (:) [Add-AzureAccount], AadAuthenticationFailedException
    - FullyQualifiedErrorId : Microsoft.WindowsAzure.Commands.Profile.AddAzureAccount
    

Script/Steps for Reproduction

PS C:\WINDOWS\system32> add-azureaccount -Credential ( Get-Credential )

mwassell avatar Sep 09 '16 15:09 mwassell

@mwassell Can you try setting $DebugPreference="Continue" and provide the logs?

markcowl avatar Sep 09 '16 16:09 markcowl

DEBUG: 1:02:36 PM - AddAzureAccount begin processing with ParameterSet 'User'. DEBUG: 1:02:36 PM - using account id '[email protected]'... DEBUG: [Common.Authentication]: Authenticating using configuration values: Domain: 'Common', Endpoint: 'https://login.microsoftonline.com/', ClientId: '1950a258-227b-4e31-a9cf-717495945fc2', ClientRedirect: 'urn:ietf:wg:oauth:2.0:oob', ResourceClientUri: 'https://management.core.windows.net/', ValidateAuthrity: 'True' DEBUG: [Common.Authentication]: Acquiring token using context with Authority 'https://login.microsoftonline.com/Common/', CorrelationId: '00000000-0000-0000-0000-000000000000', ValidateAuthori 'True' DEBUG: [Common.Authentication]: Acquiring token using AdalConfiguration with Domain: 'Common', AdEndpoint: 'https://login.microsoftonline.com/', ClientId: '1950a258-227b-4e31-a9cf-717495945fc2', ClientRedirectUri: urn:ietf:wg:oauth:2.0:oob DEBUG: Microsoft.IdentityModel.Clients.ActiveDirectory Information: 2 : DEBUG: 09/09/2016 17:02:36: 370b2292-9875-4afc-a3cd-6de4bac99a99 - AcquireTokenHandlerBase: === Token Acquisition started: Authority: https://login.microsoftonline.com/Common/ Resource: https://management.core.windows.net/ ClientId: 1950a258-227b-4e31-a9cf-717495945fc2 CacheType: Microsoft.Azure.Commands.Common.Authentication.ProtectedFileTokenCache (3 items) Authentication Target: User

DEBUG: Microsoft.IdentityModel.Clients.ActiveDirectory Information: 2 : DEBUG: 09/09/2016 17:02:36: - TokenCache: Deserialized 3 items to token cache. DEBUG: Microsoft.IdentityModel.Clients.ActiveDirectory Verbose: 1 : DEBUG: 09/09/2016 17:02:36: 370b2292-9875-4afc-a3cd-6de4bac99a99 - TokenCache: Looking up cache for a token... DEBUG: Microsoft.IdentityModel.Clients.ActiveDirectory Information: 2 : DEBUG: 09/09/2016 17:02:36: 370b2292-9875-4afc-a3cd-6de4bac99a99 - TokenCache: No matching token was found in the c DEBUG: Microsoft.IdentityModel.Clients.ActiveDirectory Information: 2 : DEBUG: 09/09/2016 17:02:36: 370b2292-9875-4afc-a3cd-6de4bac99a99 - d__0: Sending user realm discovery request to 'https://login.microsoftonline.com/common/UserRealm/[email protected]?api-version=1.0' DEBUG: Microsoft.IdentityModel.Clients.ActiveDirectory Information: 2 : DEBUG: 09/09/2016 17:02:36: 370b2292-9875-4afc-a3cd-6de4bac99a99 - d__4: User with hash '7KgHJwSR6XWhzvrxOYOjrlODVEbPjz8lOwZjbqWdfqs=' detected as 'Federated' DEBUG: Microsoft.IdentityModel.Clients.ActiveDirectory Error: 4 : DEBUG: 09/09/2016 17:02:36: 370b2292-9875-4afc-a3cd-6de4bac99a99 - d__0: System.InvalidOperationException Sequence contains no elements at System.Linq.Enumerable.First[TSource](IEnumerable1 source) at Microsoft.IdentityModel.Clients.ActiveDirectory.MexParser.SetPolicyEndpointAddresses(XContainer mexDocument, IReadOnlyDictionary2 bindings) at Microsoft.IdentityModel.Clients.ActiveDirectory.MexParser.ExtractWsTrustAddressFromMex(XDocument mexDocument, UserAuthType userAuthType, CallState callState) at Microsoft.IdentityModel.Clients.ActiveDirectory.MexParser.d__0.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.IdentityModel.Clients.ActiveDirectory.AcquireTokenNonInteractiveHandler.d__4.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.IdentityModel.Clients.ActiveDirectory.AcquireTokenHandlerBase.d__0.MoveNext() Add-AzureAccount : Sequence contains no elements At line:1 char:1

  • Add-AzureAccount -Credential ( Get-Credential )
  • - CategoryInfo          : CloseError: (:) [Add-AzureAccount], AadAuthenticationFailedException
    - FullyQualifiedErrorId : Microsoft.WindowsAzure.Commands.Profile.AddAzureAccount
    
    

DEBUG: AzureQoSEvent: CommandName - Add-AzureAccount; IsSuccess - False; Duration - 00:00:00.2536870; Exception - Microsoft.Azure.Commands.Common.Authentication.AadAuthenticationFailedException: Sequence contains no elements ---> System.InvalidOperationException: Sequence contains no elements at Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext.RunAsyncTask[T](Task`1 task) at Microsoft.Azure.Commands.Common.Authentication.UserTokenProvider.DoAcquireToken(AdalConfiguration config, PromptBehavior promptBehavior, String userId, SecureString password) at Microsoft.Azure.Commands.Common.Authentication.UserTokenProvider.SafeAquireToken(AdalConfiguration config, ShowDialog showDialog, String userId, SecureString password, Exception& ex) --- End of inner exception stack trace --- at Microsoft.Azure.ServiceManagemenet.Common.ProfileClient.WriteOrThrowAadExceptionMessage(AadAuthenticationException aadEx) at Microsoft.Azure.ServiceManagemenet.Common.ProfileClient.ListSubscriptionsFromServer(AzureAccount account, AzureEnvironment environment, SecureString password, ShowDialog promptBehavior) at Microsoft.Azure.ServiceManagemenet.Common.ProfileClient.AddAccountAndLoadSubscriptions(AzureAccount account, AzureEnvironment environment, SecureString password) at Microsoft.WindowsAzure.Commands.Profile.AddAzureAccount.ExecuteCmdlet() at Microsoft.WindowsAzure.Commands.Utilities.Common.AzurePSCmdlet.ProcessRecord(); DEBUG: Finish sending metric. DEBUG: 1:02:36 PM - AddAzureAccount end processing. DEBUG: 1:02:36 PM - AddAzureAccount end processing.

mwassell avatar Sep 09 '16 17:09 mwassell

It seems that non-interactive flow is not allowed for live id accounts in active directory. Will it ever be possible? The solution for now is to use a proper AD account to login.

alex-mandriko avatar Sep 16 '16 16:09 alex-mandriko

@mwassell @mandrika that is correct, you cannot use the -Credential parameter with live id credentials. This is not our restriction, it is an AD restriction.

Keeping this issue open as we should return a better error message in this case that points you toward possible solutions.

markcowl avatar Sep 26 '16 16:09 markcowl

Description

Verify the error that is returned from ADAL in this case and improive the returned error message to include possible solutions.

Depending on the error, this could include

  • checking your username and passqord
  • noting that liveid credentials cannot be used with non-interactive login
  • [ ] Add live test for new error message
  • [ ] Catch ADAL error appropriately and output improved error message

Cost : 2

markcowl avatar Sep 26 '16 17:09 markcowl

Hi Markcowl, Based on our Infrastructure is using AWS. Which will auto manage the machine instance. this means, If we want to use Application Insights status monitor, we should find out a way to sign in Azure , choose the expected resource and be enable the application which we want to monitor automatically. So I tried to use power shell script to do this. However, I met the above issue.

Can you help to figure out which solution we can use to solve the issue? Or is it viable we can use powershell to do the above steps?

If we cannot use power shell, Is there other way we can choose to sign in Azure and launch AI Status Monitor automatically in AWS VM instance?

LynnJing avatar Nov 08 '16 07:11 LynnJing

the debug log is as below PS C:> $DebugPreference="Continue" PS C:> PS C:> Login-AzureRmAccount -Credential $MyCredential DEBUG: 6:50:30 AM - AddAzureRMAccountCommand begin processing with ParameterSet 'UserWithSubscriptionId'. DEBUG: [Common.Authentication]: Authenticating using configuration values: Domain: 'Common', Endpoint: 'https://login.microsoftonline.com/', ClientId: '1950a258-227b-4e31-a9cf-717495945fc2', ClientRedirect: 'urn:ietf:wg:oauth:2.0:oob', ResourceClientUri: 'https://management.core.windows.net/', ValidateAuthrity: 'True' DEBUG: [Common.Authentication]: Acquiring token using context with Authority 'https://login.microsoftonline.com/Common/', CorrelationId: '00000000-0000-0000-0000-000000000000', ValidateAuthority: 'True' DEBUG: [Common.Authentication]: Acquiring token using AdalConfiguration with Domain: 'Common', AdEndpoint: 'https://login.microsoftonline.com/', ClientId: '1950a258-227b-4e31-a9cf-717495945fc2', ClientRedirectUri: urn:ietf:wg:oauth:2.0:oob DEBUG: Microsoft.IdentityModel.Clients.ActiveDirectory Information: 2 : DEBUG: 11/08/2016 06:50:30: a3e41225-1ea8-4cf6-9e75-24588ddd1164 - AcquireTokenHandlerBase: === Token Acquisition started: Authority: https://login.microsoftonline.com/Common/ Resource: https://management.core.windows.net/ ClientId: 1950a258-227b-4e31-a9cf-717495945fc2 CacheType: Microsoft.IdentityModel.Clients.ActiveDirectory.TokenCache (0 items) Authentication Target: User

DEBUG: Microsoft.IdentityModel.Clients.ActiveDirectory Verbose: 1 : DEBUG: 11/08/2016 06:50:30: a3e41225-1ea8-4cf6-9e75-24588ddd1164 - TokenCache: Looking up cache for a token... DEBUG: Microsoft.IdentityModel.Clients.ActiveDirectory Information: 2 : DEBUG: 11/08/2016 06:50:30: a3e41225-1ea8-4cf6-9e75-24588ddd1164 - TokenCache: No matching token was found in the cach DEBUG: Microsoft.IdentityModel.Clients.ActiveDirectory Information: 2 : DEBUG: 11/08/2016 06:50:30: a3e41225-1ea8-4cf6-9e75-24588ddd1164 - d__0: Sending user realm discovery request to 'https://login.microsoftonline.com/common/UserRealm/[email protected]?api-version=1.0' DEBUG: Microsoft.IdentityModel.Clients.ActiveDirectory Information: 2 : DEBUG: 11/08/2016 06:50:30: a3e41225-1ea8-4cf6-9e75-24588ddd1164 - d__4: User with hash '5tSLpl0+OUdxfaFJ/Sor1qz0wHFaYckIdJ/j06ZvDsg=' detected as 'Federated' DEBUG: Microsoft.IdentityModel.Clients.ActiveDirectory Error: 4 : DEBUG: 11/08/2016 06:50:32: a3e41225-1ea8-4cf6-9e75-24588ddd1164 - d__0: System.InvalidOperationException: Sequence contains no elements at System.Linq.Enumerable.First[TSource](IEnumerable1 source) at Microsoft.IdentityModel.Clients.ActiveDirectory.MexParser.SetPolicyEndpointAddresses(XContainer mexDocument, IReadOnlyDictionary2 bindings) at Microsoft.IdentityModel.Clients.ActiveDirectory.MexParser.ExtractWsTrustAddressFromMex(XDocument mexDocument, UserAuthType userAuthType, CallState callState) at Microsoft.IdentityModel.Clients.ActiveDirectory.MexParser.d__0.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.IdentityModel.Clients.ActiveDirectory.AcquireTokenNonInteractiveHandler.d__4.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.IdentityModel.Clients.ActiveDirectory.AcquireTokenHandlerBase.d__0.MoveNext() Login-AzureRmAccount : Sequence contains no elements At line:1 char:1

  • Login-AzureRmAccount -Credential $MyCredential
  • - CategoryInfo          : CloseError: (:) [Add-AzureRmAccount], AadAuthenticationFailedException
    - FullyQualifiedErrorId : Microsoft.Azure.Commands.Profile.AddAzureRMAccountCommand
    
    

DEBUG: 6:50:32 AM - AddAzureRMAccountCommand end processing. DEBUG: 6:50:32 AM - AddAzureRMAccountCommand end processing. PS C:>

LynnJing avatar Nov 08 '16 07:11 LynnJing

Hi, any update about this? I'm not particularly interested in better error info, because googling helps fortunatelly to find this support issue :)

I'd like just to automate my deployment and because I'm not able to log in with my live id automatically, I'm stuck :/ Is the issue reported further so that hopefully in some future we might log in with live id credentials?

stej avatar Feb 13 '17 11:02 stej

Fix was merged in PR https://github.com/Azure/azure-powershell/pull/3255

cormacpayne avatar Mar 04 '17 01:03 cormacpayne

It fails in 6.0.1. "Sequence Contains no Elements" error after a Connect-AzureRMAccount with a Hotmail.com account :-(

juancrl avatar May 22 '18 18:05 juancrl

Continued in https://github.com/Azure/azure-powershell/issues/3108 A bug or incomplete feature, in my opinion.

juancrl avatar Oct 31 '18 18:10 juancrl