* Added Authentication

This commit is contained in:
2025-02-21 09:59:50 +01:00
parent ed5b5634fd
commit 6774311433
20 changed files with 468 additions and 30 deletions

View File

@@ -0,0 +1,29 @@
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());
}
}