【发布时间】:2018-10-05 21:06:57
【问题描述】:
我正在尝试在 Asp.Net 中配置一个可滑动的过期 cookie。我希望 cookie 出现在 Google Chrome 开发人员工具 cookie 管理器中,并在身份验证后 5 分钟到期,但它显示为“会话”,并且在单击退出按钮之前永不过期。如果浏览器关闭,它确实会消失。
下面是当前的代码。该网站使用基于 Saml 的单点登录身份验证和 Kentor.AuthServices nuget 包(现在称为 SustainSys.Saml2,我们落后于版本)。
app.CreatePerOwinContext(ApplicationDbContext.Create);
app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create);
app.CreatePerOwinContext<ApplicationSignInManager>(ApplicationSignInManager.Create);
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/signin"),
CookieSecure = CookieSecureOption.SameAsRequest,
ExpireTimeSpan = TimeSpan.FromMinutes(5),
SlidingExpiration = true,
Provider = new CookieAuthenticationProvider
{
OnApplyRedirect = ctx => { },
OnResponseSignIn = context =>
{
context.Properties.AllowRefresh = true;
context.Properties.ExpiresUtc = DateTimeOffset.UtcNow.AddMinutes(5);
}
}
});
app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
Kentor.AuthServices.Configuration.Options.GlobalEnableSha256XmlSignatures();
OnResponseSignIn 块最近是基于此 MSDN 答案添加的:
https://forums.asp.net/t/2121970.aspx?OWIN+Authentication+ExpireTimeSpan+not+working
我希望 cookie 在 30 分钟的非活动时间内过期。上面的代码设置为5,方便测试。
【问题讨论】:
标签: asp.net cookies owin-middleware kentor-authservices sustainsys-saml2