看看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中检查这段代码。几乎所有的符号和异步信息都被优化了。

谷歌也没帮上什么忙。

问题是:

什么是ASP中的SecurityStamp。NET身份和它的用途是什么? 在创建认证cookie时,SecurityStamp是否起作用? 是否需要采取任何安全后果或预防措施?例如,不要将此值发送到下游的客户端?


更新(9/16/2014)

源代码可在这里:

https://github.com/aspnet/Identity/ https://github.com/aspnet/Security/


当前回答

我发现令牌验证需要SecurityStamp。

回购协议: 在databsae中将SecurityStamp设置为null 生成一个令牌(正常工作) 验证令牌(失败)

其他回答

UseCookieAuthentication现在已弃用。我设法配置它使用

services.Configure<SecurityStampValidatorOptions>(o => 
    o.ValidationInterval = TimeSpan.FromSeconds(10));

从回复到回答每个请求。

这表示用户凭证的当前快照。因此,如果没有任何变化,戳记将保持不变。但如果用户的密码被更改,或者登录被删除(取消您的谷歌/fb帐户的链接),印章将会改变。这是需要的事情,如自动签名用户/拒绝旧的cookie时,这是2.0的一个特性。

Identity还不是开源的,目前还在开发过程中。

编辑:更新为2.0.0。因此,SecurityStamp的主要目的是在任何地方启用签出。其基本思想是,每当用户的某些安全相关内容(如密码)发生更改时,自动使任何现有的登录cookie无效是一个好主意,因此,如果您的密码/帐户之前被泄露,攻击者就不再有访问权限。

在2.0.0中,我们添加了下面的配置来钩住CookieMiddleware中的OnValidateIdentity方法,以查看SecurityStamp并在它发生更改时拒绝cookie。如果戳没有改变,它还会在每个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);

我发现令牌验证需要SecurityStamp。

回购协议: 在databsae中将SecurityStamp设置为null 生成一个令牌(正常工作) 验证令牌(失败)