【问题标题】:Setting cookie expiration for OpenIdConnectAuthentication为 OpenIdConnect 身份验证设置 cookie 过期时间
【发布时间】:2020-07-22 22:44:40
【问题描述】:

我正在尝试为 OIDC cookie 设置过期日期。我尝试在Notifications.SecurityTokenValidated 中设置AuthenticationTicket.ExpiresUtc,但.AspNet.Cookies cookie 过期时间在浏览器中仍然是“会话”。有没有办法做到这一点?

app.UseCookieAuthentication(new CookieAuthenticationOptions
            {
                AuthenticationType = CookieAuthenticationDefaults.AuthenticationType,
                CookieHttpOnly = true
            });

var oidcOptions = new OpenIdConnectAuthenticationOptions
            {
                UseTokenLifetime = false,
                ..
                SignInAsAuthenticationType = CookieAuthenticationDefaults.AuthenticationType,
                Notifications = new OpenIdConnectAuthenticationNotifications
                {
                    SecurityTokenReceived = n =>
                    {
                        n.AuthenticationTicket.Properties.ExpiresUtc = System.DateTimeOffset.UtcNow.AddMinutes(30);
                        return Task.FromResult(0);
                    }
            };

我正在使用 ASP.NET MVC .NET 4.5.2、Owin 4.0.1

【问题讨论】:

    标签: c# asp.net asp.net-mvc owin openid-connect


    【解决方案1】:

    显然你还需要添加n.AuthenticationTicket.Properties.IsPersistent = true;

    【讨论】:

      猜你喜欢
      • 2020-07-06
      • 2012-01-30
      • 2019-11-13
      • 1970-01-01
      • 1970-01-01
      • 2020-10-14
      • 2018-09-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多