Skip to content

Blazor WASM application hangs on MSAL Authentication. #39104

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
1 task done
ghost opened this issue Dec 17, 2021 · 25 comments
Closed
1 task done

Blazor WASM application hangs on MSAL Authentication. #39104

ghost opened this issue Dec 17, 2021 · 25 comments
Assignees
Labels
area-blazor Includes: Blazor, Razor Components feature-blazor-msal This issue is related to MSAL usage in Blazor feature-blazor-wasm This issue is related to and / or impacts Blazor WebAssembly feature-blazor-wasm-auth investigate Needs: Author Feedback The author of this issue needs to respond in order for us to continue investigating this issue. Status: No Recent Activity

Comments

@ghost
Copy link

ghost commented Dec 17, 2021

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
@TanayParikh
Copy link
Contributor

Thank you for filing this issue. In order for us to investigate, please provide a minimal public GitHub project that reproduces this issue.

@TanayParikh TanayParikh added area-blazor Includes: Blazor, Razor Components feature-blazor-wasm This issue is related to and / or impacts Blazor WebAssembly feature-blazor-msal This issue is related to MSAL usage in Blazor feature-blazor-wasm-auth Needs: Author Feedback The author of this issue needs to respond in order for us to continue investigating this issue. labels Dec 17, 2021
@ghost
Copy link

ghost commented Dec 17, 2021

Hi @adam-becker. We have added the "Needs: Author Feedback" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

@ghost
Copy link
Author

ghost commented Dec 17, 2021

Thank you for filing this issue. In order for us to investigate, please provide a minimal public GitHub project that reproduces this issue.

@TanayParikh I will try, might not be able to get to it until next week.

@ghost ghost added Needs: Attention 👋 This issue needs the attention of a contributor, typically because the OP has provided an update. and removed Needs: Author Feedback The author of this issue needs to respond in order for us to continue investigating this issue. labels Dec 17, 2021
@TanayParikh TanayParikh added Needs: Author Feedback The author of this issue needs to respond in order for us to continue investigating this issue. and removed Needs: Attention 👋 This issue needs the attention of a contributor, typically because the OP has provided an update. labels Dec 17, 2021
@ghost
Copy link

ghost commented Dec 17, 2021

Hi @adam-becker. We have added the "Needs: Author Feedback" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

@ghost
Copy link

ghost commented Dec 22, 2021

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment. If it is closed, feel free to comment when you are able to provide the additional information and we will re-investigate.

See our Issue Management Policies for more information.

@eamonn-coleman
Copy link

eamonn-coleman commented 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.

@ghost
Copy link
Author

ghost commented Dec 22, 2021

Thanks @eamonn-coleman! Looks like the same issue I'm seeing.

@ghost ghost added Needs: Attention 👋 This issue needs the attention of a contributor, typically because the OP has provided an update. and removed Needs: Author Feedback The author of this issue needs to respond in order for us to continue investigating this issue. labels Dec 22, 2021
@ghost ghost changed the title Blazor WASM application Hangs on MSAL Authentication. Blazor WASM application hangs on MSAL Authentication. Dec 22, 2021
@mkArtakMSFT mkArtakMSFT removed the Needs: Attention 👋 This issue needs the attention of a contributor, typically because the OP has provided an update. label Jan 3, 2022
@javiercn javiercn added this to the Backlog milestone Jan 10, 2022
@ghost
Copy link

ghost commented Jan 10, 2022

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

@norbythegeek
Copy link

norbythegeek commented Jan 21, 2022

With Edge, if the browser is launched in InPrivate mode, hangs do not occur during authentication. Otherwise yes. .NET 6

@villodre77
Copy link

I'm facing the same issue here. Any workaround or solution on this yet?

@dstretch
Copy link

dstretch commented May 4, 2022

