Search code examples
owinasp.net-corekatana

Registering OAuth authorization service middleware


How can i register the OAuthAuthorizationServerMiddleware and OAuthBearerAuthenticationMiddleware in ASP.NET 5?

I tried the following:

app.UseMiddleware(typeof(OAuthAuthorizationServerMiddleware), OAuthServerOptions);
app.UseMiddleware(typeof(OAuthBearerAuthenticationMiddleware), new OAuthBearerAuthenticationOptions());

But this throws the following error:

System.Exception: TODO: unable to locate suitable constructor for Microsoft.Owin.Security.OAuth.OAuthBearerAuthenticationMiddleware. Ensure 'instanceType' is concrete and all parameters are accepted by a constructor.

I'm trying to port token based authentication implemented in this (click here) application into ASP.NET 5.

I've hit a wall here, not being able to register the OAuth server middleware and OAuth Bearer authentication.


Solution

  • You cannot use middlewares from Katana project with UseMiddleware method in an ASP.NET vNext project. You can try UseOwin method provided here: https://github.com/aspnet/HttpAbstractions/blob/335895d9b49042312eca12a089340adf3ca0a219/src/Microsoft.AspNet.Owin/OwinExtensions.cs but I'm not sure how it's going to work.

    The wisest decision here is to port your stuff to new world. You can find the OAuth Server middleware implementations here: https://github.com/aspnet/Security/tree/dev/src/Microsoft.AspNet.Security.OAuth