示例#1
1
        private static UserManager<IdentityUser> CreateManager(IdentityFactoryOptions<UserManager<IdentityUser>> options, IOwinContext context)
        {
            var userStore = new UserStore<IdentityUser>(context.Get<OAuthDbContext>());
            var manager = new UserManager<IdentityUser>(userStore);

            return manager;
        }
        public static UserManagerFactory Create(IdentityFactoryOptions<UserManagerFactory> options,
            IOwinContext context)
        {
            var manager = new UserManagerFactory(new UserStore(context.Get<WealthEconomyContext>()));
            // Configure validation logic for usernames
            manager.UserValidator = new UserValidator<User, int>(manager)
            {
                AllowOnlyAlphanumericUserNames = false,
                RequireUniqueEmail = true
            };

            // Configure validation logic for passwords
            // TODO Review this!
            manager.PasswordValidator = new PasswordValidator
            {
                RequiredLength = 6,
                //RequireNonLetterOrDigit = true,
                RequireDigit = true,
                RequireLowercase = true,
                //RequireUppercase = true,
            };

            manager.EmailService = new EmailService();
            manager.ConfirmEmailUrl = string.Format("{0}/account/confirmEmail", AppSettings.ClientAppUrl);

            var dataProtectionProvider = options.DataProtectionProvider;
            if (dataProtectionProvider != null)
            {
                manager.UserTokenProvider =
                    new DataProtectorTokenProvider<User, int>(dataProtectionProvider.Create("ASP.NET Identity"));
            }

            return manager;
        }
        // callback function for IAppBuilder.CreatePerOwinContext
        public static AccountManager Create(IdentityFactoryOptions<AccountManager> options, IOwinContext context)
        {
            IAccountDataAccess accountData = context.Get<SqlConnection>().As<IAccountDataAccess>();
            AccountManager manager = new AccountManager(accountData);

            return manager;
        }
        public static CategoryManager Create(IdentityFactoryOptions<CategoryManager> options, IOwinContext context)
        {
            ICategoryDataAccess categoryData = context.Get<SqlConnection>().As<ICategoryDataAccess>();
            CategoryManager manager = new CategoryManager(categoryData);

            return manager;
        }
        public static ApplicationUserManager CreateApplicationUserManager(
            IdentityFactoryOptions<ApplicationUserManager> options,
            IOwinContext context)
        {
            var manager =
                new ApplicationUserManager(
                    new ApplicationUserStore(context.Get<UrfIdentityDataContext>()));

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

            // Configure validation logic for passwords
            manager.PasswordValidator = new PasswordValidator
            {
                RequiredLength = 8,
                RequireNonLetterOrDigit = true,
                RequireDigit = true,
                RequireLowercase = true,
                RequireUppercase = true
            };

            // Configure user lockout defaults
            manager.UserLockoutEnabledByDefault = true;
            manager.DefaultAccountLockoutTimeSpan = TimeSpan.FromMinutes(5);
            manager.MaxFailedAccessAttemptsBeforeLockout = 5;

            // 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 it
            // in here.
            manager.RegisterTwoFactorProvider(
                "SMS Code", new PhoneNumberTokenProvider<ApplicationUser, Guid>
                {
                    MessageFormat = AccountResources.OAuth_SMS_Body
                });

            manager.RegisterTwoFactorProvider(
                "Email Code", new EmailTokenProvider<ApplicationUser, Guid>
                {
                    Subject = AccountResources.OAuth_Email_Subject,
                    BodyFormat = AccountResources.OAuth_Email_Body
                });

            manager.SmsService = new SmsMessagingService();
            manager.EmailService = new EmailMessagingService();

            var dataProtectionProvider = options.DataProtectionProvider;
            if (dataProtectionProvider != null)
            {
                manager.UserTokenProvider =
                    new DataProtectorTokenProvider<ApplicationUser, Guid>(
                        dataProtectionProvider.Create("UrfIdentity"));
            }
            return manager;
        }
        public static UserManager<User> Create(IdentityFactoryOptions<UserManager<User>> options, IOwinContext context)
        {
            var userManager = new UserManager<User>(new UserStore());
            userManager.UserLockoutEnabledByDefault = true;
            userManager.MaxFailedAccessAttemptsBeforeLockout = 5;
            userManager.DefaultAccountLockoutTimeSpan = TimeSpan.FromMinutes(5);

            return userManager;
        }
        internal static BackOfficeUserManager InitUserManager(BackOfficeUserStore store, UmbracoMembershipProviderBase membershipProvider, IdentityFactoryOptions<BackOfficeUserManager> options)
        {
            var manager = new UmbracoEasyADUserManager(store);
            
            // Just use the InitUserManager method in Umbraco!
            manager.InitUserManager(manager, membershipProvider, options);

            return manager;
        }
 public static ApplicationSignInManager CreateApplicationSignInManager(
     IdentityFactoryOptions<ApplicationSignInManager> options,
     IOwinContext context)
 {
     return
         new ApplicationSignInManager(
             context.GetUserManager<ApplicationUserManager>(),
             context.Authentication);
 }
