Closed newlandsvalley closed 4 years ago
Hi @newlandsvalley I'll see if I can replicate this!
What version of Servant are you using?
Hi, @sordina - many thanks. I'm using 0.16.2. I must admit, I'm not entirely sure what I'm doing at the moment!
Hi @newlandsvalley I've pushed a couple of examples to GitHub that replicates your issue:
2ea2c3c..ef7b541
I'll see if I can fix the issue!
You can work around this with something like:
type UserAPI' = "users" :> QueryParam "sortby" SortBy :> Get '[JSON] [User]
type UserAPI = BasicAuth "foo-realm" User :> UserAPI'
app :: [User] -> Application
app us = serveWithContext
(Proxy :: Proxy UserAPI)
basicAuthServerContext $ apiImpl
main :: IO ()
main = run 8081 (provideOptions (Proxy :: Proxy UserAPI') app)
Although this obviously isn't ideal, especially if your auth routes are nested!
Looks like the issue is mentioned upstream in servant-foreign:
Very many thanks for making such an effort to investigate this, @sordina. In actual fact I realise now that I can get by with simpleCors
so it's no longer holding me back. I hadn't spotted the servant-foreign issue.
No problems @newlandsvalley I'll let you know if I figure out how to implement the fix!
@newlandsvalley I got it working with the following orphan instance:
instance (HasForeign lang ftype api) => HasForeign lang ftype (BasicAuth a b :> api) where
type Foreign ftype (BasicAuth a b :> api) = Foreign ftype api
foreignFor lang proxy1 Proxy req = foreignFor lang proxy1 (Proxy :: Proxy api) req
1c3faf3..aa9338b
Wow!
I'm attempting to protect my API with BasicAuth, and get this error when using servant-options: