private void ConfigureTwoFactorAuthentication(object sender, OwinMiddlewareConfiguredEventArgs args) { var app = args.AppBuilder; var applicationContext = ApplicationContext.Current; app.SetUmbracoLoggerFactory(); app.UseTwoFactorSignInCookie(Umbraco.Core.Constants.Security.BackOfficeTwoFactorAuthenticationType, TimeSpan.FromMinutes(5)); // We need to set these values again after our custom changes. Otherwise preview doesn't work. app.UseUmbracoBackOfficeCookieAuthentication(applicationContext) .UseUmbracoBackOfficeExternalCookieAuthentication(applicationContext) .UseUmbracoPreviewAuthentication(applicationContext); app.ConfigureUserManagerForUmbracoBackOffice <TwoFactorBackOfficeUserManager, BackOfficeIdentityUser>( applicationContext, (options, context) => { var membershipProvider = MembershipProviderExtensions.GetUsersMembershipProvider().AsUmbracoMembershipProvider(); var userManager = TwoFactorBackOfficeUserManager.Create(options, applicationContext.Services.UserService, applicationContext.Services.EntityService, applicationContext.Services.ExternalLoginService, membershipProvider); return(userManager); }); }
private void ConfigureTwoFactorAuthentication(object sender, OwinMiddlewareConfiguredEventArgs args) { var app = args.AppBuilder; var applicationContext = Umbraco.Core.Composing.Current.Services; IGlobalSettings GlobalSettings = Umbraco.Core.Composing.Current.Configs.Global(); IUmbracoSettingsSection UmbracoSettings = Umbraco.Core.Composing.Current.Configs.Settings(); UmbracoMapper umbracoMapper = Umbraco.Core.Composing.Current.Mapper; //netser///////////////////////// /* var oAuthServerOptions = new OAuthAuthorizationServerOptions * * { * AllowInsecureHttp = true, * TokenEndpointPath = new PathString("/token"), * AccessTokenExpireTimeSpan = TimeSpan.FromDays(1) * }; * // Token Generation * app.UseOAuthAuthorizationServer(oAuthServerOptions); * app.UseOAuthBearerAuthentication(new OAuthBearerAuthenticationOptions());*/ ////////////////////end netser app.SetUmbracoLoggerFactory(); app.UseTwoFactorSignInCookie(Umbraco.Core.Constants.Security.BackOfficeTwoFactorAuthenticationType, TimeSpan.FromMinutes(5)); // app.UseOAuthAuthorizationServer(options); // app.UseOAuthBearerAuthentication(new OAuthBearerAuthenticationOptions()); // We need to set these values again after our custom changes. Otherwise preview doesn't work. // Gunni: Apparently we don't need this for preview to work and the following code breaks other Identity providers //app.UseUmbracoBackOfficeCookieAuthentication(umbracoContextAccessor, Umbraco.Web.Composing.Current.RuntimeState, applicationContext.UserService, GlobalSettings, securitySection) // .UseUmbracoBackOfficeExternalCookieAuthentication(umbracoContextAccessor, runtimeState, GlobalSettings) // .UseUmbracoPreviewAuthentication(umbracoContextAccessor, runtimeState, globalSettings, securitySection); app.ConfigureUserManagerForUmbracoBackOffice <TwoFactorBackOfficeUserManager, BackOfficeIdentityUser>( Umbraco.Web.Composing.Current.RuntimeState, GlobalSettings, (options, context) => { var membershipProvider = MembershipProviderExtensions.GetUsersMembershipProvider().AsUmbracoMembershipProvider(); var userManager = TwoFactorBackOfficeUserManager.Create(options, applicationContext.UserService, applicationContext.MemberTypeService, applicationContext.EntityService, applicationContext.ExternalLoginService, membershipProvider, GlobalSettings, umbracoMapper); return(userManager); }); }
private void ConfigureTwoFactorAuthentication(object sender, OwinMiddlewareConfiguredEventArgs args) { var app = args.AppBuilder; var applicationContext = ApplicationContext.Current; //netser///////////////////////// /* var oAuthServerOptions = new OAuthAuthorizationServerOptions * * { * AllowInsecureHttp = true, * TokenEndpointPath = new PathString("/token"), * AccessTokenExpireTimeSpan = TimeSpan.FromDays(1) * }; * // Token Generation * app.UseOAuthAuthorizationServer(oAuthServerOptions); * app.UseOAuthBearerAuthentication(new OAuthBearerAuthenticationOptions());*/ ////////////////////end netser app.SetUmbracoLoggerFactory(); app.UseTwoFactorSignInCookie(Umbraco.Core.Constants.Security.BackOfficeTwoFactorAuthenticationType, TimeSpan.FromMinutes(5)); // app.UseOAuthAuthorizationServer(options); // app.UseOAuthBearerAuthentication(new OAuthBearerAuthenticationOptions()); // We need to set these values again after our custom changes. Otherwise preview doesn't work. app.UseUmbracoBackOfficeCookieAuthentication(applicationContext) .UseUmbracoBackOfficeExternalCookieAuthentication(applicationContext) .UseUmbracoPreviewAuthentication(applicationContext); /**/ app.ConfigureUserManagerForUmbracoBackOffice <TwoFactorBackOfficeUserManager, BackOfficeIdentityUser>( applicationContext, (options, context) => { var membershipProvider = MembershipProviderExtensions.GetUsersMembershipProvider().AsUmbracoMembershipProvider(); var userManager = TwoFactorBackOfficeUserManager.Create(options, applicationContext.Services.UserService, applicationContext.Services.EntityService, applicationContext.Services.ExternalLoginService, membershipProvider); return(userManager); }); }
/// <summary> /// Creates a BackOfficeUserManager instance with all default options and the default BackOfficeUserManager /// </summary> /// <param name="options"></param> /// <param name="userService"></param> /// <param name="entityService"></param> /// <param name="externalLoginService"></param> /// <param name="membershipProvider"></param> /// <returns></returns> public static TwoFactorBackOfficeUserManager Create( IdentityFactoryOptions <TwoFactorBackOfficeUserManager> options, IUserService userService, IEntityService entityService, IExternalLoginService externalLoginService, MembershipProviderBase membershipProvider) { if (options == null) { throw new ArgumentNullException("options"); } if (userService == null) { throw new ArgumentNullException("userService"); } if (entityService == null) { throw new ArgumentNullException("entityService"); } if (externalLoginService == null) { throw new ArgumentNullException("externalLoginService"); } var manager = new TwoFactorBackOfficeUserManager(new TwoFactorBackOfficeUserStore(userService, externalLoginService, entityService, membershipProvider)); manager.InitUserManager(manager, membershipProvider, options.DataProtectionProvider, UmbracoConfig.For.UmbracoSettings().Content); //Here you can specify the 2FA providers that you want to implement var dataProtectionProvider = options.DataProtectionProvider; manager.RegisterTwoFactorProvider(Constants.YubiKeyProviderName, new TwoFactorValidationProvider(dataProtectionProvider.Create(Constants.YubiKeyProviderName))); manager.RegisterTwoFactorProvider(Constants.GoogleAuthenticatorProviderName, new TwoFactorValidationProvider(dataProtectionProvider.Create(Constants.GoogleAuthenticatorProviderName))); return(manager); }