mirror of
https://github.com/meysamhadeli/booking-microservices.git
synced 2026-04-10 17:59:38 +08:00
24 lines
764 B
C#
24 lines
764 B
C#
using System.Net.Http.Headers;
|
|
using Microsoft.AspNetCore.Http;
|
|
|
|
namespace BuildingBlocks.Jwt;
|
|
|
|
public class AuthHeaderHandler : DelegatingHandler
|
|
{
|
|
private readonly IHttpContextAccessor _httpContext;
|
|
|
|
public AuthHeaderHandler(IHttpContextAccessor httpContext)
|
|
{
|
|
_httpContext = httpContext;
|
|
}
|
|
|
|
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request,
|
|
CancellationToken cancellationToken)
|
|
{
|
|
var token = (_httpContext?.HttpContext?.Request.Headers["Authorization"])?.ToString();
|
|
|
|
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", token?.Replace("Bearer ", "", StringComparison.CurrentCulture));
|
|
|
|
return base.SendAsync(request, cancellationToken);
|
|
}
|
|
} |