What is the difference between role-based and claims-based authorization in ASP.NET Core?
Short answer
Role-based authorization ([Authorize(Roles = "Admin")]) checks whether the user's ClaimsPrincipal has a role claim matching one of the specified roles -- a simple, coarse-grained check.
Advertisement
AModel answer
Role-based authorization ([Authorize(Roles = "Admin")]) checks whether the user's ClaimsPrincipal has a role claim matching one of the specified roles -- a simple, coarse-grained check. Claims-based authorization checks for the presence (and optionally the value) of any specific claim type, offering finer-grained control since claims can represent arbitrary attributes beyond just roles (like a subscription tier, department, or permission level).
// Role-based
[Authorize(Roles = "Admin")]
public IActionResult DeleteUser(int id) { ... }
// Claims-based (via policy)
builder.Services.AddAuthorization(options => {
options.AddPolicy("PremiumOnly", policy => policy.RequireClaim("subscription", "premium"));
});Real-world example
An e-commerce platform uses role-based authorization for admin functions (Admin, Support roles) but claims-based policies for feature access (checking a 'subscription' claim's value) since subscription tiers aren't naturally modeled as roles.
Likely follow-ups
- How is a role technically implemented as just a special kind of claim internally?
- When does claims-based authorization become preferable to role-based?
Related topics