npm stats
  • Search
  • About
  • Repo
  • Sponsor
  • more
    • Search
    • About
    • Repo
    • Sponsor

Made by Antonio Ramirez

basic-auth-middleware

1.0.0

@yoshuawuyts

npmHomeRepoSnykSocket
Downloads:299
$ npm install basic-auth-middleware
DailyWeeklyMonthlyYearly

basic-auth-middleware stability

npm version build status downloads js-standard-style

Basic auth middleware

Usage

var Auth = require('basic-auth-middleware')
var http = require('http')

var auth = Auth('my-username', 'some-password')

http.createServer(function (req, res) {
  var ctx = {}
  auth(req, res, ctx, function (err) {
    if (err) return res.end('not authenticated')
    res.end('authentication successful')
  })
})

API

middleware = auth(username, password)

Create a new middleware instance.

middleware(req, res, ctx, done([err]))

Validate an incoming HTTP request. Sets res.statusCode to 401. err is an instance of boom.

License

MIT