Refactored project to module structure

This commit is contained in:
2026-03-12 22:50:15 +01:00
parent 93de9c5d00
commit 1257e8b950
219 changed files with 1231 additions and 1259 deletions

View File

@@ -0,0 +1,48 @@
using System.Net;
using System.Net.Http.Json;
using System.Security.Claims;
using Microsoft.AspNetCore.Components.Authorization;
using Microsoft.Extensions.Logging;
using Moonlight.Shared.Shared.Auth;
using SerializationContext = Moonlight.Shared.SerializationContext;
namespace Moonlight.Frontend.Infrastructure.Services;
public class RemoteAuthProvider : AuthenticationStateProvider
{
private readonly HttpClient HttpClient;
private readonly ILogger<RemoteAuthProvider> Logger;
public RemoteAuthProvider(ILogger<RemoteAuthProvider> logger, HttpClient httpClient)
{
Logger = logger;
HttpClient = httpClient;
}
public override async Task<AuthenticationState> GetAuthenticationStateAsync()
{
try
{
var claimResponses = await HttpClient.GetFromJsonAsync<ClaimDto[]>(
"api/auth/claims", SerializationContext.Default.Options
);
var claims = claimResponses!.Select(claim => new Claim(claim.Type, claim.Value));
return new AuthenticationState(
new ClaimsPrincipal(new ClaimsIdentity(claims, "remote"))
);
}
catch (HttpRequestException e)
{
if (e.StatusCode != HttpStatusCode.Unauthorized)
Logger.LogError(e, "An api error occured while requesting claims from api");
}
catch (Exception e)
{
Logger.LogError(e, "An unhandled error occured while requesting claims from api");
}
return new AuthenticationState(new ClaimsPrincipal());
}
}