haskell-servant / haskell-servant/servant

Generating clients for JWT example in cookbook

Open
#1,873 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Haskell
Stars
2k
Forks
427
Avg merge
2d 23h
Merged PRs (30d)
5

Description

Hello,

I'm following the Servant Cookbook example to combine Basic authentication with JWT. My server works but when trying to generate client functions, I keep getting an error similar to https://github.com/haskell-servant/servant/issues/558

```
[typecheck] • Couldn't match type: Token
-> (RegisterPayload -> ClientM RegisterResponse)
:<|> (ClientM LoginResponse :<|> ClientM TestPayload)
with: (Token -> RegisterPayload -> ClientM RegisterResponse)
:<|> ((Token -> ClientM LoginResponse)
:<|> (Token -> ClientM TestPayload))
Expected: ClientM ServerStatus
:<|> ((Token -> RegisterPayload -> ClientM RegisterResponse)
:<|> ((Token -> ClientM LoginResponse)
:<|> (Token -> ClientM TestPayload)))
Actual: Client ClientM API
• In the expression: client $ (Proxy :: Proxy API)
In a pattern binding:
checkStatus :<|> (basicRegister :<|> basicLogin :<|> basicTest)
= client $ (Proxy :: Proxy API)
```

```haskell
type PublicAPI =
"status" :> Description "Provide server status" :> Get '[JSON] ServerStatus

type ManagedAPI =
"register"
:> Description "Create a user"
:> ReqBody '[JSON] RegisterPayload
:> PostCreated '[JSON] RegisterResponse
:<|> "login"
:> Description "Log in with existing user"
:> Post '[JSON] LoginResponse
:<|> "tokentest"
:> Description "Test JWT auth"
:> Get '[JSON] TestPayload

type API =
PublicAPI
:<|> Auth '[SA.JWT, SA.BasicAuth] AuthenticatedUser :> (ManagedAPI)

checkStatus :: ClientM ServerStatus
basicRegister :: Token -> RegisterPayload -> ClientM RegisterResponse
basicLogin :: Token -> ClientM LoginResponse
basicTest :: Token -> ClientM TestPayload
checkStatus :<|> (basicRegister :<|> basicLogin :<|> basicTest) = client $ (Proxy :: Proxy API)

```

Shouldn't the `Token` parameter get distributed to all the client functions under `ManagedAPI`?

Contributor guide

Open the contributing guide

Research direction

Start with the Servant Cookbook JWT and Basic authentication example, then inspect client generation at the `client (Proxy :: Proxy API)` entry point and compare it with the `ManagedAPI` type. Confirm whether the generated client distributes `Token` across the managed endpoints, and consider the issue complete when the example's client bindings typecheck with the expected signatures.

Written by the indexing model from the issue text.

Assessment

Tech stack
haskell
Domain
api
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.