Exemplo n.º 1
0
            public static ApplicationUserManager Create(IdentityFactoryOptions <ApplicationUserManager> options,
                                                        IOwinContext context)
            {
                IdentityUserContext    db      = context.Get <IdentityUserContext>();
                ApplicationUserManager manager = new ApplicationUserManager(new UserStore <ApplicationUser>(db));
                var dataProtectionProvider     = options.DataProtectionProvider;

                if (dataProtectionProvider != null)
                {
                    manager.UserTokenProvider = new DataProtectorTokenProvider <ApplicationUser>(dataProtectionProvider.Create("UsedGoodApp"));
                }
                return(manager);
            }
Exemplo n.º 2
0
        /// <summary>
        /// Gets a claim value by it's type name
        /// </summary>
        /// <param name="claimType">Claim type name</param>
        /// <returns>Claim value if found, <value>null</value> otherwise</returns>
        public static async Task SetClaimAsync <TUser, TKey, TUserClaim, TUserLogin, TUserToken>(this IdentityUserContext <TUser, TKey, TUserClaim, TUserLogin, TUserToken> identityUserContext, IdentityUser <TKey> user, string claimType, string claimValue)
            where TUser : IdentityUser <TKey>
            where TKey : IEquatable <TKey>
            where TUserClaim : IdentityUserClaim <TKey>
            where TUserLogin : IdentityUserLogin <TKey>
            where TUserToken : IdentityUserToken <TKey>
        {
            IdentityUserClaim <TKey> claimName = await identityUserContext.UserClaims.FirstOrDefaultAsync(x => x.UserId.Equals(user.Id) && x.ClaimType.Equals(claimType, StringComparison.OrdinalIgnoreCase));

            claimName.ClaimValue = claimValue;
        }