Skip to content

Blazor Wasm MSAL authentication stuck on logging in when msal.js returns "Operation Completed" #43317

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
njannink opened this issue Aug 16, 2022 · 11 comments
Closed
1 task done
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 Needs: Author Feedback The author of this issue needs to respond in order for us to continue investigating this issue.

Comments

@njannink
Copy link

njannink commented Aug 16, 2022

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

In rare cases especially after an update of our Blazor Wasm website with MSAL (Azure B2C) stays stuck on logging-in. It's difficult to reproduce, but I saw it happening on a iPhone with Chrome. What I saw is that the url only consisted of https://xxx.com/authentication/login-callback resulting in the app being stuck on infinite 'logging-in', because with that url the masl.js libarary only returns operation completed which is not handled in the Microsoft.AspNetCore.Components.WebAssembly.Authentication.RemoteAuthenticatorViewCore<TState>.ProcessLogInCallback.

I created the following fix by overriding the 'RemoteAuthenticatorView', but would like to get your opinion about the possible risks\implications of this and maybe this will need to be fixed in the original 'RemoteAuthenticationView' aswell.

public sealed class AuthenticatorViewEx : RemoteAuthenticatorView
{
    [Inject] internal NavigationManager Navigation { get; set; }
    [Inject] internal AuthenticationStateProvider AuthenticationStateProvider { get; set; }

    protected override async Task OnParametersSetAsync()
    {
        await base.OnParametersSetAsync();

        // Fix stuck in login-callback => redirect to home or login
        if (Action == RemoteAuthenticationActions.LogInCallback && Navigation.Uri.Contains($"authentication/{RemoteAuthenticationActions.LogInCallback}", StringComparison.OrdinalIgnoreCase))
        {
            var state = await AuthenticationStateProvider.GetAuthenticationStateAsync();

            if (state.User.Identity is { IsAuthenticated: true })
            {
                Navigation.NavigateTo(Navigation.BaseUri, false, true);
            }
            else
            {
                Navigation.NavigateTo($@"authentication/{RemoteAuthenticationActions.LogIn}");
            }
        }
    }
}

Expected Behavior

No response

Steps To Reproduce

No response

Exceptions (if any)

No response

.NET Version

6.0(.8)

Anything else?

No response

@javiercn javiercn 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 labels Aug 16, 2022
@javiercn javiercn added this to the .NET 7 Planning milestone Aug 16, 2022
@ghost
Copy link

ghost commented Aug 16, 2022

Thanks for contacting us.

We're moving this issue to the .NET 7 Planning milestone for future evaluation / consideration. We would like to keep this around to collect more feedback, which can help us with prioritizing this work. 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.

@mkArtakMSFT
Copy link
Member

Thanks for contacting us.
We've done some improvements in this area during .NET 7. Please try out the latest RC release of .NET 7 and see if you're still experiencing this issue or not.

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

ghost commented Oct 27, 2022

Hi @njannink. 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 Oct 31, 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.

@njannink
Copy link
Author

this is not something that I can easily validate a number of dependencies that we use don't support .net7 so I can't migrate to the RC to retest this issue

@danroth27 danroth27 changed the title Blazor Wasm MSAL authentication stuck on loggin in when msal.js returns "Operation Completed" Blazor Wasm MSAL authentication stuck on logging in when msal.js returns "Operation Completed" Nov 1, 2022
@ghost
Copy link

ghost commented Nov 7, 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 Nov 10, 2022
@ghost
Copy link

ghost commented Nov 20, 2022

Still not fixed! Thanks to @njannink will try you workaround
image

@njannink
Copy link
Author

@ericbrunner my workaround isn't working anymore for net7. I have the idea that the original issue is not occuring anymore, but I did some code review and the "Operation Completed" is still not handled so in theory it could still happen

@ghost
Copy link

ghost commented Nov 21, 2022

@njannink thanks for getting back. I'm already on net7.0 but it still happens in Edge and Chrome browser.
The only workaround is to clear the cache in the browser and then sign-in proceeds.
Would be very kind when you can take a look on my Client project and give me some advice:

BlazorHostedWasmMsal.zip

@njannink
Copy link
Author

I think a new issue needs to be made for this so the guys from MSAL or Blazor can have a look at this problem. Since this issue has already been marked as closed or @mkArtakMSFT should reopen it.

I did not find a good solution either hence the workaround that I used in Net6, but in Net7 I see that this workaround gives unwanted side effects. Its quite annoying and disrupts the user experience of Azure B2C in a blazor wasm app.

@njannink
Copy link
Author

It's actually this issue: #44981

@ghost ghost locked as resolved and limited conversation to collaborators Dec 28, 2022
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 Needs: Author Feedback The author of this issue needs to respond in order for us to continue investigating this issue.
Projects
None yet
Development

No branches or pull requests

4 participants