cookie '.AspNetCore.Identity.Application' 已设置 'SameSite=None' 并且还必须设置 'Secure'
The cookie '.AspNetCore.Identity.Application' has set 'SameSite=None' and must also set 'Secure'
我点击了这些链接:
https://www.thinktecture.com/en/identity/samesite/prepare-your-identityserver/
https://www.thinktecture.com/en/identity/samesite/how-to-delete-samesite-cookies/
这些是我的设置:
services.AddIdentityServer()
.AddApiAuthorization<ApplicationUser, ApplicationDbContext>();
services.AddAuthentication()
.AddIdentityServerJwt();
services.ConfigureNonBreakingSameSiteCookies();
// Adjust to this (or similar)
services
.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
.AddCookie(options =>
{
// add an instance of the patched manager to the options:
options.CookieManager = new ChunkingCookieManager();
});
然后在配置中:
app.UseCookiePolicy();
我正在尝试 运行 通过 http 进行身份验证。我在设置某些(但不是所有 cookie)时遇到这些错误,并且我完全无法删除 chrome
中的 cookie
你的代码一切正常,但你应该更多地配置你的cookies。
在 AddCookie
中添加其他属性 - Secure
、HttpOnly
和 SameSite
。 official documentation
中的更多信息
示例:
services
.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
.AddCookie(options =>
{
// add an instance of the patched manager to the options:
options.CookieManager = new ChunkingCookieManager();
options.Cookie.HttpOnly = true;
options.Cookie.SameSite = SameSiteMode.None;
options.Cookie.SecurePolicy = CookieSecurePolicy.Always;
});
以防其他人遇到此问题但仍有问题。我最终不得不对 NonceCookie 和 CorrelationCookie 属性进行类似的更改才能使它们正常工作。我们的系统正在使用 Identity Server 并位于负载均衡器的后面,该负载均衡器也卸载 SSL 部分。
services.AddAuthentication(options =>
{
options.DefaultScheme = "cookies";
options.DefaultChallengeScheme = "oidc";
})
.AddCookie("cookies", options =>
{
options.Cookie.Name = "appcookie";
options.Cookie.SameSite = SameSiteMode.Strict;
options.Cookie.SecurePolicy = CookieSecurePolicy.Always;
})
.AddOpenIdConnect("oidc", options =>
{
options.NonceCookie.SecurePolicy = CookieSecurePolicy.Always;
options.CorrelationCookie.SecurePolicy = CookieSecurePolicy.Always;
...
}
我点击了这些链接:
https://www.thinktecture.com/en/identity/samesite/prepare-your-identityserver/
https://www.thinktecture.com/en/identity/samesite/how-to-delete-samesite-cookies/
这些是我的设置:
services.AddIdentityServer()
.AddApiAuthorization<ApplicationUser, ApplicationDbContext>();
services.AddAuthentication()
.AddIdentityServerJwt();
services.ConfigureNonBreakingSameSiteCookies();
// Adjust to this (or similar)
services
.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
.AddCookie(options =>
{
// add an instance of the patched manager to the options:
options.CookieManager = new ChunkingCookieManager();
});
然后在配置中:
app.UseCookiePolicy();
我正在尝试 运行 通过 http 进行身份验证。我在设置某些(但不是所有 cookie)时遇到这些错误,并且我完全无法删除 chrome
中的 cookie你的代码一切正常,但你应该更多地配置你的cookies。
在 AddCookie
中添加其他属性 - Secure
、HttpOnly
和 SameSite
。 official documentation
示例:
services
.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
.AddCookie(options =>
{
// add an instance of the patched manager to the options:
options.CookieManager = new ChunkingCookieManager();
options.Cookie.HttpOnly = true;
options.Cookie.SameSite = SameSiteMode.None;
options.Cookie.SecurePolicy = CookieSecurePolicy.Always;
});
以防其他人遇到此问题但仍有问题。我最终不得不对 NonceCookie 和 CorrelationCookie 属性进行类似的更改才能使它们正常工作。我们的系统正在使用 Identity Server 并位于负载均衡器的后面,该负载均衡器也卸载 SSL 部分。
services.AddAuthentication(options =>
{
options.DefaultScheme = "cookies";
options.DefaultChallengeScheme = "oidc";
})
.AddCookie("cookies", options =>
{
options.Cookie.Name = "appcookie";
options.Cookie.SameSite = SameSiteMode.Strict;
options.Cookie.SecurePolicy = CookieSecurePolicy.Always;
})
.AddOpenIdConnect("oidc", options =>
{
options.NonceCookie.SecurePolicy = CookieSecurePolicy.Always;
options.CorrelationCookie.SecurePolicy = CookieSecurePolicy.Always;
...
}