node.js basic auth parser
Generic basic auth Authorization header field parser for whatever.
$ npm install basic-auth
var auth = require'basic-auth'
Get the basic auth credentials from the given request. The Authorization
header is parsed and if the header is invalid, undefined is returned,
otherwise an object with name and pass properties.
Pass a node request or koa Context object to the module exported. If
parsing fails undefined is returned, otherwise an object with
.name and .pass.
var auth = require'basic-auth';var user = authreq;// => { name: 'something', pass: 'whatever' }
var http = require'http'var auth = require'basic-auth' // Create server var server = httpcreateServer var credentials = authreq if !credentials || credentialsname !== 'john' || credentialspass !== 'secret' resstatusCode = 401 ressetHeader'WWW-Authenticate' 'Basic realm="example"' resend'Access denied' else resend'Access granted' // Listen serverlisten3000