Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/304.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何为代理通信的Auth0授权设置用户代理http头_C#_Asp.net Core - Fatal编程技术网

C# 如何为代理通信的Auth0授权设置用户代理http头

C# 如何为代理通信的Auth0授权设置用户代理http头,c#,asp.net-core,C#,Asp.net Core,我们正在建立一个新的Asp.NETCore3.0Web应用程序。使用Auth0对此WebApp进行身份验证时,应用程序将尝试使用HTTP GET访问.eu.Auth0.com。要访问我们公司代理背后的此站点,应用程序需要发送用户代理http头 我的尝试是添加一个自定义Http消息处理程序,它将此头添加到授权后端的所有请求中 public class CustomHttpMessageHandler : DelegatingHandler { public CustomHttpMessa

我们正在建立一个新的Asp.NETCore3.0Web应用程序。使用Auth0对此WebApp进行身份验证时,应用程序将尝试使用HTTP GET访问.eu.Auth0.com。要访问我们公司代理背后的此站点,应用程序需要发送用户代理http头

我的尝试是添加一个自定义Http消息处理程序,它将此头添加到授权后端的所有请求中

public class CustomHttpMessageHandler : DelegatingHandler {

    public CustomHttpMessageHandler() {
        InnerHandler = new HttpClientHandler();
    }

    protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) {
        request.Headers.Add("User-Agent", "myApp/0.1.0");

        return await base.SendAsync(request, cancellationToken);
    }
}
调试时,将运行此代码并将用户代理添加到请求中。这里的问题是,应用程序(在GET之前)向.eu.auth0.com发送一个HTTP选项请求,我无法修改该请求

有没有办法为授权中间件设置此Http头?甚至全球? 或者我可以为他们提供一个完整的定制Http客户端吗

services.AddAuthentication(options => {
       options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
       options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;

}).AddJwtBearer(options => {
       options.SaveToken = true;
       options.Authority = domain;
       options.Audience = Configuration["Auth0:ApiIdentifier"];
       options.BackchannelHttpHandler = new CustomHttpMessageHandler();
});