Skip to content

Provide access to parsed route parameters and method body parameters in authorization filters #45698

@KirkMunro

Description

@KirkMunro

Maybe I'm just missing how this should be done, so if that is the case please let me know.

I use authorization filters to ensure that the calling user is authorized to make certain API calls. Sometimes these are simply via claims checks, other times they involve lookups in the database to verify that they have access to invoke the action. In the latter case, route parameters, query parameters, or values in a message body are used as part of the authorization logic. I can make calls within the individual API methods to do authorization, but I also have a unit test that ensures that all API endpoints are appropriately attributed with authorization attributes, and that doesn't pick up on authorization inside the code. I also prefer the authorization logic to be in authorization filters/attributes so that the endpoint logic is focused on what the endpoint is supposed to do.

The issue (which may end up being a feature request) is that it appears that parsing of request inputs (route parameters, query parameters, and message body parameters) has not been completed when an authorization filter is invoked. I can parse the data myself easily enough; however, I don't want to duplicate parsing, and for performance reasons I want input parameter values parsed once and only once.

Is it possible from within an authorization filter to access parsed route parameters, query parameters, and message body parameters? If not, is there an API in ASP.NET Core that can be invoked to do the parsing for the endpoint, such that it is done only once and accessible to an authorization handler? Or is there a better way to do this in another type of authorization filter/middleware that allows me to access inputs and use them for authorization purposes without manually parsing them myself and without duplicating parsing efforts?

I hope this was easy enough to follow. Thanks in advance.

Metadata

Metadata

Assignees

No one assigned

    Labels

    old-area-web-frameworks-do-not-use*DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions