1
votes

I am creating an application that will use MVC 5 to serve the initial layout, views, scripts, etc. and then I am using WebApi2 to serve data to the UI.

I want to use the OWIN OAuth bits for Authentication on the WebApi.

The WebApi lives in a DLL and the MVC 5 app is a Web Application.

I have referenced this article for the OAuth WebApi bits.

How do I setup the WebApi to run in the MVC 5 application and use the OWIN Startup class?

Or is this not possible?

1
is your question about how to make WebAPI and a traditional MVC 5 app share code and routes? - Claies
No, more on how to use OAuth for the WebApi using OWIN while hosting the two together. - Sam
I guess I'm still confused. what does using the OAuth provider with OWIN have to do with them being hosted together? - Claies
That is what I am trying to make work... I think I am getting close and will update the question if I do. - Sam

1 Answers

2
votes

I recommend you to check the VS 2013 Web API template (Web API and MVC core dependency) but with individual accounts checked as this image, I believe you are missing adding those both lines in class WebApiConfig.cs:

config.SuppressDefaultHostAuthentication();
config.Filters.Add(new HostAuthenticationFilter(OAuthDefaults.AuthenticationType));

You need to suppress the default authentication (Forms Auth) then add the bearer authentication only for Web API.