codementor on Nostr: Learn: Authentication vs authorization Authentication: who are you? (login, a cookie, ...
Learn: Authentication vs authorization
Authentication: who are you? (login, a cookie, a token)
Authorization: what may you do? (roles, policies)
On a protected endpoint: no valid login → 401; logged in but not allowed → 403. (Cookie login redirects web pages to a login page; since .NET 10, API endpoints get 401/403.)
```csharp
var identity = new ClaimsIdentity(new[] { new Claim(ClaimTypes.Name, "ann"), new Claim(ClaimTypes.Role, "Admin") }, "demo");
var user = new ClaimsPrincipal(identity);
Console.WriteLine($"{user.Identity!.IsAuthenticated} {user.IsInRole("Admin")} {user.IsInRole("Billing")}");
```
It prints True True False. IsAuthenticated is true only because an authentication type ("demo") was given. ASP.NET Core builds this ClaimsPrincipal for every request (HttpContext.User).
Read more:
https://learn.microsoft.com/en-us/aspnet/core/security/authentication/#tip · TIP-083
Published at
2026-10-15 11:08:03 UTCEvent JSON
{
"id": "2a5fb46fc2a4e2896ce32d28fe446139aeb9ee9049885c6d37af50a7efdd573f",
"pubkey": "e68a0856e90d9997b1f721e905249896412dd570399a987b2e8fd5e7fcfe2279",
"created_at": 1792062483,
"kind": 1,
"tags": [
[
"t",
"tip"
]
],
"content": "Learn: Authentication vs authorization\n\nAuthentication: who are you? (login, a cookie, a token)\nAuthorization: what may you do? (roles, policies)\nOn a protected endpoint: no valid login → 401; logged in but not allowed → 403. (Cookie login redirects web pages to a login page; since .NET 10, API endpoints get 401/403.)\n\n```csharp\nvar identity = new ClaimsIdentity(new[] { new Claim(ClaimTypes.Name, \"ann\"), new Claim(ClaimTypes.Role, \"Admin\") }, \"demo\");\nvar user = new ClaimsPrincipal(identity);\nConsole.WriteLine($\"{user.Identity!.IsAuthenticated} {user.IsInRole(\"Admin\")} {user.IsInRole(\"Billing\")}\");\n```\n\nIt prints True True False. IsAuthenticated is true only because an authentication type (\"demo\") was given. ASP.NET Core builds this ClaimsPrincipal for every request (HttpContext.User).\n\nRead more: https://learn.microsoft.com/en-us/aspnet/core/security/authentication/\n\n#tip · TIP-083",
"sig": "e3d64e2904711d8f27f29570a4c7ea7908b7d258e2d6a80c82a457eb03d17af82041519468ada625e0e8f251688b3523789b17d6b670608867e24e1c24aaff30"
}