From d411102dbefa009460136fc20e2f4acb434ac91d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Chalet?= Date: Wed, 7 Oct 2015 13:53:33 +0200 Subject: [PATCH] Use AspNet.Hosting.Extensions and AspNet.Hosting.Katana.Extensions --- src/OpenIddict/OpenIddictExtensions.cs | 122 +------------------------ src/OpenIddict/project.json | 4 +- 2 files changed, 5 insertions(+), 121 deletions(-) diff --git a/src/OpenIddict/OpenIddictExtensions.cs b/src/OpenIddict/OpenIddictExtensions.cs index ec7c763a..69ceb723 100644 --- a/src/OpenIddict/OpenIddictExtensions.cs +++ b/src/OpenIddict/OpenIddictExtensions.cs @@ -5,33 +5,20 @@ */ using System; -using System.Collections.Generic; using System.Diagnostics; -using System.Diagnostics.Tracing; using System.Reflection; -using System.Threading; -using System.Threading.Tasks; using AspNet.Security.OpenIdConnect.Server; -using Microsoft.AspNet.Builder.Internal; -using Microsoft.AspNet.DataProtection; using Microsoft.AspNet.FileProviders; -using Microsoft.AspNet.Hosting; using Microsoft.AspNet.Http; using Microsoft.AspNet.Identity; using Microsoft.AspNet.Identity.EntityFramework; using Microsoft.AspNet.StaticFiles; -using Microsoft.Dnx.Runtime; -using Microsoft.Dnx.Runtime.Infrastructure; using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.Internal; -using Microsoft.Framework.Logging; using OpenIddict; #if DNX451 -using Microsoft.Owin.Builder; -using Microsoft.Owin.BuilderProperties; using NWebsec.Owin; -using Owin; #endif namespace Microsoft.AspNet.Builder { @@ -104,8 +91,8 @@ namespace Microsoft.AspNet.Builder { return next(context); }); - #if DNX451 - builder.UseOwinAppBuilder(owin => { +#if DNX451 + builder.UseKatana(owin => { // Insert a new middleware responsible of setting the Content-Security-Policy header. // See https://nwebsec.codeplex.com/wikipage?title=Configuring%20Content%20Security%20Policy&referringTitle=NWebsec owin.UseCsp(options => options.DefaultSources(directive => directive.Self()) @@ -125,7 +112,7 @@ namespace Microsoft.AspNet.Builder { // See https://nwebsec.codeplex.com/wikipage?title=Configuring%20security%20headers&referringTitle=NWebsec owin.UseXXssProtection(options => options.EnabledWithBlockMode()); }); - #endif +#endif builder.UseStaticFiles(new StaticFileOptions { FileProvider = new EmbeddedFileProvider( @@ -241,108 +228,5 @@ namespace Microsoft.AspNet.Builder { }); }); } - - // Note: remove when https://github.com/aspnet-contrib/AspNet.Hosting.Extensions/pull/1 is merged. - internal static IApplicationBuilder Isolate( - [NotNull] this IApplicationBuilder app, - [NotNull] Action configuration, - [NotNull] Action serviceConfiguration) { - var services = new ServiceCollection(); - - // Retrieve the runtime services from the host provider. - var manifest = CallContextServiceLocator.Locator.ServiceProvider.GetService(); - if (manifest != null) { - foreach (var service in manifest.Services) { - services.AddTransient(service, sp => CallContextServiceLocator.Locator.ServiceProvider.GetService(service)); - } - } - - services.AddLogging(); - - // Copy the services added by the hosting layer. - services.AddInstance(app.ApplicationServices.GetRequiredService()); - services.AddInstance(app.ApplicationServices.GetRequiredService()); - services.AddInstance(app.ApplicationServices.GetRequiredService()); - services.AddInstance(app.ApplicationServices.GetRequiredService()); - services.AddInstance(app.ApplicationServices.GetRequiredService()); - services.AddInstance(app.ApplicationServices.GetRequiredService()); - services.AddInstance(app.ApplicationServices.GetRequiredService()); - - serviceConfiguration(services); - var provider = services.BuildServiceProvider(); - - var builder = new ApplicationBuilder(null); - builder.ApplicationServices = provider; - - builder.Use(next => async context => { - var priorApplicationServices = context.ApplicationServices; - var scopeFactory = provider.GetRequiredService(); - - // Store the original request services in the current ASP.NET context. - context.Items[typeof(IServiceProvider)] = context.RequestServices; - - try { - using (var scope = scopeFactory.CreateScope()) { - context.ApplicationServices = provider; - context.RequestServices = scope.ServiceProvider; - - await next(context); - } - } - finally { - context.RequestServices = null; - context.ApplicationServices = priorApplicationServices; - } - }); - - configuration(builder); - - return app.Use(next => { - // Run the rest of the pipeline in the original context, - // with the services defined by the parent application builder. - builder.Run(async context => { - var priorApplicationServices = context.ApplicationServices; - var scopeFactory = app.ApplicationServices.GetRequiredService(); - - try { - using (var scope = scopeFactory.CreateScope()) { - context.ApplicationServices = app.ApplicationServices; - context.RequestServices = scope.ServiceProvider; - - await next(context); - } - } - finally { - context.RequestServices = null; - context.ApplicationServices = priorApplicationServices; - } - }); - - var branch = builder.Build(); - - return context => branch(context); - }); - } - -#if DNX451 - // Note: remove when this extension is moved to https://github.com/aspnet-contrib/AspNet.Hosting.Extensions - internal static IApplicationBuilder UseOwinAppBuilder( - [NotNull] this IApplicationBuilder app, - [NotNull] Action configuration) { - return app.UseOwin(setup => setup(next => { - var builder = new AppBuilder(); - var lifetime = app.ApplicationServices.GetService(); - - var properties = new AppProperties(builder.Properties); - properties.AppName = app.ApplicationServices.GetApplicationUniqueIdentifier(); - properties.OnAppDisposing = lifetime?.ApplicationStopping ?? CancellationToken.None; - properties.DefaultApp = next; - - configuration(builder); - - return builder.Build, Task>>(); - })); - } -#endif } } \ No newline at end of file diff --git a/src/OpenIddict/project.json b/src/OpenIddict/project.json index 2d945ec2..baf8e185 100644 --- a/src/OpenIddict/project.json +++ b/src/OpenIddict/project.json @@ -17,6 +17,7 @@ "version": "1.0.0-*" }, + "AspNet.Hosting.Extensions": "1.0.0-*", "AspNet.Security.OpenIdConnect.Server": "1.0.0-*", "OpenIddict.Assets": "1.0.0-*", @@ -26,8 +27,7 @@ "frameworks": { "dnx451": { "dependencies": { - "Microsoft.AspNet.Owin": "1.0.0-*", - "Microsoft.Owin": "3.0.0", + "AspNet.Hosting.Katana.Extensions": "1.0.0-*", "NWebsec.Owin": "1.0.0" } },