Use WebAPI 2 without OWIN Authentication Middleware

I would like to use ASP.NET WebAPI 2, but with my own authentication mechanism. I tried to remove all the code that comes with the SPA template in VS 2013, as well as the regular WebAPI template. If I remove all the auth related code from the project and don’t configure OWIN in Startup.Auth, I always get an error message that OWIN middleware authentication is not configured and I can’t get to any controller action.

What is the correct way to implement token authentication in WebAPI 2 with native code, bypassing what is in OWIN host.dll, including configuration requirements?

+6
source share
3 answers

You can use the empty Asp.Net template and add Web Api 2 as nuget packages or remove unused materials from other starter templates.

+2
source

Like John, but you can remove OWIN when creating the WebAPI. A cleaner approach.

To do this: Select "Change Authentication" enter image description here

then select "No Authenciation"

enter image description here

Now your project will not have OWIN material

Cheers Choco

+11
source

You can simply comment on the following lines of code:

Startup.cs:

//[assembly: OwinStartup(typeof(Yourpoject.Startup))] public void Configuration(IAppBuilder app) { //ConfigureAuth(app); } 

WebApiConfig.cs:

  //// Web API configuration and services //// Configure Web API to use only bearer token authentication. //config.SuppressDefaultHostAuthentication(); //config.Filters.Add(new HostAuthenticationFilter(OAuthDefaults.AuthenticationType)); 
+1
source

Source: https://habr.com/ru/post/978298/


All Articles