从企业代理后面通过

从企业代理后面通过

本文介绍了使用 .Net Core 3.00 从企业代理后面通过 Azure AD 进行身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 .Net 核心应用程序.我尝试使用 AzureAd 身份验证.它在 LocalHost 上运行良好,但是当我在公司服务器上部署该应用程序时,我遇到了代理凭据问题.我使用了以下代码但不起作用:

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")
                    }
                });

应用设置:

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

推荐答案

经过深入搜索,我找到了解决方案:

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();

这篇关于使用 .Net Core 3.00 从企业代理后面通过 Azure AD 进行身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 08:16