首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >什么是ASP.NET Identity的IUserSecurityStampStore<TUser>接口?

什么是ASP.NET Identity的IUserSecurityStampStore<TUser>接口?
EN

Stack Overflow用户
提问于 2013-10-21 14:09:06
回答 3查看 68.2K关注 0票数 195

查看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.NET Identity中的cookies是什么?它的用途是什么?
  • 在创建身份验证cookies时,SecurityStamp是否扮演任何角色?
  • 对此是否有任何安全后果或需要采取的预防措施?例如,不将此值向下发送到客户端?

更新(9/16/2014)

源代码可以在这里找到:

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 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);
票数 240
EN

Stack Overflow用户

发布于 2017-12-23 04:11:18

现在UseCookieAuthentication已经是deprecated了。我设法使用以下命令来配置它

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

已从回复移动到每个request的应答。

票数 15
EN

Stack Overflow用户

发布于 2015-07-23 10:24:02

我观察到令牌验证需要SecurityStamp。

To repo:在数据库中将SecurityStamp设置为null生成令牌(工作正常)验证令牌(失败)

票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19487322

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档