Currently, I have applied RequiredAuthorization method on each endpoints as below
endpoints.MapPost($"{ProductsConfigs.ProductsPrefixUri}", CreateProducts)
.WithTags(ProductsConfigs.Tag)
.RequireAuthorization()
.Produces<CreateProductResult>(StatusCodes.Status201Created)
.Produces(StatusCodes.Status401Unauthorized)
.Produces(StatusCodes.Status400BadRequest)
.WithName("CreateProduct")
.WithDisplayName("Create a new product.");
and I have lot of endpoints ex:
endpoints.MapCreateProductsEndpoint()
.MapDebitProductStockEndpoint()
.MapReplenishProductStockEndpoint()
.MapGetProductByIdEndpoint()
.MapGetProductsViewEndpoint();
And I know, I want to apply RequiredAuthorization method for each endpoints. Would like to know is there way to apply RequirementAuthorization for all these endpoints in one place. I have other set of endpoints where I don't want to apply RequireAuthroization method as well just for your information.
Please suggest the right approach.