cookie“.AspNetCore.Identity.Application”已设置“SameSite=None”,并且还必须设置“Secure”

Dan*_*man 15 identity asp.net-core

我点击了这些链接:

这些是我的设置:

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();
      });
Run Code Online (Sandbox Code Playgroud)

然后在配置中:

app.UseCookiePolicy();
Run Code Online (Sandbox Code Playgroud)

我正在尝试通过 http 运行身份。我在设置某些(但不是全部)cookie 时遇到这些错误,并且我完全无法删除 chrome 中的 cookie

cmi*_*nus 11

万一其他人遇到这个并且仍然有问题。我最终不得不对 NonceCookie 和 CorrelationCookie 属性进行类似的更改才能使它们正常工作。我们的系统使用身份服务器,并位于负载均衡器后面,该负载均衡器也卸载 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;
...
}
Run Code Online (Sandbox Code Playgroud)

  • @GuyLevy 奇怪的是,它正在将 SameSiteMode 设置为“严格”。我原以为它会因该设置而失败,但事实并非如此。 (2认同)

Dar*_*oon 8

您的代码中一切正常,但您应该更多地配置您的cookie。

添加附加属性 - SecureHttpOnlySameSiteAddCookie更多信息请参阅官方文档

例子:

        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;
           });
Run Code Online (Sandbox Code Playgroud)