Claims and ClaimsPrincipal
noun
say it: “KLAYMZ and KLAYMZ PRIN-sih-pul” /kleɪmz ænd kleɪmz ˈprɪnsɪpəl/
Claims are facts about the signed-in user, such as name and role; the ClaimsPrincipal holds them as HttpContext.User.
What is Claims and ClaimsPrincipal?
A claim is one fact about the user (their ID, email, role). ClaimsPrincipal (HttpContext.User) holds all of them for the current request.
app.MapGet("/me", (ClaimsPrincipal user) =>
new { Id = user.FindFirstValue(ClaimTypes.NameIdentifier), IsAdmin = user.IsInRole("Admin") });
In a sentence
- “The user's claims include their name and the Admin role.”
Level: Journeyman · More ASP.NET Core terms at this level
Updated