18

I am running into a problem with a solution where I used parts from the Visual Studio SPA template for having the Account Controller in WebApi with Oauth Authentication.

  app.UseOAuthBearerTokens(OAuthOptions);

Then I in the owin webapi registration is doing

config.SuppressDefaultHostAuthentication(); 

but this also supresses the default cookie authentication outside the webapi environment. Is this the intention. If so, how can I set up WebApi to supress cookie authentication but its still active accross the environment for other requests?

Poul K. Sørensen
  • 16,950
  • 21
  • 126
  • 283
  • 3
    [This blog post by Brock Allen](https://brockallen.com/2013/10/27/host-authentication-and-web-api-with-owin-and-active-vs-passive-authentication-middleware/) details nicely why that is happening. – Bart Verkoeijen Mar 07 '17 at 13:37

1 Answers1

34

It seems that it is a good practice, especially when you mix an OWIN-hosted app and a regular one on the same IIS dir, to setup WebApi with the app.Map.

    public void Configuration(IAppBuilder app)
    {
        var configuration = WebApiConfiguration.HttpConfiguration;
        app.Map("/api", inner =>
        {
            inner.UseWebApi(configuration);
        });
    }

I had all my controllers configured with a "api" prefix route, and I just moved that to the map function instead. Now webapi is running isolated and it works out with the rest of my application. Thanks @PinpointTownes for pointing me in this direction.

Poul K. Sørensen
  • 16,950
  • 21
  • 126
  • 283
  • 2
    Make sure to install nugget pkg Microsoft ASP.Net Web API 2.2 OWIN. It had everything installed but that... – Papa Burgundy Aug 04 '14 at 00:36
  • 6
    The package identifier is `Microsoft.AspNet.WebApi.Owin` – slypete Feb 07 '15 at 04:21
  • 7
    WebApiConfiguration is nowhere to be found. I'm using MVC 5 and have Microsoft.AspNet.WebApi.Owin 5.2.3 installed. – SomethingOn Nov 16 '15 at 20:04
  • 1
    Thats not in the scope for this answer - you can also do a app.Map in MVC5 which is the answer. app.Map("/api", inner => {inner.UseMvc()}); But do not that it also changes your actions if you use the MVC part. Create a new question for your problem if this is not enough for your issue. – Poul K. Sørensen Nov 18 '15 at 10:10