added auth with a simple UI

This commit is contained in:
2026-03-09 23:29:04 +01:00
parent c8347ac96b
commit 82ac241129
123 changed files with 3419 additions and 93 deletions

View File

@@ -0,0 +1,36 @@
using System.Net.Http.Headers;
using OED.Api.Core.Interfaces.Services;
namespace OED.Api.Infrastructure.Esi;
public class EsiAuthHandler(
ITokenStore tokenStore,
IEsiTokenRefreshService refreshService,
IHttpContextAccessor httpContextAccessor
) : DelegatingHandler
{
protected override async Task<HttpResponseMessage> SendAsync(
HttpRequestMessage request,
CancellationToken cancellationToken)
{
var characterId = GetCharacterIdFromSession();
if (characterId is null)
return await base.SendAsync(request, cancellationToken);
var accessToken = await tokenStore.GetAccessTokenAsync(characterId.Value);
if (accessToken is null)
accessToken = await refreshService.RefreshAsync(characterId.Value);
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
return await base.SendAsync(request, cancellationToken);
}
private long? GetCharacterIdFromSession()
{
var context = httpContextAccessor.HttpContext;
// CharacterId is set on the HttpContext by session middleware
return context?.Items["CharacterId"] as long?;
}
}