Prima configurazione e struttura

This commit is contained in:
2026-02-04 17:31:00 +01:00
parent 1a949051ca
commit ecafebae7f
66 changed files with 1153 additions and 645 deletions

View File

@@ -0,0 +1,56 @@
using System.Security.Claims;
using IntegryApiClient.Core.Domain.Abstraction.Contracts.Account;
using Microsoft.AspNetCore.Components.Authorization;
namespace SteUp.Shared.Core.Services;
public class AppAuthenticationStateProvider : AuthenticationStateProvider
{
private readonly IUserSession _userSession;
private readonly IUserAccountService _userAccountService;
public AppAuthenticationStateProvider(IUserSession userSession, IUserAccountService userAccountService)
{
_userSession = userSession;
_userAccountService = userAccountService;
userAccountService.ExpiredUserSession += (_, _) =>
NotifyAuthenticationStateChanged(LoadAuthenticationState());
}
public override async Task<AuthenticationState> GetAuthenticationStateAsync()
{
return await LoadAuthenticationState();
}
public async Task SignOut()
{
await _userAccountService.Logout();
NotifyAuthenticationState();
}
public void NotifyAuthenticationState()
{
NotifyAuthenticationStateChanged(LoadAuthenticationState());
}
private async Task<AuthenticationState> LoadAuthenticationState()
{
if (!await _userSession.IsLoggedIn() || !await _userSession.IsRefreshTokenValid())
{
return new AuthenticationState(
new ClaimsPrincipal(
new ClaimsIdentity()
)
);
}
var claimIdentity = new ClaimsIdentity(_userSession.JwtToken!.Claims, "jwt");
var user = new ClaimsPrincipal(claimIdentity);
var authenticationState = new AuthenticationState(user);
return authenticationState;
}
}