相关疑难解决方法(0)

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

看看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);
    }
}
Run Code Online (Sandbox Code Playgroud)

IUserSecurityStampStore由默认实现EntityFramework.UserStore<TUser>,实质上获取和设置TUser.SecurityStamp属性.

经过一些挖掘之后,似乎a SecurityStampGuid在关键点新生成的UserManager(例如,更改密码).

因为我在Reflector中检查这段代码,所以我无法真正破译.几乎所有的符号和异步信息都已经过优化.

此外,谷歌也没有太多帮助.

问题是:

  • 什么是SecurityStampASP.NET标识,它用于什么?
  • SecurityStamp创建身份验证cookie时,是否扮演任何角色?
  • 是否有任何需要采取的安全措施或预防措施?例如,不要将此值向下游发送给客户端?

更新(2014年9月16日)

源代码在这里:

asp.net asp.net-mvc asp.net-mvc-5 asp.net-identity

168
推荐指数
3
解决办法
6万
查看次数

ASP Identity 2.0:重新生成身份

我无法让ASP Identity按需刷新存储在cookie中的身份.

Startup.Auth.cs文件中,cookie设置为重新生成,如下所示:

app.UseCookieAuthentication(new CookieAuthenticationOptions
            {
                AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
                LoginPath = new PathString("/Account/Login"),
                Provider = new CookieAuthenticationProvider
                {
                    OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<QuizSparkUserManager, QuizSparkUser, int>(
                    validateInterval: TimeSpan.FromMinutes(30),
                    regenerateIdentityCallback: ((manager, user) => manager.CreateIdentityAsync(user, DefaultAuthenticationTypes.ApplicationCookie)),
                    getUserIdCallback: ((claimsIdentity) => int.Parse(claimsIdentity.GetUserId())))
                }
            });
Run Code Online (Sandbox Code Playgroud)

但是我无法弄清楚如何刷新User.Identity代码中的内容,即在我需要刷新时强制刷新身份cookie.

我希望能够以编程方式使用重新生成身份回调,这可能吗?

我的问题与此类似:如何使用Asp.Net Identity 2将用户添加到角色后使.AspNet.ApplicationCookie无效?

但是我想刷新而不是使cookie无效.

编辑


在查看链接的问题后,我尝试了以下(没有完整的错误处理):

IOwinContext context = Request.GetOwinContext();
QuizSparkSignInManager manager = context.Get<QuizSparkSignInManager>();
ClaimsIdentity newIdentity = manager.CreateUserIdentity(manager.UserManager.FindById(User.Identity.GetUserId<int>()));

AuthenticateResult authenticationContext =
                    await context.Authentication.AuthenticateAsync(DefaultAuthenticationTypes.ApplicationCookie);

if (authenticationContext != null)
{
    context.Authentication.AuthenticationResponseGrant = new AuthenticationResponseGrant(
                        newIdentity, authenticationContext.Properties);
}

bool …
Run Code Online (Sandbox Code Playgroud)

c# asp.net cookies asp.net-identity-2

8
推荐指数
1
解决办法
9590
查看次数