Пример #1
0
        public ClaimsIdentity GenerateUserIdentity(CustomIdentityUserManager manager)
        {
            // Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType
            var userIdentity = manager.CreateIdentity(this, DefaultAuthenticationTypes.ApplicationCookie);

            // Add custom user claims here
            return(userIdentity);
        }
        public static CustomIdentityUserManager Create(IdentityFactoryOptions <CustomIdentityUserManager> options,
                                                       IOwinContext context)
        {
            var manager = new CustomIdentityUserManager(new CustomUserStore());

            // Configure validation logic for usernames
            manager.UserValidator = new UserValidator <CustomIdentityUser>(manager)
            {
                AllowOnlyAlphanumericUserNames = false,
                //RequireUniqueEmail = true
            };

            // Configure validation logic for passwords
            manager.PasswordValidator = new PasswordValidator
            {
                RequiredLength          = 6,
                RequireNonLetterOrDigit = true,
                RequireDigit            = true,
                RequireLowercase        = true,
                RequireUppercase        = true,
            };
            // Configure user lockout defaults
            manager.UserLockoutEnabledByDefault          = bool.Parse(PODEnvironment.GetSetting("UserLockoutEnabledByDefault"));
            manager.DefaultAccountLockoutTimeSpan        = TimeSpan.FromMinutes(int.Parse(PODEnvironment.GetSetting("DefaultAccountLockoutTimeSpan")));
            manager.MaxFailedAccessAttemptsBeforeLockout = int.Parse(PODEnvironment.GetSetting("MaxFailedAccessAttemptsBeforeLockout"));
            // Register two factor authentication providers. This application uses Phone and Emails as a step of receiving a code for verifying the user
            // You can write your own provider and plug in here.
            //manager.RegisterTwoFactorProvider("PhoneCode", new PhoneNumberTokenProvider<IdentityUser>
            //{
            //    MessageFormat = "Your security code is: {0}"
            //});
            //manager.RegisterTwoFactorProvider("EmailCode", new EmailTokenProvider<IdentityUser>
            //{
            //    Subject = "SecurityCode",
            //    BodyFormat = "Your security code is {0}"
            //});

            manager.EmailService = new EmailService();
            //manager.SmsService = new SmsService();
            var dataProtectionProvider = options.DataProtectionProvider;

            if (dataProtectionProvider != null)
            {
                manager.UserTokenProvider =
                    new DataProtectorTokenProvider <CustomIdentityUser>(dataProtectionProvider.Create("ResetPassword"));
            }
            return(manager);
        }
Пример #3
0
        //public Task<ClaimsIdentity> GenerateUserIdentityAsync(CustomIdentityUserManager manager)
        //{
        //    return Task.FromResult(GenerateUserIdentity(manager));
        //}

        //public ClaimsIdentity GenerateUserIdentity(CustomIdentityUserManager manager)
        //{
        //    // Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType
        //    var userIdentity = manager.CreateIdentity(this, DefaultAuthenticationTypes.ApplicationCookie);
        //    userIdentity.AddClaim(new System.Security.Claims.Claim("RoleID", this.DBUser.Role.ID.ToString()));
        //    // Add custom user claims here
        //    return userIdentity;
        //}

        public async Task <ClaimsIdentity> GenerateUserIdentityAsync(CustomIdentityUserManager manager)
        {
            // Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType
            var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);

            string roleDisplayName = String.Format("{0} {1}", (OrganizationType)this.DBUser.Organization.OrganizationTypeID, this.DBUser.Role.RoleName);

            userIdentity.AddClaim(new System.Security.Claims.Claim("FullName", this.DBUser.FullName));
            userIdentity.AddClaim(new System.Security.Claims.Claim(ClaimTypes.Role, roleDisplayName));
            userIdentity.AddClaim(new System.Security.Claims.Claim("RoleID", this.DBUser.Role.RoleID.ToString()));
            userIdentity.AddClaim(new System.Security.Claims.Claim("IsAdmin", this.DBUser.Role.IsAdmin.ToString()));
            userIdentity.AddClaim(new System.Security.Claims.Claim("OrganizationID", this.DBUser.Organization.OrganizationID.ToString()));
            userIdentity.AddClaim(new System.Security.Claims.Claim("OrganizationTypeID", this.DBUser.Organization.OrganizationTypeID.ToString()));
            userIdentity.AddClaim(new System.Security.Claims.Claim("OrganizationName", this.DBUser.Organization.OrganizationName));

            return(userIdentity);
        }
Пример #4
0
 public Task <ClaimsIdentity> GenerateUserIdentityAsync(CustomIdentityUserManager manager)
 {
     return(Task.FromResult(GenerateUserIdentity(manager)));
 }
 public ApplicationSignInManager(CustomIdentityUserManager userManager, IAuthenticationManager authenticationManager)
     : base(userManager, authenticationManager)
 {
 }