Example #1
0
        public async Task <ClaimsIdentity> GenerateUserIdentityAsync(MyUserManager userManager)
        {
            var userIdentity = await userManager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);

            // Add custom user claims here
            return(userIdentity);
        }
Example #2
0
        public static MyUserManager Create(IdentityFactoryOptions <MyUserManager> options, IOwinContext context)
        {
            var manager = new MyUserManager(new UserStore <User, MyRole, long, MyLogin, MyUserRole, MyClaim>(context.Get <XContext>()));

            // Configure validation logic for usernames
            manager.UserValidator = new UserValidator <MyUser, long>(manager)
            {
                AllowOnlyAlphanumericUserNames = false,
                RequireUniqueEmail             = true
            };
            // Configure validation logic for passwords
            manager.PasswordValidator = new PasswordValidator
            {
                RequiredLength          = 6,
                RequireNonLetterOrDigit = true,
                RequireDigit            = true,
                RequireLowercase        = true,
                RequireUppercase        = true,
            };
            // 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 <User, long>
            {
                MessageFormat = "Your security code is: {0}"
            });
            manager.RegisterTwoFactorProvider(
                "EmailCode",
                new EmailTokenProvider <User, long>
            {
                Subject    = "Security Code",
                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 <MyUser, long>(dataProtectionProvider.Create("ASP.NET Identity"));
            }
            return(manager);
        }