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

Using with AuthProtect #2

Open
xaviershay opened this Issue Apr 28, 2018 · 2 comments

Comments

Projects
None yet
1 participant
@xaviershay
Copy link

xaviershay commented Apr 28, 2018

I'm using Generalized Authentication to protect my API, and getting the following error using servant-options:

No instance for (HasForeign NoTypes NoContent (AuthProtect "my-auth" :> ("quotes" :> Get '[JSON] [Quote])))
arising from a use of 'provideOptions'

I'm pretty sure this is related to #1, but I'm creating a more specific issue for searchability, and in case they can be solved separately. I'm going to spend some more time poking around now to see if I can wrap my head around HasForeign.

@xaviershay

This comment has been minimized.

Copy link
Author

xaviershay commented Apr 28, 2018

Seems this is a common problem in many different contexts ( eskimor/servant-purescript#9 , haskell-servant/servant-auth#8 ). First failed attempt based on haskell-servant/servant-auth#8

instance (HasForeign lang ftype api) =>
  HasForeign lang ftype (AuthProtect :> api) where

  type Foreign ftype (AuthProtect :> api) = Foreign ftype api

  foreignFor lang Proxy Proxy subR =
    foreignFor lang Proxy (Proxy :: Proxy api) subR

Doesn't type check:

    • Type indexes must match class instance head
      Expected: Foreign ftype (AuthProtect :> api)
        Actual: Foreign ftype (AuthProtect :> api)
    • In the type instance declaration for ‘Foreign’
      In the instance declaration for
        ‘HasForeign lang ftype (AuthProtect :> api)’

Tried adding kind annotations as suggested in https://ghc.haskell.org/trac/ghc/ticket/13972 but couldn't get any clearer failure messages. Adding the forall part from linked issue doesn't change error.

@xaviershay

This comment has been minimized.

Copy link
Author

xaviershay commented Apr 28, 2018

Ah I was close, I had the kind of AuthProtect wrong. The following appears to work for me:

instance (HasForeign lang ftype api) =>
  HasForeign lang ftype (AuthProtect k :> api) where

  type Foreign ftype (AuthProtect k :> api) = Foreign ftype api

  foreignFor lang Proxy Proxy subR =
    foreignFor lang Proxy (Proxy :: Proxy api) subR
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.