The oft cited reference that the frameworks are compatible is an extension method build by Thinktecture for supporting their IdentityServer3 on ASP.NET 5.
That method is specific to IdentityServer and does not support the request being processed by any middleware registered later in the AspNet pipeline (it does not call the next component).
This adapts the method to address those shortcomings:
internal static class IApplicationBuilderExtensions
{
public static void UseOwin(
this IApplicationBuilder app,
Action<IAppBuilder> owinConfiguration )
{
app.UseOwin(
addToPipeline =>
{
addToPipeline(
next =>
{
var builder = new AppBuilder();
owinConfiguration( builder );
builder.Run( ctx => next( ctx.Environment ) );
Func<IDictionary<string, object>, Task> appFunc =
(Func<IDictionary<string, object>, Task>)
builder.Build( typeof( Func<IDictionary<string, object>, Task> ) );
return appFunc;
} );
} );
}
}
It can be used as follows:
app.UseOwin(
owin =>
{
// Arbitrary IAppBuilder registrations can be placed in this block
// For example, this extension can be provided by
// NWebsec.Owin or Thinktecture.IdentityServer3
owin.UseHsts();
} );
// ASP.NET 5 components, like MVC 6, will still process the request
// (assuming the request was not handled by earlier middleware)
app.UseMvc();