question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Blazor WASM application hangs on MSAL Authentication.

See original GitHub issue

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

Same as #38653. When using MSAL authentication in a Blazor WASM application, the login page hangs on the pop-up. Opening the browser’s (specifically Chrome) developer tools causes the pop-up to stop hanging and proceed as normal. Our application was created from the Blazor WASM (PWA) template, no modifications have been done to any of the PWA related scripts.

Expected Behavior

The pop-up shouldn’t hang at all, regardless of whether the developer tools are open or not.

Steps To Reproduce

To get the issue (it’s intermittent as noted in here) we just click our sign-in button, the pop-up appears and just sits there. When this happens, opening the browser’s developer tools does something and causes the pop-up to proceed and close.

// Program.cs
builder.Services
    .AddMsalAuthentication<RemoteAuthenticationState, CustomUserAccount>(options =>
    {
        builder.Configuration.Bind("AzureAd", options.ProviderOptions.Authentication);
        options.ProviderOptions.DefaultAccessTokenScopes.Add("https://graph.microsoft.com/openid");
        options.UserOptions.RoleClaim = "http://schemas.microsoft.com/ws/2008/06/identity/claims/role";
    })
    .AddAccountClaimsPrincipalFactory<RemoteAuthenticationState, CustomUserAccount, CustomUserFactory>();

I can provide more details directly to whoever needs to look at it.

Exceptions (if any)

No response

.NET Version

5.0

Anything else?

IDE: Visual Studio 2022 (2019 also seeing the same issue). Output of dotnet --info:

$ dotnet --info
.NET SDK (reflecting any global.json):
 Version:   6.0.100
 Commit:    9e8b04bbff

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.19042
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\6.0.100\

Host (useful for support):
  Version: 6.0.0
  Commit:  4822e3c3aa

.NET SDKs installed:
  6.0.100 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 5.0.12 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 5.0.12 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 5.0.12 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 6.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

To install additional .NET runtimes or SDKs:
  https://aka.ms/dotnet-download

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:3
  • Comments:25 (12 by maintainers)

github_iconTop GitHub Comments

3reactions
villodre77commented, May 4, 2022

I could get around myself setting the login mode as ‘Redirect’.

... builder.Services .AddMsalAuthentication<RemoteAuthenticationState, CustomUserAccount>(options => {options.ProviderOptions.LoginMode = "redirect";

3reactions
eamonn-colemancommented, Dec 22, 2021

I can reproduce the problem with this command:

dotnet new blazorwasm -au SingleOrg --api-client-id <guid1> --app-id-uri <guid1> --client-id <guid2> --default-scope my.api.access --domain somedomain.com -ho -o SomeApp --tenant-id <guid3>

First login works. Logout works. Second login hangs.

Opening devtools appears to reliably work around the problem.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Blazor WASM AD Authentication Hangs with Message " ...
The problem occurs with a Blazor WASM App using MSAL and Azure AD authentication. If you press login, the message "Checking Login State....
Read more >
Fixing Blazor WebAssembly .NET 6 MSAL authorization bug
In this particular case, upgrading a Blazor WASM solution to .NET 6 broke the authentication when deployed to Azure.
Read more >
Blazor Wasm Authentication (MSAL): Not waiting for token
I have a standalone Blazor Webassembly app (.NET 6) with authentication implemented with Azure AD, using MSAL.
Read more >
Authentication Hangs...Sometimes : r/Blazor
I've got a blazor web assembly app that I am creating and I am using the out of the box authentication (from the...
Read more >
Blazor Authentication with Blazorade MSAL - An Overview
This article describes how you can implement authentication in your Blazor applications, both on the server and in WebAssembly applications.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found