/// <summary> /// Method to create a user manager which can be used to specify a custom IExternalLoginStore /// </summary> /// <param name="options"></param> /// <param name="memberService"></param> /// <param name="memberTypeService"></param> /// <param name="memberGroupService"></param> /// <param name="externalLoginStore"></param> /// <param name="membershipProvider"></param> /// <returns></returns> public static UmbracoMembersUserManager <TUser> Create( IdentityFactoryOptions <UmbracoMembersUserManager <TUser> > options, IMemberService memberService, IMemberTypeService memberTypeService, IMemberGroupService memberGroupService, IProfilingLogger profilingLogger, IScopeProvider scopeProvider, IExternalLoginStore externalLoginStore = null, IdentityEnabledMembersMembershipProvider membershipProvider = null) { //we'll grab some settings from the membership provider var provider = membershipProvider ?? Membership.Providers["UmbracoMembershipProvider"] as IdentityEnabledMembersMembershipProvider; if (provider == null) { throw new InvalidOperationException("In order to use " + typeof(UmbracoMembersUserManager <>) + " the Umbraco members membership provider must be of type " + typeof(IdentityEnabledMembersMembershipProvider)); } if (externalLoginStore == null) { //use the default externalLoginStore = new ExternalLoginStore(scopeProvider); } return(Create(options, new UmbracoMembersUserStore <TUser>(profilingLogger, memberService, memberTypeService, memberGroupService, provider, externalLoginStore), membershipProvider)); }
/// <summary> /// Configure identity User Manager for Umbraco with custom user store /// </summary> /// <typeparam name="T"></typeparam> /// <param name="app"></param> /// <param name="customUserStore"></param> /// <param name="appContext"></param> /// <param name="membershipProvider"></param> public static void ConfigureUserManagerForUmbracoMembers <T>(this IAppBuilder app, UmbracoMembersUserStore <T> customUserStore, ApplicationContext appContext, IdentityEnabledMembersMembershipProvider membershipProvider = null) where T : UmbracoIdentityMember, new() { if (appContext == null) { throw new ArgumentNullException("appContext"); } //Don't proceed if the app is not ready if (!appContext.IsConfigured || appContext.DatabaseContext == null || !appContext.DatabaseContext.IsDatabaseConfigured) { return; } //Configure Umbraco user manager to be created per request app.CreatePerOwinContext <UmbracoMembersUserManager <T> >( (o, c) => UmbracoMembersUserManager <T> .Create( o, customUserStore, membershipProvider)); //Configure Umbraco member event handler to be created per request - this will ensure that the // external logins are kept in sync if members are deleted from Umbraco app.CreatePerOwinContext <MembersEventHandler <T> >((options, context) => new MembersEventHandler <T>(context)); }
/// <summary> /// Used to create a user manager with custom store /// </summary> /// <param name="options"></param> /// <param name="customUserStore"></param> /// <param name="membershipProvider"></param> /// <returns></returns> public static UmbracoMembersUserManager <TUser> Create( IdentityFactoryOptions <UmbracoMembersUserManager <TUser> > options, UmbracoMembersUserStore <TUser> customUserStore, IdentityEnabledMembersMembershipProvider membershipProvider = null) { //we'll grab some settings from the membership provider var provider = membershipProvider ?? Membership.Providers["UmbracoMembershipProvider"] as IdentityEnabledMembersMembershipProvider; if (provider == null) { throw new InvalidOperationException("In order to use " + typeof(UmbracoMembersUserManager <>) + " the Umbraco members membership provider must be of type " + typeof(IdentityEnabledMembersMembershipProvider)); } var manager = new UmbracoMembersUserManager <TUser>(customUserStore); // Configure validation logic for usernames manager.UserValidator = new UserValidator <TUser, int>(manager) { AllowOnlyAlphanumericUserNames = false, RequireUniqueEmail = true }; // Configure validation logic for passwords manager.PasswordValidator = new PasswordValidator { RequiredLength = provider.MinRequiredPasswordLength, RequireNonLetterOrDigit = provider.MinRequiredNonAlphanumericCharacters > 0, RequireDigit = false, RequireLowercase = false, RequireUppercase = false }; //use a custom hasher based on our membership provider manager.PasswordHasher = new MembershipPasswordHasher(provider); //NOTE: Not implementing these currently //// 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<ApplicationUser> //{ // MessageFormat = "Your security code is: {0}" //}); //manager.RegisterTwoFactorProvider("EmailCode", 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 <TUser, int>(dataProtectionProvider.Create("ASP.NET Identity")); } return(manager); }
/// <summary> /// Method to create a user manager which can be used to specify a custom IExternalLoginStore /// </summary> /// <param name="options"></param> /// <param name="memberService"></param> /// <param name="memberTypeService"></param> /// <param name="memberGroupService"></param> /// <param name="externalLoginStore"></param> /// <param name="membershipProvider"></param> /// <returns></returns> public static UmbracoMembersUserManager <TUser> Create( IdentityFactoryOptions <UmbracoMembersUserManager <TUser> > options, IMemberService memberService, IMemberTypeService memberTypeService, IMemberGroupService memberGroupService, IExternalLoginStore externalLoginStore = null, IdentityEnabledMembersMembershipProvider membershipProvider = null) { //we'll grab some settings from the membership provider var provider = membershipProvider ?? Membership.Providers["UmbracoMembershipProvider"] as IdentityEnabledMembersMembershipProvider; if (provider == null) { throw new InvalidOperationException("In order to use " + typeof(UmbracoMembersUserManager <>) + " the Umbraco members membership provider must be of type " + typeof(IdentityEnabledMembersMembershipProvider)); } if (externalLoginStore == null) { //we need to rely on singletons here due to backwards compat //use the default externalLoginStore = new ExternalLoginStore( ApplicationContext.Current.ProfilingLogger.Logger, ApplicationContext.Current.DatabaseContext); } return(Create(options, new UmbracoMembersUserStore <TUser>(ApplicationContext.Current.ProfilingLogger.Logger, memberService, memberTypeService, memberGroupService, provider, externalLoginStore), membershipProvider)); }
public UmbracoMembersUserStore( IMemberService memberService, IMemberTypeService memberTypeService, IdentityEnabledMembersMembershipProvider membershipProvider, IExternalLoginStore externalLoginStore) { if (memberService == null) { throw new ArgumentNullException("memberService"); } if (membershipProvider == null) { throw new ArgumentNullException("membershipProvider"); } if (externalLoginStore == null) { throw new ArgumentNullException("externalLoginStore"); } _memberService = memberService; _memberTypeService = memberTypeService; _membershipProvider = membershipProvider; _externalLoginStore = externalLoginStore; if (_membershipProvider.PasswordFormat != MembershipPasswordFormat.Hashed) { throw new InvalidOperationException("Cannot use ASP.Net Identity with UmbracoMembersUserStore when the password format is not Hashed"); } }
public UmbracoMembersUserStore( IMemberService memberService, IMemberTypeService memberTypeService, IMemberGroupService memberGroupService, IdentityEnabledMembersMembershipProvider membershipProvider, IExternalLoginStore externalLoginStore) : this(ApplicationContext.Current.ProfilingLogger.Logger, memberService, memberTypeService, memberGroupService, membershipProvider, externalLoginStore) { }
public static void ConfigureUserManagerForUmbracoMembers <T>(this IAppBuilder app, UmbracoMembersUserStore <T> customUserStore, IdentityEnabledMembersMembershipProvider membershipProvider = null) where T : UmbracoIdentityMember, new() { //Configure Umbraco user manager to be created per request app.CreatePerOwinContext <UmbracoMembersUserManager <T> >( (o, c) => UmbracoMembersUserManager <T> .Create( o, customUserStore, membershipProvider)); //Configure Umbraco member event handler to be created per request - this will ensure that the // external logins are kept in sync if members are deleted from Umbraco app.CreatePerOwinContext <MembersEventHandler <T> >((options, context) => new MembersEventHandler <T>(context)); }
public static void Configure <TUserManager>(TUserManager manager, IdentityEnabledMembersMembershipProvider provider, IdentityFactoryOptions <TUserManager> options) where TUserManager : UmbracoMembersUserManager <TUser> { // Configure validation logic for usernames manager.UserValidator = new UserValidator <TUser, int>(manager) { AllowOnlyAlphanumericUserNames = provider.AllowOnlyAlphanumericUserNames, RequireUniqueEmail = provider.RequiresUniqueEmail }; // Configure validation logic for passwords manager.PasswordValidator = new PasswordValidator { RequiredLength = provider.MinRequiredPasswordLength, RequireNonLetterOrDigit = provider.MinRequiredNonAlphanumericCharacters > 0, RequireDigit = provider.PasswordRequiresDigit, RequireLowercase = provider.PasswordRequiresLowercase, RequireUppercase = provider.PasswordRequiresUppercase }; //use a custom hasher based on our membership provider manager.PasswordHasher = new MembershipPasswordHasher(provider); //NOTE: Not implementing these currently //// 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<ApplicationUser> //{ // MessageFormat = "Your security code is: {0}" //}); //manager.RegisterTwoFactorProvider("EmailCode", 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 <TUser, int>(dataProtectionProvider.Create("ASP.NET Identity")); } }
/// <summary> /// Used to create a user manager with custom store /// </summary> /// <param name="options"></param> /// <param name="customUserStore"></param> /// <param name="membershipProvider"></param> /// <returns></returns> public static UmbracoMembersUserManager <TUser> Create( IdentityFactoryOptions <UmbracoMembersUserManager <TUser> > options, UmbracoMembersUserStore <TUser> customUserStore, IdentityEnabledMembersMembershipProvider membershipProvider = null) { //we'll grab some settings from the membership provider var provider = membershipProvider ?? Membership.Providers["UmbracoMembershipProvider"] as IdentityEnabledMembersMembershipProvider; if (provider == null) { throw new InvalidOperationException("In order to use " + typeof(UmbracoMembersUserManager <>) + " the Umbraco members membership provider must be of type " + typeof(IdentityEnabledMembersMembershipProvider)); } var manager = new UmbracoMembersUserManager <TUser>(customUserStore); Configure(manager, provider, options); return(manager); }
public UmbracoMembersUserStore( ILogger logger, IMemberService memberService, IMemberTypeService memberTypeService, IMemberGroupService memberGroupService, IdentityEnabledMembersMembershipProvider membershipProvider, IExternalLoginStore externalLoginStore) { _logger = logger ?? throw new ArgumentNullException(nameof(logger)); _memberService = memberService ?? throw new ArgumentNullException("memberService"); _memberTypeService = memberTypeService; _memberGroupService = memberGroupService ?? throw new ArgumentNullException(nameof(memberGroupService)); _membershipProvider = membershipProvider ?? throw new ArgumentNullException("membershipProvider"); _externalLoginStore = externalLoginStore ?? throw new ArgumentNullException("externalLoginStore"); if (_membershipProvider.PasswordFormat != MembershipPasswordFormat.Hashed) { throw new InvalidOperationException("Cannot use ASP.Net Identity with UmbracoMembersUserStore when the password format is not Hashed"); } }
/// <summary> /// Default method to create a user manager /// </summary> /// <param name="options"></param> /// <param name="logger"></param> /// <param name="databaseContext"></param> /// <param name="memberService"></param> /// <param name="memberTypeService"></param> /// <param name="memberGroupService"></param> /// <param name="membershipProvider"></param> /// <returns></returns> public static UmbracoMembersUserManager <TUser> Create( IdentityFactoryOptions <UmbracoMembersUserManager <TUser> > options, ILogger logger, DatabaseContext databaseContext, IMemberService memberService, IMemberTypeService memberTypeService, IMemberGroupService memberGroupService, IdentityEnabledMembersMembershipProvider membershipProvider = null) { //we'll grab some settings from the membership provider var provider = membershipProvider ?? Membership.Providers["UmbracoMembershipProvider"] as IdentityEnabledMembersMembershipProvider; if (provider == null) { throw new InvalidOperationException("In order to use " + typeof(UmbracoMembersUserManager <>) + " the Umbraco members membership provider must be of type " + typeof(IdentityEnabledMembersMembershipProvider)); } var externalLoginStore = new ExternalLoginStore(logger, databaseContext); return(Create(options, new UmbracoMembersUserStore <TUser>(logger, memberService, memberTypeService, memberGroupService, provider, externalLoginStore), membershipProvider)); }
public MembershipPasswordHasher(IdentityEnabledMembersMembershipProvider provider) { _provider = provider; }