asp.net-core - identityserver4 关联失败
问题描述
最近在学习idenetty server 4, 在github组织了一个测试项目
env: windows 10, edge edge: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.96 Safari/537.36 Edg/88.0.705.56
services.AddAuthentication(options =>
{
options.DefaultScheme = "Cookies";
options.DefaultChallengeScheme = "oidc";
})
// 添加可以处理cookie的处理程序
.AddCookie("Cookies")
// 用于配置执行OpenID Connect协议的处理程序
.AddOpenIdConnect("oidc", options =>
{
options.Authority = "https://demo.identityserver.io/"; // 受信任令牌服务地址
options.RequireHttpsMetadata = true;
options.ClientId = "interactive.confidential";
options.ClientSecret = "secret";
options.ResponseType = "code";
options.SaveTokens = true; // 用于将来自IdentityServer的令牌保留在cookie中
// 1、添加授权访问api的支持
//options.Scope.Add("scope1");
options.Scope.Add("email");
//options.Scope.Add("profile");
options.GetClaimsFromUserInfoEndpoint = true;
//options.Scope.Add("offline_access");
options.TokenValidationParameters = new TokenValidationParameters
{
NameClaimType = "name",
RoleClaimType = "role"
};
});
问题是我已经登录并授权成功,但是当我跳转回来的时候,会出现如下错误
Exception: Correlation failed.
Unknown location
Exception: An error was encountered while handling the remote login.
Microsoft.AspNetCore.Authentication.RemoteAuthenticationHandler<TOptions>.HandleRequestAsync()
在那之后,我看到了一些关于 cookie 的问题。我加了一个ConfigureNonBreakingSameSiteCookies
,但还是不行
当我禁用 edge config 时Cookies without SameSite must be secure
,它成功了。
问题是Is there any other way?
如果有人能给我一些关于这方面的见解,我将不胜感激。
解决方案
根据上述评论,这可能是由于您没有使用 HTTPS。该关联 cookie 将设置为SameSite=None
或SameSite=Lax
因为它需要在另一个主机发起的请求期间可访问,如果不是由 HTTPS 源发出,Chrome 和 Edge 将默认阻止它。
推荐阅读
- pandas - 我可以创建一个每次达到 cumsum 阈值时从 0 重置的参考索引列吗
- python - 使用 Pandas MultiIndex 数据写入多文件 CSV
- go - 使用三重 DES 加密创建 RSA 私钥
- android - Android MaterialDatePicker 文本出现在错误的位置
- php - 编译失败,0线索怎么办
- list - Flutter:添加动态 TextFormField 以将数据上传到列表
- python - Pandas 数据框到嵌套字典,名称空间为 None
- java - 如果编译时出现条件错误 - 具体问题
- java - Nginx “400 请求标头或 Cookie 太大”问题
- java - 带有列表的 JPA 抽象继承