Interface IAuthStatusProvider
- Namespace
- Htmx.Components.AuthStatus
- Assembly
- Htmx.Components.dll
Provides authentication status information for display in authentication status components.
public interface IAuthStatusProvider
- Extension Methods
Examples
public class CustomAuthStatusProvider : IAuthStatusProvider
{
public async Task<AuthStatusViewModel> GetAuthStatusAsync(ClaimsPrincipal user)
{
var userId = user.FindFirst(ClaimTypes.NameIdentifier)?.Value;
var userProfile = await _userService.GetProfileAsync(userId);
return new AuthStatusViewModel
{
IsAuthenticated = user.Identity?.IsAuthenticated ?? false,
UserName = userProfile?.DisplayName,
ProfileImageUrl = userProfile?.AvatarUrl,
LoginUrl = "/Account/Login"
};
}
}
Remarks
Implementations of this interface are responsible for extracting user information from the security context and formatting it for display. This allows applications to customize how authentication status is presented based on their specific authentication systems and user models.
Methods
GetAuthStatusAsync(ClaimsPrincipal)
Gets authentication status information for the specified user.
Task<AuthStatusViewModel> GetAuthStatusAsync(ClaimsPrincipal user)
Parameters
user
ClaimsPrincipalThe user principal to get status information for.
Returns
- Task<AuthStatusViewModel>
A task that represents the asynchronous operation. The task result contains the authentication status view model.
Exceptions
- ArgumentNullException
Thrown when
user
is null.