30 lines
955 B
C#
30 lines
955 B
C#
using System.Security.Claims;
|
|
using Microsoft.AspNetCore.Components.Authorization;
|
|
using OrdersManagementDataModel.Dtos;
|
|
|
|
namespace OrdersManagement;
|
|
|
|
public class CustomAuthenticationStateProvider : AuthenticationStateProvider
|
|
{
|
|
private UserDto? _currentUser;
|
|
|
|
public override Task<AuthenticationState> GetAuthenticationStateAsync()
|
|
{
|
|
var identity = _currentUser != null ? new ClaimsIdentity([new Claim(ClaimTypes.Name, _currentUser.Login)], "CustomAuth") : new ClaimsIdentity();
|
|
return Task.FromResult(new AuthenticationState(new ClaimsPrincipal(identity)));
|
|
}
|
|
|
|
public Task MarkUserAsAuthenticated(UserDto? user)
|
|
{
|
|
_currentUser = user;
|
|
NotifyAuthenticationStateChanged(GetAuthenticationStateAsync());
|
|
return Task.CompletedTask;
|
|
}
|
|
|
|
public void MarkUserAsLoggedOut()
|
|
{
|
|
_currentUser = null;
|
|
NotifyAuthenticationStateChanged(GetAuthenticationStateAsync());
|
|
}
|
|
}
|