mirror of
https://github.com/claunia/marechai.git
synced 2025-12-16 19:14:25 +00:00
Add authentication and token services.
This commit is contained in:
22
Marechai.App/Services/Endpoints/HttpAuthHandler.cs
Normal file
22
Marechai.App/Services/Endpoints/HttpAuthHandler.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user