【发布时间】:2021-06-14 08:24:22
【问题描述】:
我从使用 Identity Server 中学到的一件事是,开箱即用,ASP.NET Core Identity 不能很好地与 Identity Server 配合使用。参考this question。
ASP.NET 身份 包含一种在特定用户的数据已更改时弹出用户的方法。这受 aspnetuser 表的 SecurityStamp 列的约束。当标记更改时,下次验证 cookie 时,验证失败。
这是默认开启的,这也是它不能很好地与 Identity Server 配合使用的原因。
您最终会导致用户被无规律地踢出。当你期望它踢出用户时,它不会。
无论如何,如何禁用ASP.NET Identity的这个功能???
UserManager 上有一个名为SupportsUserSecurityStamp 的列。
但是,它只是一个“getter”,我找不到任何配置设置来切换它以返回 false。
在我看来,唯一的方法是从 UserManager 类派生并让该属性只返回false。
这感觉就像一个黑客。尤其是当您在 Github 上查看该属性的代码时:
public virtual bool SupportsUserSecurityStamp
{
get
{
ThrowIfDisposed();
return Store is IUserSecurityStampStore<TUser>;
}
}
是否有“正确的方法”来关闭 ASP.NET Identity 的 SecurityStamp 功能?
旁注:目前,我们有一个创可贴的解决方案,通过这种配置使巨大的验证时间变得很长-
services.Configure<SecurityStampValidatorOptions>(
o => o.ValidationInterval = TimeSpan.FromHours(SecurityTimestampDuration)
);
所有这一切都是在印章验证之间建立一个巨大的窗口。但是完全关闭该功能更为可取。
干杯
【问题讨论】:
标签: asp.net-identity asp.net-core-identity