Specific endpoint configuration for Blazor web static files and render mode-endpoints #60138
Labels
area-blazor
Includes: Blazor, Razor Components
design-proposal
This issue represents a design proposal for a different issue, linked in the description
Milestone
Summary
A solution for #51836 - where authorization is applied to the endpoint for
_framework/blazor.web.js
via FallbackPolicy - by providing a way to specificy e.g.AllowAnonymous
on the endpoints added withinMapRazorComponents<>
.Motivation and goals
Similar to the linked issue, we're integrating a custom
IAuthorizationPolicyProvider
where both the FallbackPolicy and the DefaultPolicy will deny access to everyone - just so that no endpoint can be publically accessible by accident, only by explicitly specifyingAllowAnonymous
on that endpoint.Right now, we can adjust any endpoints via the conventions by e.g. calling
app.MapControllers().Add(eb => AddSomeMetadataWeNeed(eb))
where needed, but this falls short with both the static files-endpoint for_framework/blazor.web.js
and the endpoints registered for specific rendermodes such as InteractiveServer. We can make do by filtering the specific paths in ourIAuthorizationHandler
, but this just feels wrong, you know?In scope
_framework/blazor.web.js
IComponentRenderMode
Out of scope
Risks / unknowns
Since the endpoints are exposed for configuration, things might break down in horrible ways - which was the intial reasoning for moving
blazor.web.js
away from the usualUseStaticFiles
into its own endpoint, as far as I understood.Things might also get confusing because there'd be three possible ways to define conventions:
Examples
Typically, the endpoints are configured using the
IEndpointConventionBuilder
returned by e.g.MapGet
. This can be done forMapRazorComponents<>
as well, but these conventions apply to all endpoints, including the routed components.To make a clear distinction, I'd introduce a new method on the
RazorComponentsEndpointConventionBuilder
as well as a parameter on (at least)AddInteractiveServerRenderMode
to configure the static file and the rendermodes:I'm not feeling very inspired on the naming, but that's the gist of it. I initially thought about adding the configuration for static files as parameter to
MapRazorComponents<>
, but I feel like that'd be to implicit when omitting the parameter name.It might be interesting to also allow configuration specific for the routed components. That's not a case for us, but doing it via parameter in
MapRazorComponents<>
feels like the perfect place for that.With some overloads, this can be done non-breaking, which is very nice. It's out of the way until you actually need it, since all of this is a rather niche case after all.
The text was updated successfully, but these errors were encountered: