刷新后的OWIN sign - in认证

本文关键字:in 认证 sign OWIN 刷新 | 更新日期: 2023-09-27 18:02:26

我正在尝试登录一个用户,如....

        var accessor = HttpContext.Current.GetOwinContext().Get<ApplicationSignInManager>();
        var result = await accessor.CreateUserIdentityAsync(new User() { ... });
        AuthenticationManager.SignIn(
            new AuthenticationProperties { AllowRefresh = false, IsPersistent = false },
            result);

和SignIn工作,但是如果我刷新页面,用户仍然是经过身份验证的,我希望用户注销,因为我将AllowRefreshIsPersistent都设置为false。我错过了什么明显的东西吗?或者可能是一些不明显的东西?(如果有区别的话,登录的"用户"实际上并不存在,它是一种匿名的经过身份验证的用户)。

刷新后的OWIN sign - in认证

AllowRefresh是一个允许/不允许cookie被刷新(例如过期更新)的设置。

这与页面刷新后是否仍然需要身份验证无关。

bool? allowRefresh = authenticationTicket.Properties.AllowRefresh;
if (issuedUtc.HasValue && expiresUtc.HasValue && base.Options.SlidingExpiration && (!allowRefresh.HasValue || allowRefresh.Value))
{
    TimeSpan t = utcNow.Subtract(issuedUtc.Value);
    TimeSpan t2 = expiresUtc.Value.Subtract(utcNow);
    if (t2 < t)
    {
        this._shouldRenew = true;
        this._renewIssuedUtc = utcNow;
        TimeSpan timeSpan = expiresUtc.Value.Subtract(issuedUtc.Value);
        this._renewExpiresUtc = utcNow.Add(timeSpan);
    }
}