-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Add support for metadata-only endpoints to support path-based authorization, output caching, etc. #43642
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
I worry about examples like these, and user not understand the blast radius of making a change: // Disable authorization for all requests under /public
app.AllowAnonymous("/public"); If my mental model is correct this does define an endpoint, and that endpoint would be a candidate for path matching along with all the other endpoints, including the ability to cause ambiguities (HTTP 500). Basically these features will only work the way you when they don't overlap with other endpoints in your app. The sample here with So my feedback is that this feels like it's going to be misunderstood. It puts a lot of burden on the user to understand what happens behind the scenes. Take this example (modified from yours): // Disable authorization for all requests under /public
app.AllowAnonymous("/public");
// Cache all requests under /public
app.CacheOutput("/public"); What happens? I think most users would expect paths under |
@rynowak the ambiguities are resolved via a custom Edit: metadata-only endpoints can be selected as the match during routing, but only in the case there are no other candidates available. When they do match, they have a null handler, so while there's an active endpoint for the request to carry the metadata, there's no request delegate to execute. |
It seems like this feature lends itself nicely to the design of "route-based endpoint conventions" given that "metadata-only endpoints" doesn't apply exclusively to routes that do not map to an endpoint handler. Looking through this particular example: // Authorize all requests under /users
app.RequireAuthorization("/users"); I wonder how this feature would intersect with route groups. When and why would a user use the syntax above when they could also do: var users = app.MapGroup("/users");
users.RequireAuthorization(); Is the assumption that route group-based conventions would intersect with "metadata-only endpoints" in some way via the implementation?
How common are these types of endpoints? Static file support seems like a big one. Are there other scenarios in app where a path is not going to be tied to a handler? |
One would use Ultimately, the metadata on metadata-only endpoints (MOE) applies to any request that matches the route pattern for the MOE, which for the cases outlined would almost certainly include greedily capturing any sub-path. This is true whether there are actual endpoints in play or not, so they interact in that they compose, i.e. the metadata from the MOE is copied to the actual endpoint (in the prototype implementation the endpoint is actually replaced by the
Hard to say. Prior to ASP.NET Core 3.0 it was everything that was request-handling. Anything that didn't move to be endpoint-based would count, and I think things like Swashbuckle still use terminal middleware too. |
Thanks for contacting us. We're moving this issue to the |
Thanks for contacting us. We're moving this issue to the |
Related #43352
There are scenarios where it is desirable to affect the behavior of endpoint-aware middleware that runs in a request pipeline that will be handled by a non-endpoint-aware middleware (rather than an actual endpoint) such that the endpoint-aware middleware performs its operations as if the request-handling middleware were actually an endpoint.
For example, the static files middleware handles requests but does not do so via endpoints. Rather, it is a terminal middleware for requests with paths that map to static files in the configured file provider. The authorization middleware is an endpoint-aware middleware that uses metadata from the current request endpoint to perform authorization actions and will no-op for requests with no active endpoint. This means that one can't use the authorization middleware to enforce authorization for static files. The output cache middleware is similar.
The repo AspNetCorePathAuthorization demonstrates a concept of "metadata-only endpoints" that allows endpoints to be registered that have only metadata, and no actual endpoint handler. These endpoints only exist for the purpose of effectively adding metadata to arbitrary route paths, either adding metadata to existing real endpoints, or providing metadata for requests with no real endpoint but with a matching path. This metadata can then be used by endpoint-aware middleware to perform operations relevant for the current request.
An example of what this API could look like:
Higher level APIs like Authorization and Output Caching could be updated to leverage this with new top-level APIs for configuring authorization and output caching based on path, e.g.:
The text was updated successfully, but these errors were encountered: