Files
marechai/Marechai.App/Services/Endpoints/HttpAuthHandler.cs

22 lines
778 B
C#
Raw Normal View History

2025-11-16 19:59:05 +00:00
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading;
using System.Threading.Tasks;
using Marechai.App.Services.Authentication;
namespace Marechai.App.Services.Endpoints;
public sealed class HttpAuthHandler(ITokenService tokenService) : DelegatingHandler
{
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request,
CancellationToken cancellationToken)
{
string token = tokenService.GetToken();
if(!string.IsNullOrEmpty(token)) request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", token);
HttpResponseMessage response = await base.SendAsync(request, cancellationToken);
return response;
}
}