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.

.NET 7 Blazor WASM authentication back button history behavior still problematic with 3rd party IDP

See original GitHub issue

Summary

.NET 7 improved Blazor WASM’s authentication back history behavior in pull #43954. The underlying issue was described in issue #43063 @javiercn

However, after testing the new implementation, I’m still not getting the desirable behavior: back button returns to previous page that does not require authentication.

Motivation and goals

Consider the following typical scenario:

  1. User is currently on contoso.com, an unprotected Blazor home page.
  2. User clicks a link on the page, contoso.com/protected, which is a protected Blazor page via @attribute [Authorize]
  3. The app.razor sees that this is a protected route, and redirects user to contoso.com/Authentication/login via the RedirectToLogin Blazor component.
  4. The authentication component in turn redirects the user to a 3rd party IDP login page, such as AAD B2C’s contoso.b2clogin.com.
  5. Now user realizes this is a protected area, but decides not to sign up or login, and presses the back button, with the intent to go back to the unprotected contoso.com home page.

However, in reality, the back button brings the user to contoso.com/protected, which then redirects the user to /Authentication/login and finally the IDP login page again, still resulting in a loop.

I believe this is a bit better than the previous version, where the back button would bring the user to /Authentication/login which would trigger a failure message.

But I think it would be a much better experience if the new history state manager can store the URL the user was on before the protected page was requested that triggered authentication, and bring the user to that page accordingly when back button is clicked.

Issue Analytics

  • State:closed
  • Created 10 months ago
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
javiercncommented, Nov 17, 2022

The remaining work here is to add an overload that takes a boolean we apply to ReplaceHistoryEntry

1reaction
javiercncommented, Nov 17, 2022

The only difference with the code you showed me was to add the ReplaceHistoryEntry = true, right? This part confused me because I thought #43954 mentioned history is replaced by default in the new version, but now I guess that was referring to to the internal implementation of the authentication JS?

Yep.

I personally think the final behavior I proposed and you helped me achieve here should be the “ideal” default, out-of-the-box behavior for most use cases (avoiding authentication loop via back button press), that could warrant a documentation/default code update. What do you think?

I would be ok if we add this option to the helper methods, but I do not think is the correct default. That works when some part of your app does not require auth, but it does not when all your app requires authorization.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Authentication in WebAssembly apps - .NET
We updated the support for authentication in Blazor WebAssembly apps to rely on the history state instead of query strings in the URL....
Read more >
what do you find most frustrating about dotnet?
Community Toolkit Markup in C# with MVVM? Comet with MVU? MAUI Blazor Hybrid? WPF? UWP? Personally, I think Microsoft needs to focus on...
Read more >
You're using AuthenticationStateProvider wrong in your Blazor ...
The AuthenticationStateProvider service in in Blazor Server the main point to get information about the authentication state of the current ...
Read more >
Blazor's New LocationChanging Events in .NET 7
With this, we'll see a message in the browser's console (if running Blazor WASM) or our application logs (if Blazor Server) every time...
Read more >
May 2023 Community News
Welcome back! ... NET 7 for Authentication and Authorization ... Support Auth0 in Azure Static Web Apps for Blazor WebAssembly Apps ...
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