2

Why if I add authorization header with right token in my custom DelegatingHandler to the request without this header, I get the response: 401 authorization required?

public class ProxyHandler : DelegatingHandler
{
   protected async override Task<HttpResponseMessage> SendAsync(
        HttpRequestMessage request, CancellationToken cancellationToken)
   {
        request.Headers.Add("Authorization", "Bearer rightToken...");
        return response = await base.SendAsync(request, cancellationToken);
    }
}

If I send the request from postman with the same authorization header, I got 200 OK. enter image description here

Community
  • 1
  • 1
paulka
  • 133
  • 1
  • 2
  • 7

1 Answers1

0

I found the answer. The method AuthenticateCoreAsync from OAuthBearerAuthenticationHandler.cs class was fired before my ProxyHandler. After I have changed AuthenticationMode in OAuthBearerAuthenticationOptions from Active to Passive, request token in header is being checked after method base.SendAsync(request, cancellationToken) from my ProxyHandler is fired.

paulka
  • 133
  • 1
  • 2
  • 7