node-basic-auth

1.0.0 • Public • Published

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

MIT

Package Sidebar

Install

npm i node-basic-auth

Weekly Downloads

0

Version

1.0.0

License

MIT

Last publish

Collaborators

  • sourabhdebnath