dotnet / dotnet/aspnetcore

Custom Authorization Attributes on Min APIs

Open
#44,783 18 comments 0 reactions 0 assignees View on GitHub
area-auth area-minimal enhancement
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 5h
Merged PRs (30d)
276

Description

### Is there an existing issue for this?

- [X] I have searched the existing issues

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

On our legacy ApiControllers, we have our own customer Authorization Attributes, for instance:

[FeatureAuthorize(Features.ManageRegions]

We would like to apply the same to MinAPI, both with attributes and fluent

### Describe the solution you'd like

app.MapGet("/login", [FeatureAuthorize(Features.ManageRegions] () => "This endpoint is those users with this feature assigned.");

app.MapGet("/login2", () => "This endpoint also requires this feature.")
.FeatureAuthorize(Features.ManageRegions);

I guess the former might work out of the box... but how would the latter be accomplished, i.e. a fluent syntax for associating a customer authorization attribute with a Map call (via an extension method).

### Additional context

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.