Claims-based authorization
A claim is a key-value pair associated with identity after successful authentication. A claim can be a date of birth, gender, or zip code, for example. One or more claims can be assigned to a user. Claims-based authorization uses the value of a claim and determines whether access to a resource can be granted or not. You can use two approaches to validate a claim; one way is to just check whether the claim exists or not and the other approach is to check whether the claim exists with a particular value.
To use claims-based authorization, we need to register a policy in Program.cs. You need to pass a claim name and optional values to the RequireClaim method to register. For example, the following code registers PremiumContentPolicy with the requirement of the PremiumUser claim:
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddAuthorization(options =>
{
options.AddPolicy("PremiumContentPolicy...