0

I have a .Net core app. I trying to use AzureAd Authentication. It's working fine on LocalHost but when I deployed the app on my company server I faced an issue of Proxy Credentials. I used the below code but Not working:

services.AddAuthentication(AzureADDefaults.AuthenticationScheme)
                .AddAzureAD(options => Configuration.Bind("AzureAd", options))
                .AddOpenIdConnect(options => options.BackchannelHttpHandler = new HttpClientHandler
                {
                    UseProxy = true,
                    Proxy = new WebProxy
                    {
                        Credentials = new NetworkCredential
                        {
                            UserName = "my_UserName",
                            Password = "my_Password "
                        },
                        Address = new Uri("my_Domain:my_Port")
                    }
                }); 

appsettings:

"AzureAd": {
   "Instance": "https://login.microsoftonline.com/",
   "Domain": "My_Domain",
   "TenantId": "*************",
   "ClientId": "******",
   "CallbackPath": "/signin-oidc"
 } 

1 Answers1

0

After deep searching, I found the the solution:

services.AddAuthentication(AzureADDefaults.AuthenticationScheme)
        .AddAzureAD(options => Configuration.Bind("AzureAd", options))
        .AddCookie(options =>
             {
               options.SlidingExpiration = true;
               options.ExpireTimeSpan = TimeSpan.FromMinutes(60);
              });

services.Configure<OpenIdConnectOptions>(AzureADDefaults.OpenIdScheme, options =>
            {
                options.BackchannelHttpHandler = new HttpClientHandler
                {
                    UseProxy = true,
                    Proxy = new WebProxy()
                    {
                        Credentials = new NetworkCredential
                        {
                            UserName = "My_UserName",
                            Password = "My_Password"
                        },
                        Address = new Uri("My_Domain:My_Port")
                    }
                };
            });

            services.AddHttpClient();

halfer
  • 19,824
  • 17
  • 99
  • 186