Reuse Claim in regenerateIdentityCallback in Owin Identity in MVC5

前端 未结 2 1198
南旧
南旧 2021-02-20 00:18

I am using MVC5 with Owin identity.

I am struggling to reuse any custom Claims in regenerateIdentityCallback.

I have in Startup this configuration (as provided i

相关标签:
2条回答
  • 2021-02-20 00:25

    You can obtain the same result by doing this (context.Identity is the previous identity):

    OnValidateIdentity = context => SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, DtbsUser, Guid>(
                                validateInterval: TimeSpan.FromSeconds(30),
                                regenerateIdentityCallback:
                                    (manager, user) =>
                                        user.GenerateUserIdentityAsync(manager, context.Identity),
                                getUserIdCallback: (ci) => Guid.Parse(ci.GetUserId())).Invoke(context)
    
    0 讨论(0)
  • 2021-02-20 00:43

    I gave up and created own SecurityStampValidator which does exactly the same as original, but passes the current claimsIdentity to regenerateIdentityCallback as param. Not at all happy about this solution, but it works.

           OnValidateIdentity = MySecurityStampValidator.OnValidateIdentity<ApplicationUserManager, DtbsUser, Guid>(
                        validateInterval: TimeSpan.FromSeconds(10),
                        regenerateIdentityCallback: (manager, user, previousIdentity) => user.GenerateUserIdentityAsync(manager, previousIdentity),  
                        getUserIdCallback: user => Guid.Parse(user.GetUserId()))
    
    0 讨论(0)
提交回复
热议问题