[ASP.NET] Ionos Windows Hosting Proxy for Auth0

Yesterday I had a hard time figuring out how to get my asp.net core backend working on ionos with auth0 support. Logically, auth0 has to connect to their services from the ionos server to work correctly. Ionos does not allow data from external sites - so you have to use their proxy for that: Ionos Docs

I wasn't able to get the web.config example working so I dig a little bit deeper and found the following solution. May it safes you some headache.

Create the proxy http handler.

var proxyHpttClientHandler = new HttpClientHandler
{
  Proxy = environment.IsProduction() 
    ? new WebProxy("http://winproxy.server.lan:3128") 
    : null
};

Programm.cs

Add the handler everywhere you go to an external ressource. For my auth0 backend this means the following:

services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddJwtBearer(options =>
{
    options.BackchannelHttpHandler = proxyHpttClientHandler;
    ...
});

...

builder.Services.AddAuth0AuthenticationClient(config =>
{
  ...
}).ConfigurePrimaryHttpMessageHandler(() => proxyHpttClientHandler);

...

builder.Services.AddAuth0ManagementClient()
    .AddManagementAccessToken()
    .ConfigurePrimaryHttpMessageHandler(() => proxyHpttClientHandler);

Programm.cs

If you have further questions about this topic or need help with a problem in general, please write a comment or simply contact me at yesreply@georghoeller.dev :)