-
Notifications
You must be signed in to change notification settings - Fork 10.3k
WebApplication.UseStatusCodePages() cannot handle unauthorized requests without explicit UseAuthorization() call #49515
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
Comments
Navigation manager should work (not sure if it does in Preview6). There might be some conflicts with the SSR navigation manager overriding the static renderer one. |
@javiercn OK. Yes. I'm on Preview 6 and it uses the My workaround was to build my own "ServerNavigationManager" (Not inheriting from NavigationManager) which modifies the |
@marinasundstrom where are you seeing the 401 from the authorizeview? On SSR, the auth middleware should be handling the auth for the page. |
@javiercn Here: https://blazor8app.graypebble-0c46426e.westus2.azurecontainerapps.io/auth "/auth" is a page. Unless I have missed something in my code. |
I have learned that the component model doesn't handle the cases the same way with SSR as with Client. That makes sense, since it is about requests. But the symptoms are still here in RC1, somewhere between component and middleware. Not even Still just a page with the text: Component file: https://github.com/marinasundstrom/Blazor8Test/blob/auth/src/Server/Pages/Auth.razor |
To learn more about what this message means, what to expect next, and how this issue will be handled you can read our Triage Process document. |
WebApplication's automatic UseAuthorization() insertion happens before the user-configured UseStatusCodePagesWithRedirecte(). By adding UseAuthorization() explicitly, we can ensure UseStatusCodePagesWithRedirecte() "sees" unauthorized requests. I submitted a PR to your github repo to fix the issue. marinasundstrom/Blazor8Test#3 I don't think this is a Blazor specific issue, but I do wonder if WebApplication could be a little smarter and insert UserAuthorization after UseStatusCodePages if it's being used, because this seems really easy to mess up. I don't want to make the automatic middleware initialization much more complicated than it already is though. |
Uh oh!
There was an error while loading. Please reload this page.
Is there an existing issue for this?
Describe the bug
These are observations from implementing auth with Server-side rendered pages (SSR) in Blazor Preview 6 - using Razor components instead of MVC Razor pages.
Cookie auth just works, that is great. But there are some issues:
Issues:
AuthorizeRouteView
doesn't work with the router. TheNotAuthorized
fragment does not get rendered. Instead I get redirected to a layout-less page saying:Error: 401 Unauthorized
.The
LoginDisplay
doesn't re-ender when logged in using form. Redirecting to another page would help here.Questions:
NavigationManager
of course doesn't work here.My github repo (branch): https://github.com/marinasundstrom/Blazor8Test/tree/auth
Expected Behavior
When unauthorized and entering page that requires authorization,
I expect the
NotAuthorized
fragment to be rendered with theMainLayout
.Steps To Reproduce
https://github.com/marinasundstrom/Blazor8Test/tree/auth
Exceptions (if any)
No response
.NET Version
8.0.100-preview.6.23330.14
Anything else?
No response
The text was updated successfully, but these errors were encountered: