MIT licensed by Martin Bednar
Maintained by [email protected]
This version can be pinned in stack with:wai-middleware-bearer-1.0.3@sha256:bc3e7edbfe0fe9a2bed5c538a009a1a53cace5eae3871dfc29572ddb54fca502,1675

Module documentation for 1.0.3

wai-middleware-bearer

WAI middleware providing bearer token authentication.

Usage example

The following code shows a secure Hello World application:

{-# LANGUAGE OverloadedStrings #-}
module Main where

import Network.Wai.Middleware.BearerTokenAuth
import Network.Wai
import Network.HTTP.Types.Status (status200)
import Network.Wai.Handler.Warp (run)

myApp :: Application
myApp req rsp = rsp $ responseLBS status200 [] "Hello World"

secureApp :: Application
secureApp = tokenListAuth ["abc", "123"] myApp

main :: IO ()
main = run 3000 secureApp

Valid token request example (200 OK):

$ curl -H "Authorization: bearer abc" 'localhost:3000'

Hello World⏎

Invalid token request example (401 Unauthorized):

$ curl -H "Authorization: bearer otherToken" 'localhost:3000'

Bearer token authentication is required⏎ 

Missing token request example (401 Unauthorized):

curl 'localhost:3000'

Bearer token authentication is required⏎