go-openapi / runtime

openapi runtime interfaces
Apache License 2.0
245 stars 146 forks source link

Calling middleware handler when routing is not hit #201

Open tnoborio opened 3 years ago

tnoborio commented 3 years ago

I would like to output the Principal to the log if the authentication is successful. when the API routing exists, I could log it out by writing the following.

However, when the routing is not hit, the middleware handler is not called.

https://github.com/go-openapi/runtime/blob/master/middleware/router.go#L82-L88

Is there any way to deal with this?

fredbi commented 9 months ago

I am afraid this is not possible.

Given that the need for authentication is defined dynamically per route from the spec, we don't authenticate before we get a chance to match the route.

Dealing with a spec that determines which endpoints are subject to authentication is very different from doing it manually by injecting, say, some authentication middleware at the top of your routing tree or on a subtree.