Same problem here :(

@villodre77
Copy link

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

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

@AndreErb
Copy link

AndreErb commented Jun 7, 2022

Same problem here, with the Blazor project being created from default VS2022 (V17.2.3) templates and no additional changes.

Seems to be related to the Popup-Window and "MsalProviderOptions" being on default "LoginMode=popup". The problem occurs only in Chrome (for me) and not in Edge.
The workaround of @villodre77 works for me, too and like @eamonn-coleman wrote the hanging login-popup closes only and as soon as one opens Chrome-DevTools

@ToddEvansHome
Copy link

ToddEvansHome commented Jun 10, 2022

I have the same problem for months now w/ VS2022 v17.2.3 and "LoginMode=popup". A temp workaround I use is to have the Chrome DevTools open prior to login. Not recommended, but another approach was to close and reopen Visual Studio.
I have not tried Edge.

@Roneri75
Copy link

Roneri75 commented Aug 6, 2022

Does not seem to be a difference in browsers, I get it in both Edge and Chrome.
Same problem as everyone else, opening Dev Tools closes the login popup dialog and I get logged in to my App, changing LoginMode to "redirect" like @villodre77 suggested works for me too.
I have 2 or 3 Blazor WASM with no server projects that have the same issue.
.NET 6.0.7, VS Community 2022 v17.1.0

@EricOnGit
Copy link

EricOnGit commented Aug 19, 2022

Same here and the issue is getting worst by the day. Originally (a couple months back), this was happening a couple times a day. Now every debugging cycle takes 2-3 application restarts to eventually get through the login process. The login process gets stuck at /authentication/login-callback#state=... in the popup window.

Like some others are suggesting, I tried opening the dev console prior to the login popup and it worked 10 times in a row. So this might be a workaround until the issue is fixed.

After some more testing, even if it seemed to work for a while, the only viable workaround now is to used the redirect method.

@ghost
Copy link

ghost commented Oct 11, 2022

Thanks for contacting us.
We're moving this issue to the .NET 8 Planning milestone for future evaluation / consideration. Because it's not immediately obvious that this is a bug in our framework, we would like to keep this around to collect more feedback, which can later help us determine the impact of it. We will re-evaluate this issue, during our next planning meeting(s).
If we later determine, that the issue has no community involvement, or it's very rare and low-impact issue, we will close it - so that the team can focus on more important and high impact issues.
To learn more about what to expect next and how this issue will be handled you can read more about our triage process here.

@Hona
Copy link
Contributor

Hona commented Oct 24, 2022

I get this problem too - large application, does a little bit of work on the login event. High CPU usage about 20% ongoing while deadlocked.

@Hona
Copy link
Contributor

Hona commented Oct 24, 2022

	options.ProviderOptions.LoginMode = "redirect";
	options.ProviderOptions.Cache.CacheLocation = "localStorage";

using redirect mode & localStorage

@Hona
Copy link
Contributor

Hona commented Nov 1, 2022

A bit of context for on our Authentication page:

	<RemoteAuthenticatorView Action="@Action" OnLogInSucceeded="@UpdateAuthenticationState" OnLogOutSucceeded="@ClearAuthenticationState">
		<LoggingIn>
			<LoadingSpinner/>
		</LoggingIn>
		<CompletingLoggingIn>
			<LoadingSpinner/>
		</CompletingLoggingIn>
	</RemoteAuthenticatorView>
    public async void UpdateAuthenticationState()
    {
		var authState = await AuthenticationStateTask;
		var user = Application.User.PortalUserAccessor.MapPortalUser(authState);

        await FeatureFlagsClient.GetFeatureFlagsForUserAsync();

        await BusinessContextService.LoadDefaultOrLocalStorageBusinessContext(user);

		PortalUserAccessor.InvokePortalUserChanged();
    }

Here's some minimal snippets.

From lots of poking around with this obscure bug I'm guessing it is when there is long running work on the OnLogInSucceeded callback

@TomDDms
Copy link

TomDDms commented Nov 18, 2022

I have the exact same issue in Google Chrome Mobile. My project is .NET 7.
Authentication flow is stuck on .../authentication/login-callback#code.0.AX.................

it seems to only happen when the #code.... part is added to the call-back. (tried to configure this in Azure Portal, with no luck)
Adding: options.ProviderOptions.LoginMode = "redirect" did not fix my problem.

@Fabster1993
Copy link

Fabster1993 commented Nov 25, 2022

I have the exact same issue in Google Chrome Mobile. My project is .NET 7. Authentication flow is stuck on .../authentication/login-callback#code.0.AX.................

it seems to only happen when the #code.... part is added to the call-back. (tried to configure this in Azure Portal, with no luck) Adding: options.ProviderOptions.LoginMode = "redirect" did not fix my problem.

I have the exact same issue. Flow is stuck on "CompletingLogOut". This seems related to this. For me a fix was, to disable trimming for the app or just disable trimming for the auth assembly:

<ItemGroup>
        <TrimmerRootAssembly Include="Microsoft.AspNetCore.Components.WebAssembly.Authentication" />
</ItemGroup>

@javiercn
Copy link
Member

We think this was addressed as part of the fixes we did in .NET 7.0. Please update to that version and give it another try.

@javiercn javiercn added the Needs: Author Feedback The author of this issue needs to respond in order for us to continue investigating this issue. label Dec 22, 2022
@ghost
Copy link

ghost commented Dec 22, 2022

Hi @adam-becker. We have added the "Needs: Author Feedback" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

@ghost
Copy link

ghost commented Dec 26, 2022

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment. If it is closed, feel free to comment when you are able to provide the additional information and we will re-investigate.

See our Issue Management Policies for more information.

@ghost ghost closed this as completed Dec 29, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Jan 28, 2023
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-blazor Includes: Blazor, Razor Components feature-blazor-msal This issue is related to MSAL usage in Blazor feature-blazor-wasm This issue is related to and / or impacts Blazor WebAssembly feature-blazor-wasm-auth investigate Needs: Author Feedback The author of this issue needs to respond in order for us to continue investigating this issue. Status: No Recent Activity
Projects
None yet
Development

No branches or pull requests