c# - 从企业代理后面使用 .Net Core 3.00 对 Azure AD 进行身份验证
问题描述
我有一个 .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"
}
解决方案
经过深入搜索,我找到了解决方案:
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();
推荐阅读
- visual-studio - 将 JSON 文件从类库 nuget 包复制到 bin
- python - 通过 ssh 访问 Python celery 后端/代理
- cytoscape.js - Cytoscape-cxtmenu.js :根据条件显示菜单命令
- python - 添加到 Python sys.path - 找不到 PYTHONPATH 环境变量
- php - 查询选择并显示所有第一个表和第二个表甚至第二个表中不存在
- jquery - SVG 图像未更新 onMouseOver
- javascript - IntelliSense 或闭包编译器未找到 TypeScript 类
- ruby - Rdoc:如何记录委托?
- python-3.x - 如何为 celery 任务提供动态 soft_time_limit
- docker - Istio 1.8 上游连接错误或在标头之前断开/重置。重置原因:连接失败