wai-middleware-bearer: WAI middleware providing the Bearer Token HTTP authentication scheme.

This is a package candidate release! Here you can preview how this package release will appear once published to the main package index (which can be accomplished via the 'maintain' link below). Please note that once a package has been published to the main package index it cannot be undone! Please consult the package uploading documentation for more information.

[maintain] [Publish]

Please see the README on GitHub at https://github.com/martin-bednar/wai-middleware-bearer#readme


[Skip to Readme]

Properties

Versions 1.0.1, 1.0.3
Change log None available
Dependencies base (>=4.7 && <5), bytestring (>=0.10.12.1 && <1), http-types (>=0.12.3 && <1), wai (>=3.2.3 && <4), word8 (>=0.1.3 && <1) [details]
License BSD-3-Clause
Copyright 2022 Martin Bednar
Author Martin Bednar
Maintainer bednam17@fit.cvut.cz
Category Authentication, Web
Home page https://github.com/martin-bednar/wai-middleware-bearer#readme
Bug tracker https://github.com/martin-bednar/wai-middleware-bearer/issues
Source repo head: git clone https://github.com/martin-bednar/wai-middleware-bearer
Uploaded by martinbednar at 2022-05-26T12:01:38Z

Modules

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees


Readme for wai-middleware-bearer-1.0.1

[back to package description]

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⏎