You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
1.1 KiB
35 lines
1.1 KiB
using Microsoft.AspNetCore.Http;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Net.Http;
|
|
using System.Net.Http.Headers;
|
|
using System.Text;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace ApiGateway.Helper
|
|
{
|
|
public class HeaderDelegatingHandler : DelegatingHandler
|
|
{
|
|
private readonly IHttpContextAccessor _httpContextAccessor;
|
|
|
|
public HeaderDelegatingHandler(IHttpContextAccessor httpContextAccessor)
|
|
{
|
|
_httpContextAccessor = httpContextAccessor;
|
|
}
|
|
|
|
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
|
|
{
|
|
IEnumerable<string> headerValues;
|
|
if (request.Headers.TryGetValues("AccessToken", out headerValues))
|
|
{
|
|
string accessToken = headerValues.First();
|
|
|
|
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
|
|
request.Headers.Remove("AccessToken");
|
|
}
|
|
return await base.SendAsync(request, cancellationToken);
|
|
}
|
|
}
|
|
}
|
|
|