asp.net-core-2.0 - ASPNET Core OIDC 关联失败
问题描述
我在 StackOverflow 上查看了与此类似的一堆类似问题,但没有一个解决方案对我有用。
这个问题快把我逼疯了!
我与这里的许多类似服务器的主要区别是负载均衡器后面只有一台服务器,所以问题不在于我的请求会发送到不同的服务器。我已经实现了数据保护中间件,更改了我的回调路径,尝试捕获错误事件,为状态数据添加了缓存等。没有什么可以解决这个问题。我不知道我错过了什么。
如果有人能给我一些关于这方面的见解,我将不胜感激。
services.AddAuthentication(options =>
{
options.DefaultScheme = "Cookies";
options.DefaultChallengeScheme = "oidc";
})
.AddCookie("Cookies")
.AddOpenIdConnect("oidc", options =>
{
options.SignInScheme = "Cookies";
options.ClientId = Configuration["IdServerClientId"];
options.ClientSecret = Configuration["IdServerClientSecret"];
options.Authority = Configuration["IdServerBaseUri"];
options.CallbackPath = "/sign-in-oidc2";
options.RequireHttpsMetadata = false;
options.ResponseType = "code id_token";
options.SaveTokens = true;
options.TokenValidationParameters = new TokenValidationParameters()
{
NameClaimType = "name"
};
options.Scope.Add("openid");
options.Scope.Add("profile");
options.Scope.Add("email");
options.Events = new OpenIdConnectEvents()
{
//OnRedirectToIdentityProvider = OnRedirectToProvider,
OnRemoteFailure = OnRemoteFailure,
OnAuthenticationFailed = OnAuthenticationFailed
};
});
services.AddOidcStateDataFormatterCache("foo");
services.AddDataProtection()
.PersistKeysToFileSystem(new DirectoryInfo(Configuration["KeyPersistenceLocation"]));
解决方案
如果其他人遇到此问题,请在此处找到答案:
在 Startup 的 Configure 方法中,需要添加这个来处理 http/https 冲突。
app.Use((context, next) =>
{
context.Request.Scheme = "https";
return next();
});
推荐阅读
- python - Sklearn 多个特征(多个自变量,结果 y 取决于)
- javascript - 如何在不分页的情况下抓取下一页
- excel - 使用 vlookup 参考使用 VBA 粘贴单元格颜色
- javascript - 应该使用新的数据库信息更新页面的 ajax 函数正在发挥应有的作用
- javascript - 循环隐藏除一个以外的所有 div
- javascript - 用 JavaScript 绘制流数据图表
- javascript - Javascript,如何显示下一个日期
- php - 重新加载php后找不到类
- php - 引导程序不适用于 URL 重写
- spring-boot - Spring Zuul Gateway Swagger-UI 适用于所有微服务