@@ -44,7 +44,7 @@ You can use this combinator to protect an API as follows:
44
44
45
45
module Authentication where
46
46
47
- import Control.Monad.Trans.Except (ExceptT, throwE )
47
+ import Control.Monad.Trans.Except (ExceptT)
48
48
import Data.Aeson (ToJSON)
49
49
import Data.ByteString (ByteString)
50
50
import Data.Map (Map, fromList)
@@ -59,6 +59,7 @@ import Servant.API ((:<|>) ((:<|>)), (:>), BasicAuth,
59
59
Get, JSON)
60
60
import Servant.API.BasicAuth (BasicAuthData (BasicAuthData))
61
61
import Servant.API.Experimental.Auth (AuthProtect)
62
+ import Servant (throwError)
62
63
import Servant.Server (BasicAuthCheck (BasicAuthCheck),
63
64
BasicAuthResult( Authorized
64
65
, Unauthorized
@@ -173,7 +174,7 @@ And now we create the `Context` used by servant to find `BasicAuthCheck`:
173
174
`` `haskell
174
175
-- | We need to supply our handlers with the right Context. In this case,
175
176
-- Basic Authentication requires a Context Entry with the 'BasicAuthCheck' value
176
- -- tagged with " foo-tag" This context is then supplied to 'server' and threaded
177
+ -- tagged with " foo-tag" This context is then supplied to 'server' and threaded
177
178
-- to the BasicAuth HasServer handlers.
178
179
basicAuthServerContext :: Context (BasicAuthCheck User ': ' [])
179
180
basicAuthServerContext = authCheck :. EmptyContext
@@ -274,7 +275,7 @@ database = fromList [ ("key1", Account "Anne Briggs")
274
275
-- This is our bespoke (and bad) authentication logic.
275
276
lookupAccount :: ByteString -> ExceptT ServantErr IO Account
276
277
lookupAccount key = case Map.lookup key database of
277
- Nothing -> throwE (err403 { errBody = "Invalid Cookie" })
278
+ Nothing -> throwError (err403 { errBody = "Invalid Cookie" })
278
279
Just usr -> return usr
279
280
```
280
281
@@ -289,7 +290,7 @@ method:
289
290
authHandler :: AuthHandler Request Account
290
291
authHandler =
291
292
let handler req = case lookup "servant-auth-cookie" (requestHeaders req) of
292
- Nothing -> throwE (err401 { errBody = "Missing auth header" })
293
+ Nothing -> throwError (err401 { errBody = "Missing auth header" })
293
294
Just authCookieKey -> lookupAccount authCookieKey
294
295
in mkAuthHandler handler
295
296
```
@@ -329,7 +330,7 @@ We now construct the `Context` for our server, allowing us to instantiate a
329
330
value of type `Server AuthGenAPI`, in addition to the server value:
330
331
331
332
```haskell
332
- -- | The context that will be made available to request handlers. We supply the
333
+ -- | The context that will be made available to request handlers. We supply the
333
334
-- "cookie-auth"-tagged request handler defined above, so that the 'HasServer' instance
334
335
-- of 'AuthProtect' can extract the handler and run it on the request.
335
336
genAuthServerContext :: Context (AuthHandler Request Account ': '[])
0 commit comments