External Login Provider Proxy Settings

Configure external logins when ASP.Net Core application is running behind a proxy server

When running ASP.NET Core application behinde a proxy server, external login providers will be inaccessible and the system will throw an unhandled exception:

 

External login behinde proxy unhandled exception

 

Solution is quiet simple, just add proxy configurations at the external login provide settings in startup.cs file :

services.AddAuthentication()
    .AddGoogle(ops =>
    {
        ops.ClientId = Configuration["Authentication:Google:ClientId"];
        ops.ClientSecret = Configuration["Authentication:Google:ClientSecret"];

        ops.BackchannelHttpHandler = new HttpClientHandler()
        {
            Proxy = new WebProxy("http://my-proxy-address.com:1234")
        };
    });

 

if the proxt requires user name and password, it can be configured as below:

services.AddAuthentication()
    .AddGoogle(ops =>
    {
        ops.ClientId = Configuration["Authentication:Google:ClientId"];
        ops.ClientSecret = Configuration["Authentication:Google:ClientSecret"];

        ops.BackchannelHttpHandler = new HttpClientHandler()
        {
            Proxy = new WebProxy("http://my-proxy-address.com:1234"),
            DefaultProxyCredentials = new NetworkCredential
            {
                UserName = "user-name",
                Password = "password"
            }
        };
    });