1.0.0 • Published 8 years ago
node-basic-auth v1.0.0
node-basic-auth
Basic authentication parser for NodeJS Projects. Supports domain/team specific basic authentication.
Example format
domain\\name:pass
// =>
// => abc\\mike:test => { domain: 'abc', name: 'mike', pass: 'test' }
Installation
$ npm install node-basic-auth
Import
var bAuth = require('mode-basic-auth')
Usage
var bAuth = require('node-basic-auth')
var cred = bAuth(req)
// => { domain: 'abc', name: 'mike', pass: 'test' }
Usage using expressJS
var express = require('express');
var app = express();
var bAuth = require('node-basic-auth');
app.get('/', function(req, res) {
var cred = bAuth(req, res);
if(!cred || cred.domain != 'abc' || cred.name != 'mike' || cred.pass != 'test') {
//Auth failed
} else {
//Auth success
}
})
app.listen(3000);
Special cases
Without domain
\\mike:test
// => {domain: '', name: 'mike', pass: 'test'}
Without password
abc\\mike:
// => {domain: 'abc', name: 'mike', pass: ''}
License
1.0.0
8 years ago