asp.net-core - 使用 RunProxy 和 OpenIdConnect 时的无限身份验证循环
问题描述
在解决这个问题之前——我们如何解决无限认证循环——一些关于架构的信息。
我们正在使用 .net 核心 2.1。
我们有 2 项服务。第一个是面向公共流量的,是否终止 TLS 并确定是否应该传递请求。(可能对其他服务器)当该服务器发现请求是针对某个路径发出的,它使用RunProxy
方法将请求映射到使用 http 的“其他”服务。该代码如下所示:
app.MapWhen(<MatchRequestCondition>, proxyTime => proxyTime.RunProxy(
new ProxyOptions
{
Scheme = "http",
Host = "localhost",
Port = "1122"
}
));
例如,如果您访问https://localhost:1234/abc - 这将映射到http://localhost:1122 - 这是第二个应用程序所在的端口。
现在,此辅助服务使用 OpenIdConnect - 它的配置如下所示。
// Configure Services method
services.AddMvc(mvcOptions => {
AuthorizationPolicy policy = new AuthorizationPolicyBuilder()
.RequireAuthenticatedUser()
.Build();
mvcOptions.Filters.Add(new AuthorizeFilter(policy));
});
services.AddAuthentication(options =>
{
options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
})
.AddCookie()
.AddOpenIdConnect(auth =>
{
auth.ClientId = "<client_id>";
auth.ClientSecret = "<client_secret>";
auth.Authority = "<authority>";
});
// Configure method
app.UseAuthentication();
这就是有趣的地方:
如果我直接访问第二个节点(仅用于接收来自第一个节点的流量) - 例如http://localhost:1122 - 我将被重定向到登录并且一切正常。
但是如果我访问第一个节点(这是真正的流量应该来自的节点) - 它会进入一个疯狂的身份验证循环。
有什么想法可能是根本原因吗?这与在常规服务前使用负载均衡器有何不同?或者可能是因为我在辅助服务中使用了 cookie 中间件?
解决方案
推荐阅读
- reactjs - 如何防止在 netlify 上提交表单的默认重定向?
- python - 它显示名称错误名称 MEETING_TIMES 未定义
- c# - 从另一个项目手动在 AspNetUser 表中添加新用户
- shell - 如何使用 shell 脚本合并 2 个 csv 文件中的数据
- reactjs - 如何将 Redux 操作传递给 2 个减速器以更新 React 中的状态?
- macos - Visual Studio for Mac(AKA Xamarin)上的 Specflow 功能文件中没有突出显示语法
- python - Tensorflow 收集和无信息权重更新(tensorflow-Python)
- discord - Randompuppys 不会在 discord.js 上从 reddit 上获取图像
- postgresql - Kafka Producer 无法验证没有 PK 的记录并返回 InvalidRecordException
- python - 如何按单词“by”拆分字典并仅保留书名?