2024-07-27 14:38:39 +02:00
|
|
|
using System.Security.Claims;
|
2024-10-14 15:28:43 +02:00
|
|
|
using DotBased.ASP.Auth.Scheme;
|
2024-07-27 14:38:39 +02:00
|
|
|
using DotBased.Logging;
|
|
|
|
using Microsoft.AspNetCore.Components.Authorization;
|
|
|
|
using Microsoft.AspNetCore.Components.Server;
|
|
|
|
using ILogger = DotBased.Logging.ILogger;
|
|
|
|
|
|
|
|
namespace DotBased.ASP.Auth;
|
|
|
|
|
|
|
|
// RevalidatingServerAuthenticationStateProvider
|
|
|
|
// AuthenticationStateProvider
|
2024-10-14 15:28:43 +02:00
|
|
|
// Handles roles
|
2024-07-27 14:38:39 +02:00
|
|
|
public class BasedServerAuthenticationStateProvider : ServerAuthenticationStateProvider
|
|
|
|
{
|
|
|
|
public BasedServerAuthenticationStateProvider(BasedAuthConfiguration configuration, ISessionStateProvider stateProvider)
|
|
|
|
{
|
|
|
|
_config = configuration;
|
|
|
|
_stateProvider = stateProvider;
|
|
|
|
_logger = LogService.RegisterLogger(typeof(BasedServerAuthenticationStateProvider));
|
|
|
|
}
|
|
|
|
|
|
|
|
private BasedAuthConfiguration _config;
|
|
|
|
private ISessionStateProvider _stateProvider;
|
|
|
|
private ILogger _logger;
|
2024-10-14 15:28:43 +02:00
|
|
|
private readonly AuthenticationState _loggedInState = new AuthenticationState(new ClaimsPrincipal(new ClaimsIdentity(new List<Claim>() { new Claim(ClaimTypes.Role, "Admin"), new Claim(ClaimTypes.Name, "Anon") }, BasedAuthenticationHandler.AuthenticationScheme)));
|
|
|
|
private readonly AuthenticationState _anonState = new AuthenticationState(new ClaimsPrincipal());
|
|
|
|
|
2024-07-27 14:38:39 +02:00
|
|
|
|
|
|
|
public override Task<AuthenticationState> GetAuthenticationStateAsync()
|
|
|
|
{
|
2024-10-14 15:28:43 +02:00
|
|
|
return Task.FromResult(_loggedInState);
|
2024-07-27 14:38:39 +02:00
|
|
|
}
|
|
|
|
}
|