-
Notifications
You must be signed in to change notification settings - Fork 73
First stab at removing Cookie and JWT constraints from HasServer (Auth ...)
#120
base: master
Are you sure you want to change the base?
Conversation
@@ -1,5 +1,5 @@ | |||
name: servant-auth-server | |||
version: 0.4.0.0 | |||
version: 0.4.0.1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please leave this change out? we're now trying to be consistent over all the servant packages about not updating versions or changelogs in PRs, this is all taken care of at release time.
Could you expand on this? Because indeed, the auth check -- which happens when we get the request -- does not have any say in the response that will be sent further down the road. |
Apologies for taking a while to respond to this. Let me try and explain. My intention was to allow building auth schemes that don't require custom route _ context subserver =
route (Proxy :: Proxy (AddSetCookiesApi n api))
context
(fmap go subserver `addAuthCheck` authCheck)
where
authCheck :: DelayedIO (AuthResult v, SetCookieList ('S ('S 'Z)))
authCheck = withRequest $ \req -> liftIO $ do
authResult <- runAuthCheck (runAuths (Proxy :: Proxy auths) context) req
cookies <- makeCookies authResult
return (authResult, cookies)
... So my next thought was that if we want to remove those constraints from |
@alpmestan does that make the problem clearer? |
I have not forgotten about this, just haven't found the time to come back to this just yet. I'll answer carefully ASAP. |
I like how simpler (but not simple) the HasServer instance becomes. Feels more natural. This does however mean that we don't have any place to store the cookie that we want to attach to the response, and this is what's bothering you. I think a proper solution necessarily has to involve changing servant-server itself, to give us a way to stick those cookies (and maybe other things? what else would we want to put there? without inventing crazy scenarios, this is just to guide the thought/design process) somewhere until we actually build the response, at which point we would reach for the cookie and add it to whatever response was about to be sent. (Note: this all sounds a lot like what middleware a does.) Perhaps (P.S: Sorry for the delay) |
I've been reading through the source code of |
Hmm, so far I was more thinking about a field that would take whatever And in that case, I don't believe the Please do ask for clarifications or some (simplified) code example if needed, it's a bit late here, but I can take a stab at writing a nicer answer tomorrow, with a bit of code to illustrate my idea, if this comment is not good enough. |
I think that's clear enough for me to make a start on. To be clear though you're suggesting a modification to the |
@alexjg Yes, my suggestion indeed involves patching servant-server. Please do feel free to open the PR as early as you want and to ask for guidance/help whenever needed, if ever. It'd also be handy to link to this PR here from the new one, to have the links appear in the github UI and all that. |
I'm currently teaching servant to a client team and was putting together a demonstrating of a custom auth method and ran across this, in this example: https://gist.github.com/chrisdone/6b893cf02e4655dacd3e1d09143d0bcf The However, the |
It's been a while since I wrote this, but the cookie and JWT constraints were definitely an ugly hack. My intuition is that we could do something like the following:
|
This is a first shot at exposing the stuff needed to build custom authentication schemes without being forced to use ToJWT typeclass or set any cookies. As far as I can tell there's no way to add response headers in the auth check at the moment so it wouldn't be possible to implement the current cookie stuff using the auth check machinery without modification. This is also why the tests around cookie headers fail.
What would be the preferred approach here? Do we need to change the signature of the auth check?