[REFACTOR] Refactored logging & added support for Microsoft.Extensions.Logging. Added test WebApi project

This commit is contained in:
max
2024-11-17 22:51:54 +01:00
parent 58739c2aea
commit 737cbcfd11
31 changed files with 398 additions and 97 deletions

View File

@@ -18,21 +18,23 @@ public class BasedServerAuthenticationStateProvider : ServerAuthenticationStateP
_config = configuration;
_localStorage = localStorage;
_securityService = securityService;
_logger = LogService.RegisterLogger(typeof(BasedServerAuthenticationStateProvider));
_logger = LogService.RegisterLogger<BasedServerAuthenticationStateProvider>();
}
private BasedAuthConfiguration _config;
private readonly ProtectedLocalStorage _localStorage;
private readonly SecurityService _securityService;
private ILogger _logger;
private readonly ILogger _logger;
private readonly AuthenticationState _anonState = new(new ClaimsPrincipal());
public override async Task<AuthenticationState> GetAuthenticationStateAsync()
{
_logger.Debug("Getting authentication state...");
var sessionIdResult = await _localStorage.GetAsync<string>(BasedAuthDefaults.StorageKey);
if (!sessionIdResult.Success || sessionIdResult.Value == null)
return _anonState;
_logger.Debug("Found state [{State}], getting session from {Service}", sessionIdResult.Value, nameof(SecurityService));
var stateResult = await _securityService.GetAuthenticationStateFromSessionAsync(sessionIdResult.Value);
return stateResult is { Success: true, Value: not null } ? stateResult.Value : _anonState;
}