Prima configurazione e struttura
This commit is contained in:
13
SteUp.Shared/Core/Authorization/Enum/KeyGroupEnum.cs
Normal file
13
SteUp.Shared/Core/Authorization/Enum/KeyGroupEnum.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
namespace SteUp.Shared.Core.Authorization.Enum;
|
||||
|
||||
public enum KeyGroupEnum
|
||||
{
|
||||
UtenteAziendale = 2,
|
||||
Cliente = 3,
|
||||
Agenti = 5,
|
||||
AmministratoreAziendale = 9,
|
||||
Tecnico = 22,
|
||||
ResponsabileDiReparto = 23,
|
||||
ResponsabileAmministrativo = 29,
|
||||
Programmatore = 30
|
||||
}
|
||||
7
SteUp.Shared/Core/Interface/IFormFactor.cs
Normal file
7
SteUp.Shared/Core/Interface/IFormFactor.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace SteUp.Shared.Core.Interface;
|
||||
|
||||
public interface IFormFactor
|
||||
{
|
||||
public string GetFormFactor();
|
||||
public string GetPlatform();
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace SteUp.Shared.Core.Interface.IntegryApi;
|
||||
|
||||
public interface IIntegryApiService
|
||||
{
|
||||
Task<bool> SystemOk();
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace SteUp.Shared.Core.Interface.System.Network;
|
||||
|
||||
public interface INetworkService
|
||||
{
|
||||
public bool ConnectionAvailable { get; set; }
|
||||
|
||||
public bool IsNetworkAvailable();
|
||||
}
|
||||
56
SteUp.Shared/Core/Services/AppAuthenticationStateProvider.cs
Normal file
56
SteUp.Shared/Core/Services/AppAuthenticationStateProvider.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
22
SteUp.Shared/Core/Services/IntegryApiService.cs
Normal file
22
SteUp.Shared/Core/Services/IntegryApiService.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using IntegryApiClient.Core.Domain.Abstraction.Contracts.Account;
|
||||
using IntegryApiClient.Core.Domain.RestClient.Contacts;
|
||||
using SteUp.Shared.Core.Interface.IntegryApi;
|
||||
|
||||
namespace SteUp.Shared.Core.Services;
|
||||
|
||||
public class IntegryApiService(IIntegryApiRestClient integryApiRestClient, IUserSession userSession)
|
||||
: IIntegryApiService
|
||||
{
|
||||
public async Task<bool> SystemOk()
|
||||
{
|
||||
try
|
||||
{
|
||||
await integryApiRestClient.Get<object>("system/ok");
|
||||
return true;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user