Search code examples
.netauthenticationowinwebapikatana

.NET Web API apps with bearer token stopped working due to OWIN authentication manager


I'm gonna try and and explain as much as possible of what's going on hoping someone would be able to help.

I have 2 .NET applications that were working just fine for quite some time now. One of them is a mailing service and the other one is an application that uploads files to the Blob Storage on Azure.

These applications use bearer token from a local token provider. In the startup, JwtBearerAuthentication is used to set the token provider information. The authentication mode is Active. Both apps stopped out of nowhere because of something that has to do with OWIN authentication manager based on the exception. One of them is returning the error code 500 internal server error, and the exception message is "No OWIN authentication manager is associated with the request". Obviously, if I comment out the following two lines in the WebApiConfig.cs:

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

It'll work fine, but that's because it's not checking for the token anymore. The NuGet packages are fine based on what I've seen.

I can also see the bearer token being created and passed to the apps.

I've been trying to debug and see what could be causing the issue for the past 4 days, but no luck. I've been trying to run line by line in IIS, but couldn't find anything.

I can't share code sadly, but I'm more than happy to clarify any missing pieces.

Any ideas, suggestions or attempt to help would be great and appreciated.

Thank you!


Solution

  • It turns out, and for whatever reason, web.config was missing the package Microsoft.Owin.Host.SystemWeb. That was causing Startup.cs to not run which was resulting the error message "No OWIN authentication manager is associated with the request".