【问题标题】:Authentication Cookie does not work in 3rd party Iframe身份验证 Cookie 在第 3 方 iframe 中不起作用
【发布时间】:2020-08-11 06:52:45
【问题描述】:

我有一个 .net MVC 5 应用程序。 AuthCookie 在没有 iframe 的情况下工作正常,我可以看到 SameSite 策略设置为无。但是,在 iframe 中,[Authorize] 属性方法卡在永久重定向上。在 iframe 中,请求似乎无法读取下面代码创建的 cookie。

followed the documentation并实现SameSiteCookieManager.cs

网络配置

<httpCookies sameSite="None" requireSSL="true" />
<sessionState cookieSameSite="None">
</sessionState>
<authentication mode="None" />
<compilation targetFramework="4.7.2" />
<httpRuntime targetFramework="4.7.2" />

启动

app.UseCookieAuthentication(new CookieAuthenticationOptions
        {
            AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
            LoginPath = new PathString("/Account/Login"),
            Provider = new CookieAuthenticationProvider
            { 
                OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>(
                    validateInterval: TimeSpan.FromMinutes(30),
                    regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))
            },
            CookieManager = new SameSiteCookieManager(new SystemWebCookieManager()),
            CookieSameSite = SameSiteMode.None,
            CookieHttpOnly = true,
            CookieSecure = CookieSecureOption.Always,
            ExpireTimeSpan = new TimeSpan(0, 10, 0)
        });

帐户/登录

 var user = UserManager.Find(userName,"*****");
 AuthenticationManager.SignOut(DefaultAuthenticationTypes.ApplicationCookie);
 var identity = UserManager.CreateIdentity(user, DefaultAuthenticationTypes.ApplicationCookie);
        AuthenticationManager.SignIn(new AuthenticationProperties() { IsPersistent = isPersistent }, identity);
 return RedirectToAction("Index", "Home");

【问题讨论】:

    标签: asp.net-mvc iframe samesite


    【解决方案1】:

    问题出在浏览器上。在这里张贴只是以防万一它会节省一些时间。 原来问题出在我的 chrome 隐身浏览器上。我选中了“阻止第 3 方 Cookie”选项。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-12-19
      • 1970-01-01
      • 2020-03-19
      • 2021-06-26
      • 2017-02-01
      • 2022-10-20
      • 2017-02-13
      • 2020-06-20
      相关资源
      最近更新 更多