wai-middleware-bearer: WAI Middleware for Bearer Token Authentication

[ authentication, library, mit, web ] [ Propose Tags ] [ Report a vulnerability ]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

Versions [RSS] 1.0.3
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 MIT
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:15:07Z
Distributions LTSHaskell:1.0.3, NixOS:1.0.3, Stackage:1.0.3
Reverse Dependencies 1 direct, 3 indirect [details]
Downloads 289 total (7 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs uploaded by user
Build status unknown [no reports yet]

Readme for wai-middleware-bearer-1.0.3

[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⏎