为了账号安全,请及时绑定邮箱和手机立即绑定

ASP.NET标识的IUserSecurityStampStore<TUser>接口是什么?

ASP.NET标识的IUserSecurityStampStore<TUser>接口是什么?

波斯汪 2019-10-13 12:08:59
ASP.NET标识的IUserSecurityStampStore<TUser>接口是什么?查看ASP.NET标识(ASP.NET中的新成员关系实现),我在实现自己的接口时遇到了这个接口UserStore://Microsoft.AspNet.Identity.Core.dllnamespace 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是Guid中的关键点新生成的UserManager(例如,更改密码)。除了这个,我不能破译更多的代码,因为我正在检查这段代码反射器..几乎所有的符号和异步信息都被优化了。此外,谷歌对此也没有多大帮助。问题如下:什么是SecurityStamp在ASP.NET标识中,它用于什么?是否SecurityStamp在创建身份验证cookie时扮演什么角色?是否需要采取任何安全措施或预防措施?例如,不要将此值向下发送给客户端?这里有源代码:https://github.com/aspnet/Identity/https://github.com/aspnet/Security/
查看完整描述

3 回答

?
MM们

TA贡献1886条经验 获得超2个赞

这意味着表示用户凭据的当前快照。因此,如果没有变化,邮票将保持不变。但是,如果用户的密码被更改,或者登录被删除(取消链接您的Google/FB帐户),邮票就会改变。当出现这种情况时,需要自动对用户签名/拒绝旧cookie,这是2.0版的一个特性。

标识还不是开源的,它目前仍在酝酿中。

更新为2.0.0。所以主要的目的是SecurityStamp就是让所有地方都能签字。其基本思想是,每当用户更改与安全有关的内容(如密码)时,自动使cookie中的任何现有标识失效是一个好主意,因此,如果您的密码/帐户先前被破坏,攻击者将不再具有访问权限。

在2.0.0中,我们添加了以下配置来挂起OnValidateIdentity方法中的CookieMiddleware看看SecurityStamp当曲奇变的时候拒绝它。它还会自动刷新数据库中的用户声明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);



查看完整回答
反对 回复 2019-10-14
?
狐的传说

TA贡献1804条经验 获得超3个赞

我观察到了令牌验证所需的安全印章。

要回购:将数据库中的SecurityStamp设置为null,生成一个令牌(Works,ok),验证令牌(失败)



查看完整回答
反对 回复 2019-10-14
?
隔江千里

TA贡献1906条经验 获得超10个赞

UseCookieAuthentication是弃用到现在为止。我设法使用

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

从回复移到回答请求.


查看完整回答
反对 回复 2019-10-14
  • 3 回答
  • 0 关注
  • 454 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信