wai-middleware-bearer-1.0.3: WAI Middleware for Bearer Token Authentication
Copyright(c) Martin Bednar 2022
LicenseMIT
Maintainerbednam17@fit.cvut.cz
Stabilityexperimental
PortabilityPOSIX
Safe HaskellNone
LanguageHaskell2010

Network.Wai.Middleware.BearerTokenAuth

Description

Implements Bearer Token Authentication as a WAI Middleware.

This module is based on HttpAuth.

Synopsis

Middleware

You can choose from three functions to use this middleware:

  1. tokenListAuth is the simplest to use and accepts a list of valid tokens;
  2. tokenAuth can be used to perform a more sophisticated validation of the accepted token (such as database lookup);
  3. tokenAuth' is similar to tokenAuth, but it also passes the Request to the validation function.

tokenListAuth :: [ByteString] -> Middleware Source #

Perform token authentication based on a list of allowed tokens.

tokenListAuth ["secret1", "secret2"]

tokenAuth Source #

Arguments

:: 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" )

tokenAuth' Source #

Arguments

:: (Request -> TokenValidator)

Function that determines whether the token is valid

-> Middleware 

Like tokenAuth, but also passes the Request to the validator function.

Token validation

type TokenValidator = ByteString -> IO Bool Source #

Type synonym for validating a token