aspnetcore
aspnetcore copied to clipboard
Blazor WASM application hangs on MSAL Authentication.
Is there an existing issue for this?
- [X] 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
Thank you for filing this issue. In order for us to investigate, please provide a minimal public GitHub project that reproduces this issue.
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.
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.
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.
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.
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.
Thanks @eamonn-coleman! Looks like the same issue I'm seeing.
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.
With Edge, if the browser is launched in InPrivate mode, hangs do not occur during authentication. Otherwise yes. .NET 6
I'm facing the same issue here. Any workaround or solution on this yet?
Same problem here :(
I could get around myself setting the login mode as 'Redirect'.
... builder.Services .AddMsalAuthentication<RemoteAuthenticationState, CustomUserAccount>(options => {options.ProviderOptions.LoginMode = "redirect";
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
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.
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
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.
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.
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.
options.ProviderOptions.LoginMode = "redirect";
options.ProviderOptions.Cache.CacheLocation = "localStorage";
using redirect mode & localStorage
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
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 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>
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.
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.
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.