Parameterized authorization policy with IAuthorizationRequirementData interface in WebAPI .NET 8

Опубликовано: 15 Октябрь 2024
на канале: Authorised Territory
56
11

Authorised Territory code examples - This .NET 8 WebAPI tutorial shows how to create parameterized authorization policy with IAuthorizationRequirementData interface.
First, we create AuthorizationAttribute that accepts a parameter followed by AuthorizationHandler which marks the data requirement successful if criteria is met.
Next, we register authentication middleware in Program.cs file and create a controller with an endpoint for testing the new authorization attribute.
Finally, we use user-jwts tool to generate token with a claim which is used for testing via Visual Studio's Endpoint Explorer.