- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
查看 ASP.NET Identity(ASP.NET 中的新成员身份实现),我在实现自己的 UserStore
时遇到了这个接口(interface)。 :
//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
是 Guid
这是在UserManager
中的关键点处新生成的(例如,更改密码)。
由于我正在 Reflector 中检查此代码,因此我无法真正破译除此之外的内容。几乎所有符号和异步信息都已被优化。
此外,Google 也没有提供太多帮助。
SecurityStamp
ASP.NET Identity 中的内容以及它的用途是什么?SecurityStamp
是吗?创建身份验证 cookie 时发挥什么作用?源代码在这里:
最佳答案
这意味着您的用户凭据的当前快照。因此,如果没有任何变化,邮票将保持不变。但是,如果用户的密码被更改,或者登录信息被删除(取消链接您的 google/fb 帐户),则标记将会更改。这是在发生这种情况时自动签名用户/拒绝旧 cookie 之类的事情所需要的,这是 2.0 中提供的功能。
Identity 尚未开源,目前仍在开发中。
编辑:针对 2.0.0 进行了更新。因此,SecurityStamp
的主要目的是在任何地方启用注销。基本思想是,每当用户更改与安全相关的内容(例如密码)时,最好自动使任何现有的登录 cookie 失效,因此,如果您的密码/帐户之前已被泄露,攻击者将不再具有访问权限。
在 2.0.0 中,我们添加了以下配置来 Hook 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);
关于asp.net - ASP.NET Identity 的 IUserSecurityStampStore<TUser> 接口(interface)是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19487322/
在我的 MVC-5 应用程序中,我必须 手动创建安全标记值 .身份团队的当前实现似乎使用了 guid。 Guid.NewGuid().ToString("D") 自己创建一个新的 Guid 以用作新的
查看 ASP.NET Identity(ASP.NET 中的新成员身份实现),我在实现自己的 UserStore 时遇到了这个接口(interface)。 : //Microsoft.AspNet.I
我是一名优秀的程序员,十分优秀!