Table of Contents

Class ManualAuthenticationStateProvider

Namespace
NuvTools.Security.AspNetCore.Blazor
Assembly
NuvTools.Security.AspNetCore.Blazor.dll

Provides a manual implementation of AuthenticationStateProvider that manages user authentication state using JWT tokens stored in browser local storage.

public class ManualAuthenticationStateProvider : AuthenticationStateProvider
Inheritance
ManualAuthenticationStateProvider
Inherited Members

Remarks

This provider enables custom authentication logic in Blazor applications, typically used when not relying on built-in authentication mechanisms like OpenID Connect or Azure AD.

Constructors

ManualAuthenticationStateProvider(ILocalStorageService)

Provides a manual implementation of AuthenticationStateProvider that manages user authentication state using JWT tokens stored in browser local storage.

public ManualAuthenticationStateProvider(ILocalStorageService storage)

Parameters

storage ILocalStorageService

Remarks

This provider enables custom authentication logic in Blazor applications, typically used when not relying on built-in authentication mechanisms like OpenID Connect or Azure AD.

Properties

CurrentUser

Gets the current authenticated user.

public ClaimsPrincipal? CurrentUser { get; }

Property Value

ClaimsPrincipal

Methods

GetAuthenticationStateAsync()

Gets the current authentication state by reading the JWT token from local storage.

public override Task<AuthenticationState> GetAuthenticationStateAsync()

Returns

Task<AuthenticationState>

An AuthenticationState representing the current user or an anonymous identity if no valid token exists.

SignInAsync(string)

Signs the user in by validating the provided JWT token and updating the authentication state.

public Task SignInAsync(string token)

Parameters

token string

The JWT token used to authenticate the user.

Returns

Task

Remarks

If the token is expired or invalid, the user will be automatically signed out.

Exceptions

ArgumentNullException

Thrown if token is null or empty.

SignOutAsync()

Signs the user out by removing the stored token and setting the authentication state to anonymous.

public Task SignOutAsync()

Returns

Task