【问题标题】:Authenticate with Azure AD using .Net Core 3.00 from behind Corporate Proxy从企业代理后面使用 .Net Core 3.00 对 Azure AD 进行身份验证
【发布时间】:2020-05-31 13:37:48
【问题描述】:

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

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

【问题讨论】:

  • 能否分享一下您部署应用时的错误详情

标签: c# .net-core proxy azure-ad-b2c


【解决方案1】:

经过深入搜索,我找到了解决办法:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多