查看ASP.NET Identity (ASP.NET中的新成员实现),我在实现自己的UserStore
时遇到了这个接口
//Microsoft.AspNet.Identity.Core.dll
namespace Microsoft.AspNet.Identity
{
public interface IUserSecurityStampStore<TUser> :
{
// Methods
Task<string> GetSecurityStampAsync(TUser user);
Task SetSecurityStampAsync(TUser user, string stamp);
}
}
IUserSecurityStampStore
由默认的EntityFramework.UserStore<TUser>
实现,它本质上是获取和设置TUser.SecurityStamp
属性。
经过进一步挖掘,似乎SecurityStamp
是在UserManager
中的关键点(例如,更改密码)处新生成的Guid
。
因为我在Reflector中检查了这段代码,所以我不能对此做更多的解释。几乎所有的符号和异步信息都被优化出来了。
此外,谷歌也帮不了太多忙。
问题包括:
SecurityStamp
是否扮演任何角色?更新(9/16/2014)
源代码可以在这里找到:
发布于 2013-10-22 05:26:45
这意味着表示用户凭据的当前快照。因此,如果没有任何变化,图章将保持不变。但是,如果用户的密码被更改,或者一个登录被删除(解除你的google/fb帐户的链接),戳就会改变。这对于自动为用户签名/当发生这种情况时拒绝旧cookie之类的事情是必要的,这是2.0中即将推出的一个功能。
Identity还不是开源的,它目前仍在开发中。
编辑:为2.0.0.更新,因此SecurityStamp
的主要目的是启用sign out everywhere。其基本思想是,无论何时更改用户的安全相关内容,如密码,最好自动使cookie中的任何现有登录无效,因此,如果您的密码/帐户以前被泄露,攻击者将不再具有访问权限。
在2.0.0中,我们添加了以下配置来挂钩CookieMiddleware
中的OnValidateIdentity
方法,以查看SecurityStamp
并在cookies发生更改时拒绝它。如果戳记不变,它还会在每个refreshInterval
中自动刷新数据库中的用户声明(这会处理角色变化等问题)
app.UseCookieAuthentication(new CookieAuthenticationOptions {
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Account/Login"),
Provider = new CookieAuthenticationProvider {
// Enables the application to validate the security stamp when the user logs in.
// This is a security feature which is used when you change a password or add an external login to your account.
OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>(
validateInterval: TimeSpan.FromMinutes(30),
regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))
}
});
如果您的应用程序想要显式触发此行为,它可以调用:
UserManager.UpdateSecurityStampAsync(userId);
发布于 2017-12-23 04:11:18
现在UseCookieAuthentication已经是deprecated了。我设法使用以下命令来配置它
services.Configure<SecurityStampValidatorOptions>(o =>
o.ValidationInterval = TimeSpan.FromSeconds(10));
已从回复移动到每个request的应答。
发布于 2015-07-23 10:24:02
我观察到令牌验证需要SecurityStamp。
To repo:在数据库中将SecurityStamp设置为null生成令牌(工作正常)验证令牌(失败)
https://stackoverflow.com/questions/19487322
复制相似问题