-
Notifications
You must be signed in to change notification settings - Fork 59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Document servant-auth usage #38
Comments
To do the more aggressive parameterization, one can use this: type API loginHeaders =
"login"
:> ReqBody '[JSON] Login
:> PostNoContent '[JSON] (loginHeaders $ User)
type family ($) (f :: k1) (x :: k2) = k3
-- Server
data LoginHeaders
type instance LoginHeaders $ x = Headers '[ Header "Set-Cookie" Auth.SetCookie
, Header "Set-Cookie" Auth.SetCookie] x
type ServerAPI = API LoginHeaders
-- Client
data Id
type instance Id $ x = x
type ClientAPI = API Id
|
Would really appreciate some documentation on this. @3noch, I'm trying to use your example for option 3 and haven't been able to get it working. API and client definitions: type API setCookie =
"login"
:> ReqBody '[JSON] Login
:> Post '[JSON] (Headers '[ Header "Set-Cookie" setCookie
, Header "Set-Cookie" setCookie]
User)
data APIClient t m tag = APIClient
{ _login :: Dynamic t (Either Text Login) -> Event t () -> m (Event t (ReqResult () (Headers '[Header "Set-Cookie" Text, Header "Set-Cookie" Text] User)))
}
apiClient :: forall t m tag. MonadWidget t m => APIClient t m tag
apiClient =
let login = client layout m tag urlDyn
layout = Proxy :: Proxy (API Text)
m = Proxy :: Proxy m
tag = Proxy :: Proxy ()
urlDyn = constDyn url
in APIClient login Errors with:
The type family approach gave the same result. Am I missing something? |
@JBetz |
@3noch Yes, and it yields the same error. |
Okay, the error went away after I added Worth noting in the docs, in any case. |
Servant auth peope have moved the FromHttpData instance to http://hackage.haskell.org/package/http-api-data-0.3.10/docs/Web-HttpApiData.html#t:FromHttpApiData Currently that doesn't build against reflex platform but it should be resolved eventually. |
Once logged in then, is there any way to do cross-domain ajax with credentials? Only since it's http-only and not sent with cross-domain requests by default, what flags are we going to need? |
Copied from #36:
The tricky part about
servant-auth
is that it uses very specific types for the API spec. From the example:The problem with this is that
SetCookie
(fromcookie
) needs some [orphan] instances that are supplied byservant-auth-server
in order to work asservant
header types. Clearly the client won't have access to these instances because the server library supplies them.We have some options:
servant-auth-server
). But where would you put these? You could use anewtype
overSetCookie
to help?SetCookie
on the server and some nominal type (e.g.Text
) on the client side. A slight variation of this would be to useCPP
.For option 3, the code could be:
One advantage to option 3 is that the client code doesn't need to add a needless dependency on
cookie
. This really is a needless dependency because the client won't be benefiting from these cookies (or the types that capture them) in any way. In this case, that's actually the point as these must be HTTP-only cookies as well, which means the client can't use them. And since theSetCookie
type is opaque (it says nothing about authentication in particular), there is really no benefit to keeping this information on the client.A more aggressive option would be to parameterize the API type on the entire
Header ...
portion of the login endpoint.I am looking for feedback before I decide to write up docs for this.
I should also mention that to practically use
servant-auth
in a Reflex-DOM app, some changes are needed to support alternative CSRF options inservant-auth-server
. I've started these here: haskell-servant/servant-auth#54From @imalsogreg:
I like options 2 and 3. Maybe a 4th option would be to send a PR to
http-api-data
and to standardize theToHttpApiData
andFromHttpApiData
instances there? cookie's dependencies are very light, I don't see a problem compiling it withghcjs
.The text was updated successfully, but these errors were encountered: