Copyright | (c) Martin Bednar 2022 |
---|---|
License | MIT |
Maintainer | bednam17@fit.cvut.cz |
Stability | experimental |
Portability | POSIX |
Safe Haskell | None |
Language | Haskell2010 |
Implements Bearer Token Authentication as a WAI Middleware
.
This module is based on HttpAuth
.
Synopsis
- tokenListAuth :: [ByteString] -> Middleware
- tokenAuth :: TokenValidator -> Middleware
- tokenAuth' :: (Request -> TokenValidator) -> Middleware
- type TokenValidator = ByteString -> IO Bool
Middleware
You can choose from three functions to use this middleware:
tokenListAuth
is the simplest to use and accepts a list of valid tokens;tokenAuth
can be used to perform a more sophisticated validation of the accepted token (such as database lookup);tokenAuth'
is similar totokenAuth
, but it also passes theRequest
to the validation function.
tokenListAuth :: [ByteString] -> Middleware Source #
Perform token authentication based on a list of allowed tokens.
tokenListAuth ["secret1", "secret2"]
:: TokenValidator | Function that determines whether the token is valid |
-> Middleware |
Performs token authentication.
If the token is accepted, leaves the Application unchanged.
Otherwise, sends a 401 Unauthorized
HTTP response.
tokenAuth (\tok -> return $ tok == "abcd" )
:: (Request -> TokenValidator) | Function that determines whether the token is valid |
-> Middleware |
Token validation
type TokenValidator = ByteString -> IO Bool Source #
Type synonym for validating a token