I'm implementing an asp .net core web API for my company. The authentication should be processed via the built-in jwt bearer authentication.
The problem I'm struggling with is, that I'm working behind a proxy. So for the token validation, I'm facing 407 proxy authentication failed responses.
As far as I know, in .net framework, there was the possibility to define a default proxy in the web.config but for .net core, I couldn't find any similar functionality.
Is it possible to "inject" proxy settings for the jwt authentication or if not, is there any other way to work with this authentication behind a proxy?
The option to define a global proxy in the Web.config is gone for ASP.NET Core.
Most APIs that do anything over HTTP allow you to set a HttpMessageHandler, though. You can set the proxy for that MessageHandler.
For instance, assuming you're using default JwtBearer Authentication you could try this approach:
appsettings.json:
"Proxy": {
"ProxyAddress": "http://MyProxy:8080"
},
In your ConfigureServices method you can then:
services.AddAuthentication()
.AddJwtBearer("Bearer", o =>
{
o.BackchannelHttpHandler = new HttpClientHandler
{
Proxy = new WebProxy(Configuration["Proxy:ProxyAddress"])
};
});
Depending on what flow you use you may need to set the Proxy on other/additional handlers as well. Additionally, if you require finer grained control over the Proxy, you can always write a class implementing IWebProxy and use that instead of newing a WebProxy with a proxy address.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.