adds overload to specify custom backoffice user store for custom implementations (i.e. 2 factor auth, etc...)
This commit is contained in:
@@ -61,20 +61,58 @@ namespace Umbraco.Core.Security
|
||||
}
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Creates a BackOfficeUserManager instance with all default options and the default BackOfficeUserManager
|
||||
/// </summary>
|
||||
/// <param name="options"></param>
|
||||
/// <param name="userService"></param>
|
||||
/// <param name="externalLoginService"></param>
|
||||
/// <param name="membershipProvider"></param>
|
||||
/// <returns></returns>
|
||||
public static BackOfficeUserManager Create(
|
||||
IdentityFactoryOptions<BackOfficeUserManager> options,
|
||||
IOwinContext context,
|
||||
IUserService userService,
|
||||
IExternalLoginService externalLoginService,
|
||||
MembershipProviderBase membershipProvider)
|
||||
{
|
||||
if (options == null) throw new ArgumentNullException("options");
|
||||
if (context == null) throw new ArgumentNullException("context");
|
||||
if (userService == null) throw new ArgumentNullException("userService");
|
||||
if (externalLoginService == null) throw new ArgumentNullException("externalLoginService");
|
||||
|
||||
var manager = new BackOfficeUserManager(new BackOfficeUserStore(userService, externalLoginService, membershipProvider));
|
||||
|
||||
return InitUserManager(manager, membershipProvider, options);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a BackOfficeUserManager instance with all default options and a custom BackOfficeUserManager instance
|
||||
/// </summary>
|
||||
/// <param name="options"></param>
|
||||
/// <param name="customUserStore"></param>
|
||||
/// <param name="membershipProvider"></param>
|
||||
/// <returns></returns>
|
||||
public static BackOfficeUserManager Create(
|
||||
IdentityFactoryOptions<BackOfficeUserManager> options,
|
||||
BackOfficeUserStore customUserStore,
|
||||
MembershipProviderBase membershipProvider)
|
||||
{
|
||||
if (options == null) throw new ArgumentNullException("options");
|
||||
if (customUserStore == null) throw new ArgumentNullException("customUserStore");
|
||||
|
||||
var manager = new BackOfficeUserManager(customUserStore);
|
||||
|
||||
return InitUserManager(manager, membershipProvider, options);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes the user manager with the correct options
|
||||
/// </summary>
|
||||
/// <param name="manager"></param>
|
||||
/// <param name="membershipProvider"></param>
|
||||
/// <param name="options"></param>
|
||||
/// <returns></returns>
|
||||
private static BackOfficeUserManager InitUserManager(BackOfficeUserManager manager, MembershipProviderBase membershipProvider, IdentityFactoryOptions<BackOfficeUserManager> options)
|
||||
{
|
||||
// Configure validation logic for usernames
|
||||
manager.UserValidator = new UserValidator<BackOfficeIdentityUser, int>(manager)
|
||||
{
|
||||
@@ -102,7 +140,7 @@ namespace Umbraco.Core.Security
|
||||
}
|
||||
|
||||
//custom identity factory for creating the identity object for which we auth against in the back office
|
||||
manager.ClaimsIdentityFactory = new BackOfficeClaimsIdentityFactory();
|
||||
manager.ClaimsIdentityFactory = new BackOfficeClaimsIdentityFactory();
|
||||
|
||||
//NOTE: Not implementing these, if people need custom 2 factor auth, they'll need to implement their own UserStore to suport it
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="umb-pane external-logins">
|
||||
<div class="umb-pane external-logins" ng-if="externalLoginProviders.length > 0">
|
||||
|
||||
<h5>External login providers</h5>
|
||||
|
||||
|
||||
@@ -17,8 +17,9 @@ namespace Umbraco.Web.Security.Identity
|
||||
public static class AppBuilderExtensions
|
||||
{
|
||||
#region Backoffice
|
||||
|
||||
/// <summary>
|
||||
/// Configure Identity User Manager for Umbraco
|
||||
/// Configure Default Identity User Manager for Umbraco
|
||||
/// </summary>
|
||||
/// <param name="app"></param>
|
||||
/// <param name="appContext"></param>
|
||||
@@ -36,12 +37,36 @@ namespace Umbraco.Web.Security.Identity
|
||||
app.CreatePerOwinContext<BackOfficeUserManager>(
|
||||
(options, owinContext) => BackOfficeUserManager.Create(
|
||||
options,
|
||||
owinContext,
|
||||
appContext.Services.UserService,
|
||||
appContext.Services.ExternalLoginService,
|
||||
userMembershipProvider));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configure a custom UserStore with the Identity User Manager for Umbraco
|
||||
/// </summary>
|
||||
/// <param name="app"></param>
|
||||
/// <param name="appContext"></param>
|
||||
/// <param name="userMembershipProvider"></param>
|
||||
/// <param name="customUserStore"></param>
|
||||
public static void ConfigureUserManagerForUmbracoBackOffice(this IAppBuilder app,
|
||||
ApplicationContext appContext,
|
||||
MembershipProviderBase userMembershipProvider,
|
||||
BackOfficeUserStore customUserStore)
|
||||
{
|
||||
//Don't proceed if the app is not ready
|
||||
if (appContext.IsConfigured == false
|
||||
|| appContext.DatabaseContext == null
|
||||
|| appContext.DatabaseContext.IsDatabaseConfigured == false) return;
|
||||
|
||||
//Configure Umbraco user manager to be created per request
|
||||
app.CreatePerOwinContext<BackOfficeUserManager>(
|
||||
(options, owinContext) => BackOfficeUserManager.Create(
|
||||
options,
|
||||
customUserStore,
|
||||
userMembershipProvider));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ensures that the UmbracoBackOfficeAuthenticationMiddleware is assigned to the pipeline
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user