示例#9
0
        public static VGUserManager Create(IdentityFactoryOptions<VGUserManager> options, IOwinContext context)
        {
            var manager = new VGUserManager();

            var dataProtectionProvider = options.DataProtectionProvider;
            if (dataProtectionProvider != null)
            {
                manager.UserTokenProvider = new DataProtectorTokenProvider<User>(dataProtectionProvider.Create("ASP.NET Identity"));
            }
            return manager;
        }
        // See http://bitoftech.net/2015/03/11/asp-net-identity-2-1-roles-based-authorization-authentication-asp-net-web-api/
        public static ApplicationRoleManager CreateApplicationRoleManager(
            IdentityFactoryOptions<ApplicationRoleManager> options,
            IOwinContext context)
        {
            var appRoleManager =
                new ApplicationRoleManager(
                    new ApplicationRoleStore(
                        context.Get<UrfIdentityDataContext>()));

            return appRoleManager;
        }
示例#11
0
        public static UserManager<User, int> CreateUserManager(
            IdentityFactoryOptions<UserManager<User, int>> options, IOwinContext context)
        {
            var manager = new CustomUserManager(new CustomUserStore(context.Get<CustomDbContext>()));
            // Configure validation logic for usernames
            manager.UserValidator = new UserValidator<User, int>(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 = true;
            manager.DefaultAccountLockoutTimeSpan = TimeSpan.FromMinutes(5);
            manager.MaxFailedAccessAttemptsBeforeLockout = 5;

            // 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 it in here.
            manager.RegisterTwoFactorProvider("Phone Code", new PhoneNumberTokenProvider<User, int>
            {
                MessageFormat = "Your security code is {0}"
            });
            manager.RegisterTwoFactorProvider("Email Code", new EmailTokenProvider<User, int>
            {
                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<User, int>(dataProtectionProvider.Create("ASP.NET Identity"));
            }
            return manager;
        }
示例#12
0
        public UserManager<ApplicationUser> Create(IdentityFactoryOptions<AuthRepository> options, IOwinContext context)
        {
            var appDbContext = context.Get<ERPInventoryDBContext>();

            _userManager.EmailService = new EmailService();

            var dataProtectionProvider = options.DataProtectionProvider;
            if (dataProtectionProvider != null)
            {
                _userManager.UserTokenProvider = new DataProtectorTokenProvider<ApplicationUser>(dataProtectionProvider.Create("ASP.NET Identity"))
                {
                    //Code for email confirmation and reset password life time
                    TokenLifespan = TimeSpan.FromHours(6)
                };
            }

            return _userManager;
        }
        internal UserIdentityService(IUserStore<ApplicationUser> userStore, IAuthenticationManager authenticationManager)
        {
            if (userStore == null)
            {
                throw new ArgumentNullException("userStore");
            }

            if (authenticationManager == null)
            {
                throw new ArgumentNullException("authenticationManager");
            }

            //this.UserDatabase = documentStore;

            var options = new IdentityFactoryOptions<ApplicationUserManager>();

            this.UserManager = ApplicationUserManager.Create(options, userStore);
            this.SignInManager = new ApplicationSignInManager(this.UserManager, authenticationManager);
        }
示例#14
0
        public XcendantIdentityFixture()
        {
            var builder = new ContainerBuilder();

            builder.RegisterType<XcendantTestAuthContext>().As<AbstractXcendentAuthContext>().InstancePerLifetimeScope();

            var stubUserStore = new XcendantTestUserStore<XcendentUser>();

            //builder.Register(c => stubUserStore).
            //    As<AbstractXcendentUserStore<XcendentUser, AbstractXcendentAuthContext>>().InstancePerLifetimeScope();

            var stubIdentityOptions = new IdentityFactoryOptions<AbstractXcendentUserManager<XcendentUser>>
            {
                DataProtectionProvider = new Microsoft.Owin.Security.DataProtection.DpapiDataProtectionProvider("Application​")
            };
            builder.Register(c => stubIdentityOptions);
            var stubUserManager = Substitute.For<XcendentTestUserManager>(stubUserStore, stubIdentityOptions);
            //stubUserManager.CreateAsync(new XcendentUser(), "").ReturnsForAnyArgs(Task.FromResult(IdentityResult.Success));
            //builder.RegisterType<XcendentTestUserManager>().As<AbstractXcendentUserManager<XcendentUser>>().InstancePerLifetimeScope();
            builder.Register(c => stubUserManager).As<AbstractXcendentUserManager<XcendentUser>>().InstancePerLifetimeScope();
            Container = builder.Build();
        }
示例#15
0
        public static UserManager Create(IdentityFactoryOptions<UserManager> options, IOwinContext context)
        {
            var manager = new UserManager();

            var user = context.Authentication.User.Identity;
            manager.CurrentPrincipal = user.GetUserPrincipal().Result;

            if (manager.CurrentPrincipal != null)
            {
                using (AppDbContext Context = new AppDbContext())
                {
                    manager.CurrentUser = manager.CurrentPrincipal.GetAppUser(Context).Result;

                    if (manager.CurrentUser != null)
                    {
                        manager.UserRoles = Context.AppUserRoles.Where(x => x.AppUserId == manager.CurrentUser.Id).Select(x => x.AppRole.Role).ToList();
                    }
                }
            }

            return manager;
        }
        // Methods
        public static ApplicationUserManager Create(IdentityFactoryOptions<ApplicationUserManager> options, IOwinContext context)
        {
            #region Contracts

            if (options == null) throw new ArgumentNullException();
            if (context == null) throw new ArgumentNullException();

            #endregion

            // 建立使用者管理員
            var userManager = new ApplicationUserManager(context.Get<ApplicationDbContext>());
            if (userManager == null) throw new InvalidOperationException();

            // 設定使用者名稱的驗證邏輯
            userManager.UserValidator = new UserValidator<ApplicationUser>(userManager)
            {
                AllowOnlyAlphanumericUserNames = false,
                RequireUniqueEmail = true
            };

            // 設定密碼的驗證邏輯
            userManager.PasswordValidator = new PasswordValidator
            {
                RequiredLength = 5,              // 最小長度
                RequireNonLetterOrDigit = false, // 是否需要一個非字母或是數字
                RequireDigit = false,            // 是否需要一個數字
                RequireLowercase = false,        // 是否需要一個小寫字母
                RequireUppercase = false,        // 是否需要一個大寫字母
            };

            // 設定使用者鎖定詳細資料
            userManager.UserLockoutEnabledByDefault = true;
            userManager.DefaultAccountLockoutTimeSpan = TimeSpan.FromMinutes(5);
            userManager.MaxFailedAccessAttemptsBeforeLockout = 5;

            // 註冊雙因素驗證提供者。此應用程式使用手機和電子郵件接收驗證碼以驗證使用者
            // 您可以撰寫專屬提供者,並將它外掛到這裡。
            userManager.RegisterTwoFactorProvider("電話代碼", new PhoneNumberTokenProvider<ApplicationUser>
            {
                MessageFormat = "您的安全碼為 {0}"
            });
            userManager.RegisterTwoFactorProvider("電子郵件代碼", new EmailTokenProvider<ApplicationUser>
            {
                Subject = "安全碼",
                BodyFormat = "您的安全碼為 {0}"
            });
            userManager.EmailService = new EmailService();
            userManager.SmsService = new SmsService();
            var dataProtectionProvider = options.DataProtectionProvider;
            if (dataProtectionProvider != null)
            {
                userManager.UserTokenProvider = new DataProtectorTokenProvider<ApplicationUser>(dataProtectionProvider.Create("ASP.NET Identity"));
            }

            // 回傳
            return userManager;
        }
示例#17
0
 public static ApplicationRoleManager Create(IdentityFactoryOptions <ApplicationRoleManager> options, IOwinContext context)
 {
     return(new ApplicationRoleManager(new RoleStore <IdentityRole>(new UnitOfWork().Session)));
 }
示例#18
0
 public static ApplicationRoleManager Create(IdentityFactoryOptions <ApplicationRoleManager> options, IOwinContext context)
 {
     return(new ApplicationRoleManager(new RoleStore <IdentityRole>(context.Get <ApplicationDbContext>())));
 }
 private static UserManager<ApplicationUser>  CreateUserManager(IdentityFactoryOptions<UserManager<ApplicationUser>> options, IOwinContext context)
 {
     return CreateUserManager(options.DataProtectionProvider, context.Get<IContosoWebContext>());
 }
 private static SignInManager<ApplicationUser, string> CreateSignInManager(IdentityFactoryOptions<SignInManager<ApplicationUser, string>> options, IOwinContext context)
 {
     return new SignInManager<ApplicationUser, string>(context.GetUserManager<UserManager<ApplicationUser>>(), context.Authentication);
 }
 public static CustomCategoryManager Create(IdentityFactoryOptions<CustomCategoryManager> options, IOwinContext context)
 {
     return new CustomCategoryManager(new CustomCategoryStore(context.Get<CustomDbContext>()));
 }
 // Methods
 public static ApplicationUserManager Create(IdentityFactoryOptions<ApplicationUserManager> options, IOwinContext context)
 {
     return ApplicationUserManager.Create(context.Get<ApplicationDbContext>(), options.DataProtectionProvider);
 }
示例#23
0
 public static ApplicationSignInManager Create(IdentityFactoryOptions <ApplicationSignInManager> options, IOwinContext context)
 {
     return(new ApplicationSignInManager(context.GetUserManager <ApplicationUserManager>(), context.Authentication));
 }
示例#24
0
 public static IoTClientManager Create(IdentityFactoryOptions<IoTClientManager> options, IOwinContext context)
 {
     return new IoTClientManager(context.Get<IdentityDbContext>());
 }
示例#25
0
 public static FlightRoleManager Create(IdentityFactoryOptions<FlightRoleManager> options, IOwinContext context)
 {
     return new FlightRoleManager(new
     RoleStore<FlightRole>(context.Get<FlightIdentityDbContext>()));
 }
示例#26
0
 public static ApplicationSignInManager Create(IdentityFactoryOptions<ApplicationSignInManager> options, IOwinContext context)
 {
     CommonTools._signInManager= new ApplicationSignInManager(context.GetUserManager<ApplicationUserManager>(), context.Authentication);
     // return new ApplicationSignInManager(context.GetUserManager<ApplicationUserManager>(), context.Authentication);
     return (BlackOwl.Core.Application.ApplicationSignInManager)CommonTools._signInManager;
 }
 // Methods
 public static ApplicationPermissionManager Create(IdentityFactoryOptions<ApplicationPermissionManager> options, IOwinContext context)
 {
     return new ApplicationPermissionManager(context.Get<ApplicationDbContext>());
 }
 // Methods
 public static ApplicationRoleManager Create(IdentityFactoryOptions<ApplicationRoleManager> options, IOwinContext context)
 {
     return ApplicationRoleManager.Create(context.Get<ApplicationDbContext>());
 }
示例#29
0
 public static SSOAppConfigManager Create(IdentityFactoryOptions<SSOAppConfigManager> options, IOwinContext context)
 {
     return new SSOAppConfigManager(context.Get<SSODbContext>());
 }
示例#30
0
 public static GroupManager Create(IdentityFactoryOptions<GroupManager> options, IOwinContext context)
 {
     return new GroupManager(context.Get<IdentityDbContext>());
 }
示例#31
0
 public static OrderManager Create(IdentityFactoryOptions<OrderManager> options, IOwinContext context)
 {
     return new OrderManager(context.Get<ApplicationDbContext>());
 }
示例#32
0
 public static PermissionManager Create(IdentityFactoryOptions<PermissionManager> options, IOwinContext context)
 {
     return new PermissionManager(context.Get<IdentityDbContext>());
 }
示例#33
0
 public static SSOIoTUserManager Create(IdentityFactoryOptions<SSOIoTUserManager> options, IOwinContext context)
 {
     return new SSOIoTUserManager();
 }
示例#34
0
        public static ApplicationUserManager Create(IdentityFactoryOptions <ApplicationUserManager> options, IOwinContext context)
        {
            var manager = new ApplicationUserManager(new UserStore <ApplicationUser>(context.Get <ApplicationDbContext>()));

            // Configure validation logic for usernames
            manager.UserValidator = new UserValidator <ApplicationUser>(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          = true;
            manager.DefaultAccountLockoutTimeSpan        = TimeSpan.FromMinutes(5);
            manager.MaxFailedAccessAttemptsBeforeLockout = 5;

            // 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 it in here.
            manager.RegisterTwoFactorProvider("Phone Code", new PhoneNumberTokenProvider <ApplicationUser>
            {
                MessageFormat = "Your security code is {0}"
            });
            manager.RegisterTwoFactorProvider("Email Code", new EmailTokenProvider <ApplicationUser>
            {
                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 <ApplicationUser>(dataProtectionProvider.Create("ASP.NET Identity"));
            }

            //var roleManager = new RoleManager<IdentityRole>(new RoleStore<IdentityRole>(context.Get<ApplicationDbContext>()));
            //IdentityResult result = null;
            //if (!roleManager.RoleExists("Admin"))
            //    result = roleManager.Create(new IdentityRole("Admin"));
            //if (!roleManager.RoleExists("Page Editor"))
            //    result = roleManager.Create(new IdentityRole("Page Editor"));

            //ApplicationUser user = manager.FindByName("*****@*****.**");
            //if (!manager.IsInRole(user.Id, "Admin"))
            //    result = manager.AddToRole(user.Id, "Admin");
            //if (!manager.IsInRole(user.Id, "Page Editor"))
            //    result = manager.AddToRole(user.Id, "Page Editor");
            //user.Mailbox = "123456789";
            //result = manager.Update(user);

            //user = manager.FindByName("*****@*****.**");
            //if (!manager.IsInRole(user.Id, "Admin"))
            //    roleResult = manager.AddToRole(user.Id, "Admin");
            //if (!manager.IsInRole(user.Id, "Page Editor"))
            //    roleResult = manager.AddToRole(user.Id, "Page Editor");

            //var user = manager.FindByName("*****@*****.**");
            //if (!manager.IsInRole(user.Id, "Admin"))
            //    manager.AddToRole(user.Id, "Admin");
            //if (!manager.IsInRole(user.Id, "Page Editor"))
            //    manager.AddToRole(user.Id, "Page Editor");

            return(manager);
        }