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

Servant Auth forces me to use JWT #1598

Closed
mastarija opened this issue Jul 29, 2022 · 1 comment
Closed

Servant Auth forces me to use JWT #1598

mastarija opened this issue Jul 29, 2022 · 1 comment

Comments

@mastarija
Copy link

This is a bit odd, but I have the following API:

data API mode = API
   { info :: mode :- (Auth '[GWS] ( UserProfile Int ) ) :> "info" :> NamedRoutes InfoAPI
   , template :: mode :- (Auth '[GWS] ( UserProfile Int ) ) :> "template" :> NamedRoutes TemplateAPI
   }
  deriving (Generic)

However, I get this warning when I try to compile the program:

server/Server/Servant.hs:132:14: error:
    • Could not deduce (Servant.Server.Internal.Context.HasContextEntry
                          '[] Servant.Auth.Server.Internal.ConfigTypes.JWTSettings)
        arising from a use of ‘genericServeTWithContext’
      from the context: (Given ServerLib.DatabaseUnitSystem,
                         Given PdxfVersion, Given Reporter, Given ServerLib.Port,
                         Given ServerLib.JwsHmacSecret)
        bound by a type expected by the context:
                   (Given ServerLib.DatabaseUnitSystem, Given PdxfVersion,
                    Given Reporter, Given ServerLib.Port,
                    Given ServerLib.JwsHmacSecret) =>
                   IO ()
        at server/Server/Servant.hs:(121,26)-(132,49)
    • In the second argument of ‘($)’, namely
        ‘genericServeTWithContext trn srv ctx’
      In a stmt of a 'do' block:
        run 8088 $ genericServeTWithContext trn srv ctx
      In the second argument of ‘($)’, namely
        ‘do let trn = flip runReaderT Env
                srv = srvr
                ....
            run 8088 $ genericServeTWithContext trn srv ctx’
    |
132 |   run 8088 $ genericServeTWithContext trn srv ctx
    |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Basically it says I should add JWTSettings to my context (even though I have no JWT auth method defined in the Auth list). And if I do add JWTSettings then it asks me to add the CookieSettings as well, and after that to implement the FromJWT instance for my auth result type:

server/Server/Servant.hs:132:14: error:
    • Could not deduce (ToJWT (UserProfile Flouble))
        arising from a use of ‘genericServeTWithContext’
      from the context: (Given ServerLib.DatabaseUnitSystem,
                         Given PdxfVersion, Given Reporter, Given ServerLib.Port,
                         Given ServerLib.JwsHmacSecret)
        bound by a type expected by the context:
                   (Given ServerLib.DatabaseUnitSystem, Given PdxfVersion,
                    Given Reporter, Given ServerLib.Port,
                    Given ServerLib.JwsHmacSecret) =>
                   IO ()
        at server/Server/Servant.hs:(121,26)-(132,49)
    • In the second argument of ‘($)’, namely
        ‘genericServeTWithContext trn srv ctx’
      In a stmt of a 'do' block:
        run 8088 $ genericServeTWithContext trn srv ctx
      In the second argument of ‘($)’, namely
        ‘do let trn = flip runReaderT Env
                srv = srvr
                ....
            run 8088 $ genericServeTWithContext trn srv ctx’
    |
132 |   run 8088 $ genericServeTWithContext trn srv ctx
    |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

After I provide a bogus implementation of ToJWT it settles down, however, now I'm worried it'll try to use it at some point (haven't tested that out yet).

The problem is a constraint in the Auth HasServer instance which requires me to have a ToJWT instance. I don't see why that should be required.

I would also like to implement my own JWT auth, as I have some legacy auth stuff to deal with and I need to check the database when parsing the JWT, so ToJWT and FromJWT aren't enough, and now I'm worried about how this is going to interact with each other.

@mastarija
Copy link
Author

I've just noticed #1576 which mentions this problem and there's #1560 which attempts to address it, so I'm closing this issue.

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