mzabani / Fos

FastCgi Server designed to run Owin applications side by side with a FastCgi enabled web server.
BSD 2-Clause "Simplified" License
62 stars 12 forks source link

FOS throws NotSupportedException when using Microsoft.Owin.Security middlewares #9

Open mikdav opened 6 years ago

mikdav commented 6 years ago

Wired up a test application with UseActiveDirectoryFederationServicesBearerAuthentication, and get the following exception:

System.NotSupportedException: The OWIN key 'server.OnSendingHeaders' is not available for this request. at Microsoft.Owin.OwinResponse.OnSendingHeaders(Action1 callback, Object state) at Microsoft.Owin.Security.Infrastructure.AuthenticationHandler.<BaseInitializeAsync>d__0.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Owin.Security.Infrastructure.AuthenticationMiddleware1.d0.MoveNext() --- End of inner exception stack trace --- ---> (Inner Exception #0) System.NotSupportedException: The OWIN key 'server.OnSendingHeaders' is not available for this request. at Microsoft.Owin.OwinResponse.OnSendingHeaders(Action`1 callback, Object state) at Microsoft.Owin.Security.Infrastructure.AuthenticationHandler.d0.MoveNext() --- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Owin.Security.Infrastructure.AuthenticationMiddleware`1.d__0.MoveNext()

The FosRequest class would need to be able to handle the common key server.OnSendingHeaders (defined here: http://owin.org/spec/spec/CommonKeys.html#_6._Common_keys) in order to use these middlewares.

mikdav commented 6 years ago

Committed possible change in d7e95757c2e9d2f9fa60505e02f95381cf414cf7

mikdav commented 6 years ago

Verified that I can now use MS Auth middlewares and all unit tests pass.

mzabani commented 6 years ago

This is really great! If you're willing to submit a Pull Request, I'll accept it right away!

mikdav commented 6 years ago

Have you had a chance to look at dbd5a6460cda1ecc2256388ba9aca408cc42660c that fixes #8? I know it is a bit heavier change because it takes a new dependency on Microsoft.Owin and ups the framework version. However, I needed webapi before I needed the auth, so I committed it first. Just need to know whether you want a pull request for both or if I need to branch. Thanks.

mzabani commented 6 years ago

I don't mind taking a dependency on Microsoft.Owin, but it upping the framework version really necessary?

mikdav commented 6 years ago

Unfortunately the last version of Microsoft.Owin that supported .Net 4 was 2.1.0 which is more than 4 years old and two major versions ago. Everything since then has required .Net 4.5. So, don't need to go all the way to 4.62, but probably should at least consider 4.5. I have not tested my changes with Microsoft.Owin 2.1.0.

mzabani commented 6 years ago

Sorry for taking so long to respond, I thought I already had replied to this. I don't believe requiring .NET 4.5 would be a problem at this point. What do you think?