AppUserBase Class
Helper class that consolidates access to Claims and Authentication features more easily. Subclass this class and add specific properties with Getters to retrieve data out of the user claims, roles and settings.
Westwind.AspNetCore.Security.AppUserBase
Remarks
Create an application specific class that inherits from AppUserBase and uses specific claims retrieved as property values:
public class AppUser : AppUserBase
{
public AppUser(ClaimsPrincipal user) : base(user) { }
public string Email => GetClaim("Username");
public string Fullname => GetClaim("Fullname");
public string UserId => GetClaim("UserId");
public bool IsAdmin => HasRole("Admin");
}
retrieves a user from ClaimsPrincipal with your own implementation.
public static class ClaimsPrincipalExtensions
{
public static AppUser GetAppUser(this ClaimsPrincipal user)
{
return new AppUser(user);
}
}
Class Members
Member | Description | |
---|---|---|
![]() |
Constructor | |
![]() |
AddClaim | Add a claim to the user (use this if multiple claims for the same setting can be set)
public void AddClaim(string claimName, string value)
|
![]() |
AddOrUpdateClaim | Adds or updates a claim for the user. Use this for unique claims
public void AddOrUpdateClaim(string claimName, string value)
|
![]() |
AddRole |
public void AddRole(string userRole)
|
![]() |
GetClaim | Helper to retrieve a claim by name on the current logged in user
public string GetClaim(string claimName)
|
![]() |
HasRole | Checks if a role exists
public bool HasRole(string role)
|
![]() |
IsAuthenticated | Checks if the user is authenticated
public bool IsAuthenticated()
|
![]() |
IsEmpty | Checks to see if the user identity is set
public bool IsEmpty()
|
![]() |
LoginUser | Logs in a user with Cookie Authentication
public void LoginUser(HttpContext context, ClaimsIdentity identity)
|
![]() |
LoginUserAsync | Logins a user with Cookie Authentication
public Task LoginUserAsync(HttpContext context, ClaimsIdentity identity)
|
![]() |
LogoutUser | Logs out a user with Cookie Authentication
public void LogoutUser(HttpContext context)
|
![]() |
LogoutUserAsync | Logs out a user with Cookie Authentication
public Task LogoutUserAsync(HttpContext context)
|
![]() |
RemoveClaim | Removes a claim from the claims collection
public void RemoveClaim(string claimName)
|
![]() |
Claims | The list of claims for this user |
![]() |
HttpContext | Optionally set Http Context which is needed for Cookie accessto properties |
![]() |
User | The underlying user |
Assembly: Westwind.AspNetCore.dll
© West Wind Technologies, 2025 • Updated: 2025-03-08
Comment or report problem with topic