How to Authorize Endpoint for specific Role
xts-velkumars opened this issue · 1 comments
xts-velkumars commented
@jchannon, Is there any example how to use "RequiresClaims"
I couldn't find any Extension Method for "RequiresClaims" Carter V7.0.0
Basically, I want to achieve below
[Route("/api/users")]
[AuthorizeRole(RoleType.SuperAdmin)]
public async Task<IEnumerable<UsersViewModel>> GetUsers(CancellationToken cancellationToken)
{
return await mediator.Send(new UsersQuery(), cancellationToken);
}
jchannon commented
Use RequireAuthorization
on your route definition or on the module in it's constructor and pass in your roles/policies:
app.MapGet("/", () =>
{
return "Hi";
}).RequireAuthorization();
public DirectorsModule() : base("/directors")
{
this.RequireAuthorization();
}