Skip to content
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

Client implementation for Cookie auth APIs #1537

Open
L7R7 opened this issue Feb 18, 2022 · 0 comments
Open

Client implementation for Cookie auth APIs #1537

L7R7 opened this issue Feb 18, 2022 · 0 comments

Comments

@L7R7
Copy link

L7R7 commented Feb 18, 2022

I'm currently experimenting with servant-auth and Cookie based authentication and I would like to write a test for such an API using servant-client.

I have the following API definition:

type Unprotected =
  "login"
    :> ReqBody '[FormUrlEncoded] Login
    :> Verb 'POST 204 '[JSON] (Headers '[Header "Set-Cookie" SetCookie, Header "Set-Cookie" SetCookie] NoContent)

type Logout = "logout" :> Get '[JSON] (Headers '[Header "Set-Cookie" SetCookie, Header "Set-Cookie" SetCookie] String)

type Protected = "name" :> Get '[JSON] String

type AuthAPI = (Servant.Auth.Server.Auth '[Cookie] User :> Protected) :<|> Unprotected :<|> Logout

which is supposed to model a form-based login, logout and a protected resource.
This is all fine and works as intended. If I now try and generate client functions, it doesn't compile:

_ = client (Proxy :: Proxy AuthAPI)
Error:     • No instance for (HasClient
                         ClientM (Auth '[Cookie] User :> Protected))
        arising from a use of ‘client’
    • In the expression: client (Proxy :: Proxy AuthAPI)
      In a pattern binding: _ = client (Proxy :: Proxy AuthAPI)
   |
17 | _ = client (Proxy :: Proxy AuthAPI)
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

I found out that servant-auth-client- only supports JWT and basic auth, so it probably isn't what I can use here. I'm also aware that there's ongoing discussion in #1484, but to be honest I'm a bit lost in the details and don't know how to proceed here. Is that something that is supported? Or will it be supported in the future? Or do I have to provide my own implementation for a HasClient instance?

I have a minimal working example for that here. It also includes a test, so you can see the compile error here as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant