public static void UseIdentityServer(this IApplicationBuilder app, IdentityServerOptions options) { app.UseOwin(pipeline => { pipeline(next => { var builder = new Microsoft.Owin.Builder.AppBuilder(); var provider = app.ApplicationServices.GetService<DataProtection.IDataProtectionProvider>(); builder.Properties["security.DataProtectionProvider"] = new DataProtectionProviderDelegate(purposes => { var dataProtection = provider.CreateProtector(String.Join(",", purposes)); return new DataProtectionTuple(dataProtection.Protect, dataProtection.Unprotect); }); builder.Map("/admin", adminApp => { var factory = new IdentityManagerServiceFactory(); factory.ConfigureSimpleIdentityManagerService("AspId"); //factory.ConfigureCustomIdentityManagerServiceWithIntKeys("AspId_CustomPK"); adminApp.UseIdentityManager(new IdentityManagerOptions() { Factory = factory }); }); builder.UseIdentityServer(options); builder.UseAesDataProtectorProvider(); var appFunc = builder.Build(typeof(Func<IDictionary<string, object>, Task>)) as Func<IDictionary<string, object>, Task>; return appFunc; }); }); }
public static void UseIdentityServer(this IApplicationBuilder app, IdentityServerOptions options) { app.UseOwin(pipeline => { pipeline(next => { var builder = new Microsoft.Owin.Builder.AppBuilder(); var provider = app.ApplicationServices.GetService <DataProtection.IDataProtectionProvider>(); builder.Properties["security.DataProtectionProvider"] = new DataProtectionProviderDelegate(purposes => { var dataProtection = provider.CreateProtector(String.Join(",", purposes)); return(new DataProtectionTuple(dataProtection.Protect, dataProtection.Unprotect)); }); builder.Map("/admin", adminApp => { var factory = new IdentityManagerServiceFactory(); factory.ConfigureSimpleIdentityManagerService("AspId"); //factory.ConfigureCustomIdentityManagerServiceWithIntKeys("AspId_CustomPK"); adminApp.UseIdentityManager(new IdentityManagerOptions() { Factory = factory }); }); builder.UseIdentityServer(options); builder.UseAesDataProtectorProvider(); var appFunc = builder.Build(typeof(Func <IDictionary <string, object>, Task>)) as Func <IDictionary <string, object>, Task>; return(appFunc); }); }); }
public static void UseIdentityServerBearerTokenAuthentication(this IApplicationBuilder app, IdentityServerBearerTokenAuthenticationOptions options) { app.UseOwin(addToPipeline => { addToPipeline(next => { var builder = new Microsoft.Owin.Builder.AppBuilder(); var loggerFactory = app.ApplicationServices.GetService<Microsoft.Extensions.Logging.ILoggerFactory>(); var lifetime = app.ApplicationServices.GetService<IApplicationLifetime>(); var owinLoggerFactory = new OwinLoggerFactory(loggerFactory); var provider = app.ApplicationServices.GetService(typeof(Microsoft.AspNet.DataProtection.IDataProtectionProvider)) as Microsoft.AspNet.DataProtection.IDataProtectionProvider; var properties = new AppProperties(builder.Properties); properties.OnAppDisposing = lifetime.ApplicationStopping; properties.DefaultApp = next; builder.SetLoggerFactory(owinLoggerFactory); builder.Properties["security.DataProtectionProvider"] = new DataProtectionProviderDelegate(purposes => { var dataProtection = provider.CreateProtector(string.Join(",", purposes)); return new DataProtectionTuple(dataProtection.Protect, dataProtection.Unprotect); }); builder.UseIdentityServerBearerTokenAuthentication(options); return builder.Build(typeof(Func<IDictionary<string, object>, Task>)) as Func<IDictionary<string, object>, Task>; }); }); }
public static void UseIdentityServer(this IApplicationBuilder app, IdentityServerOptions options) { app.UseOwin(action => { action?.Invoke(next => { var builder = new Microsoft.Owin.Builder.AppBuilder(); var provider = app.ApplicationServices.GetService(typeof(DataProtection.IDataProtectionProvider)) as DataProtection.IDataProtectionProvider; if (provider == null) { throw new Exception("Provider can not be null at UseIdentityServer extension method"); } 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); }); }); }
public static void UseIdentityServerBearerTokenAuthentication(this IApplicationBuilder app, IdentityServerBearerTokenAuthenticationOptions options) { app.UseOwin(addToPipeline => { addToPipeline(next => { var builder = new Microsoft.Owin.Builder.AppBuilder(); var loggerFactory = app.ApplicationServices.GetService <Microsoft.Framework.Logging.ILoggerFactory>(); var lifetime = app.ApplicationServices.GetService <IApplicationLifetime>(); var owinLoggerFactory = new OwinLoggerFactory(loggerFactory); var provider = app.ApplicationServices.GetService(typeof(Microsoft.AspNet.DataProtection.IDataProtectionProvider)) as Microsoft.AspNet.DataProtection.IDataProtectionProvider; var properties = new AppProperties(builder.Properties); properties.OnAppDisposing = lifetime.ApplicationStopping; properties.DefaultApp = next; builder.SetLoggerFactory(owinLoggerFactory); builder.Properties["security.DataProtectionProvider"] = new DataProtectionProviderDelegate(purposes => { var dataProtection = provider.CreateProtector(string.Join(",", purposes)); return(new DataProtectionTuple(dataProtection.Protect, dataProtection.Unprotect)); }); builder.UseIdentityServerBearerTokenAuthentication(options); return(builder.Build(typeof(Func <IDictionary <string, object>, Task>)) as Func <IDictionary <string, object>, Task>); }); }); }
public void Configure(IApplicationBuilder app, IApplicationEnvironment env) { Log.Logger = new LoggerConfiguration().MinimumLevel.Debug().WriteTo.Trace().CreateLogger(); BasePath = env.ApplicationBasePath; var certFile = Path.Combine(BasePath, "idsrv3test.pfx"); var options = ConfigureIdentityServer(certFile); app.UseOwin(pipeline => { pipeline(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.UseAesDataProtectorProvider(); builder.Map("/admin", adminApp => { var factory = new IdentityManagerServiceFactory(); factory.ConfigureSimpleIdentityManagerService("AspId"); //factory.ConfigureCustomIdentityManagerServiceWithIntKeys("AspId_CustomPK"); adminApp.UseIdentityManager(new IdentityManagerOptions() { Factory = factory }); }); builder.UseIdentityServer(options); var appFunc = builder.Build(typeof(Func<IDictionary<string, object>, Task>)) as Func<IDictionary<string, object>, Task>; return appFunc; }); }); app.UseIdentityServer(options); }
public void Configure(IApplicationBuilder app, IApplicationEnvironment env) { Log.Logger = new LoggerConfiguration().MinimumLevel.Debug().WriteTo.Trace().CreateLogger(); BasePath = env.ApplicationBasePath; var certFile = Path.Combine(BasePath, "idsrv3test.pfx"); var options = ConfigureIdentityServer(certFile); app.UseOwin(pipeline => { pipeline(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.UseAesDataProtectorProvider(); builder.Map("/admin", adminApp => { var factory = new IdentityManagerServiceFactory(); factory.ConfigureSimpleIdentityManagerService("AspId"); //factory.ConfigureCustomIdentityManagerServiceWithIntKeys("AspId_CustomPK"); adminApp.UseIdentityManager(new IdentityManagerOptions() { Factory = factory }); }); builder.UseIdentityServer(options); var appFunc = builder.Build(typeof(Func <IDictionary <string, object>, Task>)) as Func <IDictionary <string, object>, Task>; return(appFunc); }); }); app.UseIdentityServer(options); }
public static void UseIdentityServer(this IApplicationBuilder app, IdentityServerOptions options) { 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; }); }); }
public static void UseIdentityServer(this IApplicationBuilder app, IdentityServerOptions options) { 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); }); }); }
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); }); }); }
public void Configure(IApplicationBuilder app) { LogProvider.SetCurrentLogProvider(new DiagnosticsTraceLogProvider()); var options = new IdentityServerOptions { Factory = InMemoryFactory.Create(users: new List<InMemoryUser> { _user }, scopes: _scopes, clients: new List<Client> { _client }), RequireSsl = false, LoggingOptions = new LoggingOptions { EnableHttpLogging = true, EnableWebApiDiagnostics = true, IncludeSensitiveDataInLogs = true, WebApiDiagnosticsIsVerbose = true } }; app.Map("/core", appl => { appl.UseOwin(pipeline => { pipeline(next => { var builder = new Microsoft.Owin.Builder.AppBuilder(); var provider = app.ApplicationServices.GetService<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; }); }); }); }