public static ApplicationRoleManager Create(IdentityFactoryOptions <ApplicationRoleManager> options, IOwinContext context) { var container = MvcApplication.BootstrapContainer(); var log = container.Resolve <ILogger>(); var session = container.Resolve <ISession>(); var errorHandler = container.Resolve <ExceptionManager>(); var roleManager = new ApplicationRoleManager(new RoleRepository(session, errorHandler, log)); return(roleManager); }
public static ApplicationUserManager Create(IdentityFactoryOptions <ApplicationUserManager> options, IOwinContext context) { var container = MvcApplication.BootstrapContainer(); var log = container.Resolve <ILogger>(); var session = container.Resolve <ISession>(); var errorHandler = container.Resolve <ExceptionManager>(); var manager = new ApplicationUserManager(new UserRepository(session, errorHandler, log)); // Configure validation logic for usernames manager.UserValidator = new UserValidator <User>(manager) { AllowOnlyAlphanumericUserNames = false, RequireUniqueEmail = true }; // Configure validation logic for passwords manager.PasswordValidator = new PasswordValidator { RequiredLength = 6, RequireNonLetterOrDigit = false, RequireDigit = false, 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("PhoneCode", new PhoneNumberTokenProvider <User> { MessageFormat = "Your security code is {0}" }); manager.RegisterTwoFactorProvider("EmailCode", new EmailTokenProvider <User> { 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>(dataProtectionProvider.Create("ASP.NET Identity")); } return(manager); }
public Startup() { PublicClientId = "self"; var container = MvcApplication.BootstrapContainer(); var session = container.Resolve <ISession>(); var exManager = container.Resolve <ExceptionManager>(); var log = container.Resolve <ILogger>(); UserManagerFactory = new UserManager <User>(new UserRepository(session, exManager, log)); RoleManagerFactory = new RoleManager <Role>(new RoleRepository(session, exManager, log)); CookieOptions = new CookieAuthenticationOptions(); OAuthOptions = new OAuthAuthorizationServerOptions { TokenEndpointPath = new PathString("/Token"), Provider = new ApplicationOAuthProvider(PublicClientId, () => UserManagerFactory), AuthorizeEndpointPath = new PathString("/api/Account/ExternalLogin"), AccessTokenExpireTimeSpan = TimeSpan.FromDays(14), AllowInsecureHttp = true }; }