public static void AddMembershipReboot(this IServiceCollection services, EnvConfig config) { // any middleware or component that uses DI to inject an instance of UserAccountService<HierarchicalUserAccount> // should instead depend on either AdminUserAccountServiceContainer, or DefaultUserAccountServiceContainer services.AddScoped(provider => { MembershipRebootSetup setup = MembershipRebootConfigFactory.GetAdminConfig(provider.GetService <IApplicationEnvironment>(), provider.GetRequiredService <ILoggerFactory>(), config); var repository = provider.GetRequiredService <IUserAccountRepository <HierarchicalUserAccount> >(); return(new AdminUserAccountServiceContainer { Service = new UserAccountService <HierarchicalUserAccount>(setup, repository) }); }); services.AddScoped(provider => { MembershipRebootSetup setup = MembershipRebootConfigFactory.GetDefaultConfig(provider.GetService <IApplicationEnvironment>(), provider.GetRequiredService <ILoggerFactory>(), config); var repository = provider.GetRequiredService <IUserAccountRepository <HierarchicalUserAccount> >(); return(new DefaultUserAccountServiceContainer { Service = new UserAccountService <HierarchicalUserAccount>(setup, repository) }); }); services.AddScoped(typeof(IUserAccountRepository <HierarchicalUserAccount>), typeof(MongoUserAccountRepository <HierarchicalUserAccount>)); services.AddScoped <IBulkUserRepository <HierarchicalUserAccount>, MongoUserAccountRepository <HierarchicalUserAccount> >(); services.AddAuthentication(sharedOptions => sharedOptions.SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme); services.AddScoped(provider => new MongoDatabase(config.DB.MembershipReboot)); }
public static void ConfigureCustomUserService(this IdentityServerServiceFactory factory, string connString, IApplicationEnvironment appEnv, ILoggerFactory loggerFactory, EnvConfig config) { factory.Register(new Registration <UserAccount, HierarchicalUserAccount>()); factory.Register(new Registration <MembershipRebootConfiguration <HierarchicalUserAccount> >(x => MembershipRebootConfigFactory.GetDefaultConfig(appEnv, loggerFactory, config))); factory.Register(new Registration <IUserAccountRepository <HierarchicalUserAccount>, MongoUserAccountRepository <HierarchicalUserAccount> >()); factory.Register(new Registration <UserAccountService <HierarchicalUserAccount> >()); factory.Register(new Registration <MongoDatabase>(resolver => new MongoDatabase(connString))); }
public static void UseIdentityServer(this IApplicationBuilder app, IApplicationEnvironment env, ILoggerFactory loggerFactory, EnvConfig config, StoreSettings idSvrStoreSettings) { var usrSrv = new Registration <IUserService, MembershipRebootUserService>(); var idSvcFactory = new ServiceFactory(usrSrv, idSvrStoreSettings) { ViewService = new Registration <IViewService>(typeof(CustomViewService)) }; idSvcFactory.ConfigureCustomUserService(config.DB.MembershipReboot, env, loggerFactory, config); idSvcFactory.Register(new Registration <IApplicationEnvironment>(env)); idSvcFactory.Register( new Registration <DefaultUserAccountServiceContainer>(resolver => new DefaultUserAccountServiceContainer { Service = new UserAccountService <HierarchicalUserAccount>( MembershipRebootConfigFactory.GetDefaultConfig(env, loggerFactory, config), resolver.Resolve <IUserAccountRepository <HierarchicalUserAccount> >()) } ) ); X509Certificate2 secondarySigningCertificate = null; if (!string.IsNullOrWhiteSpace(config.Cert.JwksSecondaryCertStoreName) && !string.IsNullOrWhiteSpace(config.Cert.JwksSecondaryCertThumbprint)) { secondarySigningCertificate = Crypto.Certificate.Get(config.DataProtection.CertStoreName, config.DataProtection.CertThumbprint); } var options = new IdentityServerOptions { SiteName = config.AppName, PublicOrigin = config.Uri.IssuerUri, SigningCertificate = Crypto.Certificate.Get(config.Cert.JwksCertStoreName, config.Cert.JwksCertThumbprint), SecondarySigningCertificate = secondarySigningCertificate, IssuerUri = config.Uri.IssuerUri, RequireSsl = true, LoggingOptions = new LoggingOptions() { EnableHttpLogging = true, EnableKatanaLogging = config.IsDebug, EnableWebApiDiagnostics = config.IsDebug, WebApiDiagnosticsIsVerbose = config.IsDebug }, Endpoints = new EndpointOptions() { EnableCspReportEndpoint = true }, Factory = idSvcFactory, AuthenticationOptions = new IdentityServer3.Core.Configuration.AuthenticationOptions() { EnableLocalLogin = true, EnableLoginHint = true, RememberLastUsername = false, CookieOptions = new CookieOptions() { ExpireTimeSpan = new TimeSpan(10, 0, 0), IsPersistent = false, SlidingExpiration = false, AllowRememberMe = true, RememberMeDuration = new TimeSpan(30, 0, 0, 0) }, EnableSignOutPrompt = true, EnablePostSignOutAutoRedirect = true, SignInMessageThreshold = 5 }, CspOptions = new CspOptions() { Enabled = true, ScriptSrc = config.Csp.ScriptSrc, StyleSrc = config.Csp.StyleSrc, FontSrc = config.Csp.FontSrc }, EnableWelcomePage = false }; app.UseOwin(addToPipeline => { addToPipeline(next => { var builder = new Microsoft.Owin.Builder.AppBuilder(); var provider = app.ApplicationServices.GetService <Microsoft.AspNet.DataProtection.IDataProtectionProvider>(); builder.Properties["security.DataProtectionProvider"] = new DataProtectionProviderDelegate(purposes => { var dataProtection = provider.CreateProtector(String.Join(",", purposes)); return(new DataProtectionTuple(dataProtection.Protect, dataProtection.Unprotect)); }); builder.UseIdentityServer(options); var appFunc = builder.Build(typeof(Func <IDictionary <string, object>, Task>)) as Func <IDictionary <string, object>, Task>; return(appFunc); }); }); }