Skip to content

Blazor Auth: Replace history entry on navigating to IdP login/register endpoints to avoid navigation cycle #43063

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
yugabe opened this issue Aug 3, 2022 · 5 comments
Assignees
Labels
area-blazor Includes: Blazor, Razor Components bug This issue describes a behavior which is not expected - a bug. feature-blazor-wasm This issue is related to and / or impacts Blazor WebAssembly
Milestone

Comments

@yugabe
Copy link

yugabe commented Aug 3, 2022

Is there an existing issue for this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe the problem.

I set up my Hosted Blazor WASM application to use Azure B2C following the official guidelines and using a sign up or sign in user flow.

When a user navigates to the authentication/login endpoint (for example, by clicking a link), the history entry for the source URL will be replaced. As the B2C UI doesn't show a link back to the application and the history entry essentially gets rewritten, there is no way to get back to the app without the user either completing a log in OR by typing in a URL in the browser address bar.

Describe the solution you'd like

When a user navigates to the authentication/login or authentication/register endpoints (or triggers these action another way), the source URL of where they navigated from should be stored in the browser's history stack, so that they can go back to the page they came from if they don't wish to complete the sign in/sign up user flow.

Additional context

When a user goes from / to authentication/login, they get redirected to the IdP login page. Pushing the browser's "back" button gets them to authentication/login, which once more redirects them to the IdP login page. The browser's history for this tab at this point will be empty and there will be no way to navigate back to the app without completing the log in flow unless the user types an URL in the address bar.

If the originating URL would be stored in history instead of the page that is redirecting to the IdP, the user would be able to go back to the / page of the application.

@javiercn javiercn added area-blazor Includes: Blazor, Razor Components feature-blazor-wasm This issue is related to and / or impacts Blazor WebAssembly labels Aug 3, 2022
@javiercn
Copy link
Member

javiercn commented Aug 3, 2022

@yugabe thanks for contacting us.

We replace the history entry because the way this works is: From / we always navigate you to authentication/login which automatically starts the login process, which can end in two outcomes:

  • Succeeds: You get redirected back to / or where you came from.
  • Fails before redirect: You are sent to authentication/login-failed.
  • Fails after redirect, when you hit the back button, you want to end up in / or where you were, not in /authentication/login. Otherwise, you end up in an infinite redirect loop.

@yugabe
Copy link
Author

yugabe commented Aug 3, 2022

Thanks @javiercn for the timely reply.

It might have been unclear, but this is not exactly how it plays out. The success and failure branches are okay.

From the IdP, when you press the back button, you get redirected to authentication/login, which in turn redirects you back to the IdP and replaces the previous history entry. Thus, you are unable to navigate back to / using the back button even if you wanted to, because that entry is overwritten. If this is not working as designed, this may rather be a bug than a feature request.

I think when navigating from /wherever-in-app to /authorization/login, which in turn redirects to the IdP, the user should be able to press the back button to go back to /wherever-in-app. Currently, it navigates back to /authorization/login, which is undesirable and if I understand right, incorrect.

@javiercn
Copy link
Member

javiercn commented Aug 3, 2022

@yugabe I think if I remember correctly, we didn't have the choice to do the redirect in msal at the time. I believe the option is there now, so we'll likely be updating that to make sure we replace the history entry.

Ok, so the behavior is that today for AAD and B2C we don't replace the history entry, and we SHOULD replace it, so that you do not end up in /authentication/login when you press the back button.

@yugabe
Copy link
Author

yugabe commented Aug 3, 2022

Ok, so the behavior is that today for AAD and B2C we don't replace the history entry, and we SHOULD replace it, so that you do not end up in /authentication/login when you press the back button.

That is correct -- as per my experiments at least, that's what I'm experiencing.

@mkArtakMSFT mkArtakMSFT changed the title Blazor Auth: Don't replace history entry on navigating to IdP login/register endpoints Blazor Auth: Replace history entry on navigating to IdP login/register endpoints to avoid navigation cycle Aug 3, 2022
@mkArtakMSFT mkArtakMSFT added this to the 7.0-rc2 milestone Aug 3, 2022
@danroth27 danroth27 added the bug This issue describes a behavior which is not expected - a bug. label Aug 24, 2022
@javiercn
Copy link
Member

#43954

@ghost ghost locked as resolved and limited conversation to collaborators Oct 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-blazor Includes: Blazor, Razor Components bug This issue describes a behavior which is not expected - a bug. feature-blazor-wasm This issue is related to and / or impacts Blazor WebAssembly
Projects
None yet
Development

No branches or pull requests

4 participants