microsoftgraph/msgraph-sdk-powershell

Connect-MgGraph Fails, "Key not valid for use in specified state"

gabrieljtaylor opened this issue ยท 6 comments

Issue Summary:
Connect-MgGraph fails regardless of parameters (or lackthereof) supplied to it, always citing the same error - "Key not valid for use in specified state."

Environment:
Module Version = Microsoft.Graph.* module versions 1.3.1
PowerShell Version(s) = 7.1.1, 5.1.19041.610
Terminals experiencing the issue = Windows Terminal, Visual Studio Code integrated terminal, native Windows cmd.exe terminal
Operating System = Windows 10 version 20H2, OS Build 19042.804

What I've Tried So Far:

  • I've tried Connect-MgGraph (and the alias Connect-Graph) with no parameters at all, with Scopes provided, with TenantId provided, with ForceRefresh provided, and combinations thereof, in every terminal and PS version listed above, and the same error is always generated.
  • I've tried changing the profile from v1.0 to beta via Set-MgProfile; the results are the same.
  • I've tried running Disconnect-MgGraph to make sure nothing is cached, receiving the message "No application to sign out from".
  • I've completely uninstalled the module, ensuring the folders and files are all removed, restarted my computer, and reinstalled the module from scratch, same error.

I'm guessing this issue isn't widespread due to the lack of others reporting the issue, but I've not been able to identify what is unique about my situation that is causing the issue. If there is any further data I can share to assist, let me know and I'll do so.
AB#8104

@gabrieljtaylor Please provide us with the output of Connect-Graph -Debug -Verbose

@finsharp - Unfortunately, Connect-Graph -Debug -Verbose was surprisingly unhelpful, just resulting in the same error:

image

What other information can I supply you with?

@gabrieljtaylor I can't repro the bug locally, but this looks like a bug in the authentication library we use - AzureAD/microsoft-authentication-library-for-dotnet#2352. We will bump MSAL to the latest version as part of #534 .

For now, could you try deleting .graph folder in C:\Users\{Your-UserName}\ and try again.

@peombwa - deleting the .graph folder did the trick - after doing so and restarting PowerShell, Connect-MgGraph behaved normally and prompted for device login as expected. Thank you very much!

@peombwa - deleting the .graph folder did the trick - after doing so and restarting PowerShell, Connect-MgGraph behaved normally and prompted for device login as expected. Thank you very much!

thanks for the tip !
.graph folder is in the userprofile folder ;)

Wow, seems like this bug is still not fixed, I am having the same issue, and only the .graph folder deletion helped :(