Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

http-auth-utils

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

http-auth-utils - npm Package Compare versions

Comparing version 1.0.1 to 2.0.0

API.md

2

.prettierrc.js

@@ -6,3 +6,3 @@ module.exports = {

trailingComma: 'all',
proseWrap: true,
proseWrap: 'always',
};

@@ -0,1 +1,21 @@

<a name="2.0.0"></a>
# [2.0.0](https://github.com/nfroidure/http-auth-utils/compare/v1.0.1...v2.0.0) (2018-08-30)
### Bug Fixes
* **Root modules:** Fix exportation of root modules ([0ae79ee](https://github.com/nfroidure/http-auth-utils/commit/0ae79ee))
### Code Refactoring
* **Typo:** Fix the mechanism typo ([d2ebdde](https://github.com/nfroidure/http-auth-utils/commit/d2ebdde))
### BREAKING CHANGES
* **Typo:** The mechanism word replaced the bad mecanism one everywhere
<a name="1.0.1"></a>

@@ -2,0 +22,0 @@ ## [1.0.1](https://github.com/nfroidure/http-auth-utils/compare/v1.0.0...v1.0.1) (2017-12-04)

@@ -6,3 +6,3 @@ 'use strict';

});
exports.mecanisms = exports.BEARER = exports.DIGEST = exports.BASIC = undefined;
exports.mechanisms = exports.BEARER = exports.DIGEST = exports.BASIC = undefined;
exports.parseWWWAuthenticateHeader = parseWWWAuthenticateHeader;

@@ -15,11 +15,11 @@ exports.parseAuthorizationHeader = parseAuthorizationHeader;

var _basic = require('./mecanisms/basic');
var _basic = require('./mechanisms/basic');
var _basic2 = _interopRequireDefault(_basic);
var _digest = require('./mecanisms/digest');
var _digest = require('./mechanisms/digest');
var _digest2 = _interopRequireDefault(_digest);
var _bearer = require('./mecanisms/bearer');
var _bearer = require('./mechanisms/bearer');

@@ -35,30 +35,32 @@ var _bearer2 = _interopRequireDefault(_bearer);

/**
* Basic authentication mecanism.
* @type {Object}
* @see {@link module:http-auth-utils/mecanisms/basic}
* Natively supported authentication mechanisms.
* @type {Array}
*/
exports.BASIC = _basic2.default;
const mechanisms = [_basic2.default, _digest2.default, _bearer2.default];
/**
* Digest authentication mecanism.
* Basic authentication mechanism.
* @type {Object}
* @see {@link module:http-auth-utils/mecanisms/digest}
* @see {@link module:http-auth-utils/mechanisms/basic}
*/
_basic2.default;
exports.DIGEST = _digest2.default;
/**
* Bearer authentication mecanism.
* Digest authentication mechanism.
* @type {Object}
* @see {@link module:http-auth-utils/mecanisms/digest}
* @see {@link module:http-auth-utils/mechanisms/digest}
*/
_digest2.default;
exports.BEARER = _bearer2.default;
/**
* Natively supported authentication mecanisms.
* @type {Array}
* Bearer authentication mechanism.
* @type {Object}
* @see {@link module:http-auth-utils/mechanisms/digest}
*/
_bearer2.default;
var mecanisms = exports.mecanisms = [_basic2.default, _digest2.default, _bearer2.default];
exports.BASIC = _basic2.default;
exports.DIGEST = _digest2.default;
exports.BEARER = _bearer2.default;
exports.mechanisms = mechanisms;

@@ -69,3 +71,3 @@ /**

* @param {string} header The WWW-Authenticate header contents
* @param {Array} [authMecanisms=[BASIC, DIGEST]] Allow providing custom authentication mecanisms.
* @param {Array} [authMechanisms=[BASIC, DIGEST]] Allow providing custom authentication mechanisms.
* @return {Object} Result of the contents parse.

@@ -83,12 +85,11 @@ * @api public

*/
function parseWWWAuthenticateHeader(header) {
var authMecanisms = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : mecanisms;
var result = null;
function parseWWWAuthenticateHeader(header, authMechanisms = mechanisms) {
let result = null;
authMecanisms.some(function (authMecanism) {
if (0 === header.indexOf(authMecanism.type + ' ')) {
authMechanisms.some(authMechanism => {
if (0 === header.indexOf(authMechanism.type + ' ')) {
result = {
type: authMecanism.type,
data: authMecanism.parseWWWAuthenticateRest(header.substr(authMecanism.type.length + 1))
type: authMechanism.type,
data: authMechanism.parseWWWAuthenticateRest(header.substr(authMechanism.type.length + 1))
};

@@ -100,3 +101,3 @@ return true;

if (!result) {
throw new _yerror2.default('E_UNKNOWN_AUTH_MECANISM', header);
throw new _yerror2.default('E_UNKNOWN_AUTH_MECHANISM', header);
}

@@ -110,3 +111,3 @@ return result;

* @param {string} header The Authorization header contents
* @param {Array} [authMecanisms=[BASIC, DIGEST, BEARER]] Allow custom authentication mecanisms.
* @param {Array} [authMechanisms=[BASIC, DIGEST, BEARER]] Allow custom authentication mechanisms.
* @return {Object} Result of the contents parse.

@@ -124,12 +125,10 @@ * @api public

*/
function parseAuthorizationHeader(header) {
var authMecanisms = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : mecanisms;
function parseAuthorizationHeader(header, authMechanisms = mechanisms) {
let result = null;
var result = null;
authMecanisms.some(function (authMecanism) {
if (0 === header.indexOf(authMecanism.type + ' ')) {
authMechanisms.some(function (authMechanism) {
if (0 === header.indexOf(authMechanism.type + ' ')) {
result = {
type: authMecanism.type,
data: authMecanism.parseAuthorizationRest(header.substr(authMecanism.type.length + 1))
type: authMechanism.type,
data: authMechanism.parseAuthorizationRest(header.substr(authMechanism.type.length + 1))
};

@@ -143,3 +142,3 @@ return true;

}
throw new _yerror2.default('E_UNKNOWN_AUTH_MECANISM', header);
throw new _yerror2.default('E_UNKNOWN_AUTH_MECHANISM', header);
}

@@ -15,5 +15,5 @@ 'use strict';

describe('index', function () {
describe('parseWWWAuthenticateHeader', function () {
it('should parse Basic headers', function () {
describe('index', () => {
describe('parseWWWAuthenticateHeader', () => {
it('should parse Basic headers', () => {
(0, _neatequal2.default)((0, _index.parseWWWAuthenticateHeader)('Basic realm="test"'), {

@@ -26,6 +26,18 @@ type: 'Basic',

});
it('should parse Basic headers', () => {
(0, _neatequal2.default)((0, _index.parseWWWAuthenticateHeader)('Basic realm="test"', _index.mechanisms), {
type: 'Basic',
data: {
realm: 'test'
}
});
});
it('should fail with unknown headers', () => {
_assert2.default.throws(() => (0, _index.parseWWWAuthenticateHeader)('Kikoolol realm="test"'), /E_UNKNOWN_AUTH_MECHANISM/);
});
});
describe('parseAuthorizationHeader', function () {
it('should parse Basic headers', function () {
describe('parseAuthorizationHeader', () => {
it('should parse Basic headers', () => {
(0, _neatequal2.default)((0, _index.parseAuthorizationHeader)('Basic QWxpIEJhYmE6b3BlbiBzZXNhbWU='), {

@@ -39,2 +51,10 @@ type: 'Basic',

});
(0, _neatequal2.default)((0, _index.parseAuthorizationHeader)('Basic QWxpIEJhYmE6b3BlbiBzZXNhbWU=', _index.mechanisms), {
type: 'Basic',
data: {
username: 'Ali Baba',
password: 'open sesame',
hash: 'QWxpIEJhYmE6b3BlbiBzZXNhbWU='
}
});
(0, _neatequal2.default)((0, _index.parseAuthorizationHeader)('Basic bmljb2xhcy5mcm9pZHVyZUBzaW1wbGlmaWVsZC5jb206dGVzdA=='), {

@@ -50,3 +70,3 @@ type: 'Basic',

it('should parse Basic headers with a ":" char in the password', function () {
it('should parse Basic headers with a ":" char in the password', () => {
(0, _neatequal2.default)((0, _index.parseAuthorizationHeader)('Basic Sm9objpSOlU6a2lkZGluZz8='), {

@@ -61,10 +81,14 @@ type: 'Basic',

});
it('should fail with unknown headers', () => {
_assert2.default.throws(() => (0, _index.parseAuthorizationHeader)('Kikoolol ddd'), /E_UNKNOWN_AUTH_MECHANISM/);
});
});
describe('mecanisms', function () {
it('should export bot DIGEST and BASIC mecanisms', function () {
_assert2.default.equal(_index.mecanisms.length, 3);
describe('mechanisms', () => {
it('should export bot DIGEST and BASIC mechanisms', () => {
_assert2.default.equal(_index.mechanisms.length, 3);
});
it('should export DIGEST BASIC and BEARER mecanisms', function () {
it('should export DIGEST BASIC and BEARER mechanisms', () => {
(0, _assert2.default)(_index.BASIC);

@@ -71,0 +95,0 @@ (0, _assert2.default)(_index.DIGEST);

@@ -6,5 +6,2 @@ 'use strict';

});
var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
exports.parseHTTPHeadersQuotedKeyValueSet = parseHTTPHeadersQuotedKeyValueSet;

@@ -19,14 +16,12 @@ exports.buildHTTPHeadersQuotedKeyValueSet = buildHTTPHeadersQuotedKeyValueSet;

var QUOTE = '"';
var EQUAL = '=';
var SEPARATOR = ', ';
var SEPARATOR_REGEXP = /", ?/;
const QUOTE = '"';
const EQUAL = '=';
const SEPARATOR = ', ';
const SEPARATOR_REGEXP = /", ?/;
// FIXME: Create a real parser
function parseHTTPHeadersQuotedKeyValueSet(contents, authorizedKeys) {
var requiredKeys = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
var data = contents.split(SEPARATOR_REGEXP).map(function (part, partPosition, parts) {
function parseHTTPHeadersQuotedKeyValueSet(contents, authorizedKeys, requiredKeys = []) {
const data = contents.split(SEPARATOR_REGEXP).map((part, partPosition, parts) => {
part = parts.length - 1 === partPosition ? part : part + '"';
var pair = part.split(EQUAL);
let pair = part.split(EQUAL);
if (2 !== pair.length) {

@@ -36,7 +31,3 @@ throw new _yerror2.default('E_MALFORMED_QUOTEDKEYVALUE', partPosition, part, pair.length);

return pair;
}).reduce(function (parsedValues, _ref, valuePosition) {
var _ref2 = _slicedToArray(_ref, 2),
name = _ref2[0],
value = _ref2[1];
}).reduce(function (parsedValues, [name, value], valuePosition) {
if (-1 === authorizedKeys.indexOf(name)) {

@@ -57,5 +48,3 @@ throw new _yerror2.default('E_UNAUTHORIZED_KEY', valuePosition, name);

function buildHTTPHeadersQuotedKeyValueSet(data, authorizedKeys) {
var requiredKeys = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
function buildHTTPHeadersQuotedKeyValueSet(data, authorizedKeys, requiredKeys = []) {
_checkRequiredKeys(requiredKeys, data);

@@ -71,4 +60,4 @@ return authorizedKeys.reduce(function (contents, key) {

function _checkRequiredKeys(requiredKeys, data) {
requiredKeys.forEach(function (name) {
if ('undefined' !== typeof data[name]) {
requiredKeys.forEach(name => {
if ('undefined' === typeof data[name]) {
throw new _yerror2.default('E_REQUIRED_KEY', name);

@@ -75,0 +64,0 @@ }

@@ -15,6 +15,6 @@ 'use strict';

describe('utils', function () {
describe('parseHTTPHeadersQuotedKeyValueSet', function () {
it('should work with good datas', function () {
(0, _neatequal2.default)((0, _utils.parseHTTPHeadersQuotedKeyValueSet)('realm="testrealm@host.com", ' + 'qop="auth, auth-int", ' + 'nonce="dcd98b7102dd2f0e8b11d0f600bfb0c093", ' + 'opaque="5ccc069c403ebaf9f0171e9517f40e41"', ['realm', 'qop', 'nonce', 'opaque']), {
describe('utils', () => {
describe('parseHTTPHeadersQuotedKeyValueSet', () => {
it('should work with good datas', () => {
(0, _neatequal2.default)((0, _utils.parseHTTPHeadersQuotedKeyValueSet)('realm="testrealm@host.com", ' + 'qop="auth, auth-int", ' + 'nonce="dcd98b7102dd2f0e8b11d0f600bfb0c093", ' + 'opaque="5ccc069c403ebaf9f0171e9517f40e41"', ['realm', 'qop', 'nonce', 'opaque'], ['realm', 'qop', 'nonce', 'opaque']), {
realm: 'testrealm@host.com',

@@ -26,14 +26,41 @@ qop: 'auth, auth-int',

});
it('should fail with bad quoted value pair', () => {
_assert2.default.throws(() => (0, _utils.parseHTTPHeadersQuotedKeyValueSet)('realm'), /E_MALFORMED_QUOTEDKEYVALUE/);
});
it('should fail with bad quoted value pair', () => {
_assert2.default.throws(() => (0, _utils.parseHTTPHeadersQuotedKeyValueSet)('realm="dsad"', []), /E_UNAUTHORIZED_KEY/);
});
it('should fail with bad quoted value pair', () => {
_assert2.default.throws(() => (0, _utils.parseHTTPHeadersQuotedKeyValueSet)('realm=dsad', ['realm']), /E_UNQUOTED_VALUE/);
});
});
describe('buildHTTPHeadersQuotedKeyValueSet', function () {
it('should work with good datas', function () {
describe('buildHTTPHeadersQuotedKeyValueSet', () => {
it('should work with good datas', () => {
_assert2.default.equal((0, _utils.buildHTTPHeadersQuotedKeyValueSet)({
realm: 'testrealm@host.com',
qop: 'auth, auth-int',
nonce: 'dcd98b7102dd2f0e8b11d0f600bfb0c093'
}, ['realm', 'qop', 'nonce', 'opaque'], ['realm', 'qop', 'nonce']), 'realm="testrealm@host.com", ' + 'qop="auth, auth-int", ' + 'nonce="dcd98b7102dd2f0e8b11d0f600bfb0c093"');
});
it('should work with unused keys', () => {
_assert2.default.equal((0, _utils.buildHTTPHeadersQuotedKeyValueSet)({
realm: 'testrealm@host.com',
qop: 'auth, auth-int',
nonce: 'dcd98b7102dd2f0e8b11d0f600bfb0c093',
opaque: '5ccc069c403ebaf9f0171e9517f40e41'
}, ['realm', 'qop', 'nonce', 'opaque']), 'realm="testrealm@host.com", ' + 'qop="auth, auth-int", ' + 'nonce="dcd98b7102dd2f0e8b11d0f600bfb0c093", ' + 'opaque="5ccc069c403ebaf9f0171e9517f40e41"');
}, ['realm', 'qop', 'nonce']), 'realm="testrealm@host.com", ' + 'qop="auth, auth-int", ' + 'nonce="dcd98b7102dd2f0e8b11d0f600bfb0c093"');
});
it('should fail without required keys', () => {
_assert2.default.throws(() => (0, _utils.buildHTTPHeadersQuotedKeyValueSet)({
realm: 'testrealm@host.com',
qop: 'auth, auth-int'
}, ['realm', 'qop', 'nonce'], ['realm', 'qop', 'nonce'], 'realm="testrealm@host.com", ' + 'qop="auth, auth-int", ' + 'nonce="dcd98b7102dd2f0e8b11d0f600bfb0c093"', /E_UNQUOTED_VALUE/));
});
});
});
{
"name": "http-auth-utils",
"version": "1.0.1",
"version": "2.0.0",
"description": "Parse, build and deal with HTTP auth headers.",

@@ -8,4 +8,7 @@ "main": "dist/index.js",

"data": {
"files": "src/*.js src/**/*.js",
"testsFiles": "src/*.mocha.js"
"files": "'src/**/*.js'",
"testsFiles": "'src/**/*.mocha.js'",
"ignore": [
"dist"
]
},

@@ -26,10 +29,10 @@ "configs": [

"compile": "babel src --out-dir=dist",
"cover": "istanbul cover _mocha --report html -- --compilers js:babel-register src/*.mocha.js -R spec -t 5000",
"coveralls": "istanbul cover _mocha --report lcovonly -- --compilers js:babel-register src/*.mocha.js -R spec -t 5000 && cat ./coverage/lcov.info | coveralls && rm -rf ./coverage",
"cover": "istanbul cover _mocha --report html -- --compilers js:babel-register 'src/**/*.mocha.js' -R spec -t 5000",
"coveralls": "istanbul cover _mocha --report lcovonly -- --compilers js:babel-register 'src/**/*.mocha.js' -R spec -t 5000 && cat ./coverage/lcov.info | coveralls && rm -rf ./coverage",
"cz": "env NODE_ENV=${NODE_ENV:-cli} git cz",
"doc": "mkdir -p .readme; echo \"# API\" > .readme/API.md; jsdoc2md src/*.js src/**/*.js >> .readme/API.md",
"lint": "eslint src/*.js src/**/*.js",
"doc": "echo \"# API\" > API.md; jsdoc2md 'src/**/*.js' >> API.md",
"lint": "eslint 'src/**/*.js'",
"metapak": "metapak",
"mocha": "mocha --compilers js:babel-register src/*.mocha.js",
"prettier": "prettier --write src/*.js src/**/*.js",
"mocha": "mocha --compilers js:babel-register 'src/**/*.mocha.js'",
"prettier": "prettier --write 'src/**/*.js'",
"preversion": "npm t && npm run lint && npm run metapak -s && npm run compile",

@@ -60,22 +63,21 @@ "test": "npm run mocha",

"babel-cli": "^6.26.0",
"babel-eslint": "^7.1.0",
"babel-plugin-transform-async-to-module-method": "^6.24.1",
"babel-core": "^6.26.0",
"babel-eslint": "^8.2.2",
"babel-plugin-transform-object-rest-spread": "^6.26.0",
"babel-preset-env": "^1.6.1",
"babel-preset-es2015": "^6.3.13",
"babel-register": "^6.9.0",
"babel-register": "^6.26.0",
"commitizen": "^2.9.6",
"conventional-changelog-cli": "^1.3.5",
"coveralls": "^2.13.3",
"cz-conventional-changelog": "^2.0.0",
"eslint": "^4.12.1",
"eslint-plugin-prettier": "^2.3.1",
"conventional-changelog-cli": "^1.3.8",
"coveralls": "^3.0.0",
"cz-conventional-changelog": "^2.1.0",
"eslint": "^4.19.0",
"eslint-plugin-prettier": "^2.6.0",
"istanbul": "^1.0.0-alpha.2",
"jsdoc-to-markdown": "^3.1.0-0",
"metapak": "^1.0.2",
"metapak-nfroidure": "^2.0.2",
"mocha": "^3.5.3",
"metapak": "^1.0.3",
"metapak-nfroidure": "^6.1.0",
"mocha": "^5.0.0",
"mocha-lcov-reporter": "^1.3.0",
"neatequal": "^1.0.0",
"prettier": "^1.8.2",
"prettier": "^1.11.1",
"sinon": "^1.14.1"

@@ -108,3 +110,18 @@ },

]
},
"babel": {
"presets": [
[
"env",
{
"targets": {
"node": "6.9.5"
}
}
]
],
"plugins": [
"transform-object-rest-spread"
]
}
}

@@ -1,6 +0,7 @@

<!--
# This file is automatically generated by a `metapak`
# module. Do not change it elsewhere, changes would
# be overridden.
-->
[//]: # ( )
[//]: # (This file is automatically generated by a `metapak`)
[//]: # (module. Do not change it except between the)
[//]: # (`content:start/end` flags, your changes would)
[//]: # (be overridden.)
[//]: # ( )
# http-auth-utils

@@ -17,2 +18,5 @@ > Parse, build and deal with HTTP auth headers.

[//]: # (::contents:start)
This library provide several utilities to parse and build WWW-Authenticate and

@@ -30,7 +34,7 @@ Authorization headers as described per the HTTP RFC.

<dd></dd>
<dt><a href="#module_http-auth-utils/mecanisms/basic">http-auth-utils/mecanisms/basic</a></dt>
<dt><a href="#module_http-auth-utils/mechanisms/basic">http-auth-utils/mechanisms/basic</a></dt>
<dd></dd>
<dt><a href="#module_http-auth-utils/mecanisms/bearer">http-auth-utils/mecanisms/bearer</a></dt>
<dt><a href="#module_http-auth-utils/mechanisms/bearer">http-auth-utils/mechanisms/bearer</a></dt>
<dd></dd>
<dt><a href="#module_http-auth-utils/mecanisms/digest">http-auth-utils/mecanisms/digest</a></dt>
<dt><a href="#module_http-auth-utils/mechanisms/digest">http-auth-utils/mechanisms/digest</a></dt>
<dd></dd>

@@ -44,15 +48,596 @@ </dl>

* [http-auth-utils](#module_http-auth-utils)
* [.mecanisms](#module_http-auth-utils.mecanisms) : <code>Array</code>
* [.parseWWWAuthenticateHeader(header, [authMecanisms])](#module_http-auth-utils.parseWWWAuthenticateHeader) ⇒ <code>Object</code>
* [.parseAuthorizationHeader(header, [authMecanisms])](#module_http-auth-utils.parseAuthorizationHeader) ⇒ <code>Object</code>
* _static_
* [.parseWWWAuthenticateHeader(header, [authMechanisms])](#module_http-auth-utils.parseWWWAuthenticateHeader) ⇒ <code>Object</code>
* [.parseAuthorizationHeader(header, [authMechanisms])](#module_http-auth-utils.parseAuthorizationHeader) ⇒ <code>Object</code>
* _inner_
* [~mechanisms](#module_http-auth-utils..mechanisms) : <code>Array</code>
<a name="module_http-auth-utils.mecanisms"></a>
<a name="module_http-auth-utils.parseWWWAuthenticateHeader"></a>
### http-auth-utils.mecanisms : <code>Array</code>
Natively supported authentication mecanisms.
### http-auth-utils.parseWWWAuthenticateHeader(header, [authMechanisms]) ⇒ <code>Object</code>
Parse HTTP WWW-Authenticate header contents.
**Kind**: static constant of [<code>http-auth-utils</code>](#module_http-auth-utils)
**Kind**: static method of [<code>http-auth-utils</code>](#module_http-auth-utils)
**Returns**: <code>Object</code> - Result of the contents parse.
**Api**: public
| Param | Type | Default | Description |
| --- | --- | --- | --- |
| header | <code>string</code> | | The WWW-Authenticate header contents |
| [authMechanisms] | <code>Array</code> | <code>[BASIC, DIGEST]</code> | Allow providing custom authentication mechanisms. |
**Example**
```js
assert.equal(
parseWWWAuthenticateHeader('Basic realm="test"'), {
type: 'Basic',
data: {
realm: 'test'
}
}
);
```
<a name="module_http-auth-utils.parseAuthorizationHeader"></a>
### http-auth-utils.parseAuthorizationHeader(header, [authMechanisms]) ⇒ <code>Object</code>
Parse HTTP Authorization header contents.
**Kind**: static method of [<code>http-auth-utils</code>](#module_http-auth-utils)
**Returns**: <code>Object</code> - Result of the contents parse.
**Api**: public
| Param | Type | Default | Description |
| --- | --- | --- | --- |
| header | <code>string</code> | | The Authorization header contents |
| [authMechanisms] | <code>Array</code> | <code>[BASIC, DIGEST, BEARER]</code> | Allow custom authentication mechanisms. |
**Example**
```js
assert.equal(
parseAuthorizationHeader('Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ=='), {
type: 'Basic',
data: {
hash: 'QWxhZGRpbjpvcGVuIHNlc2FtZQ=='
}
}
);
```
<a name="module_http-auth-utils..mechanisms"></a>
### http-auth-utils~mechanisms : <code>Array</code>
Natively supported authentication mechanisms.
**Kind**: inner constant of [<code>http-auth-utils</code>](#module_http-auth-utils)
<a name="module_http-auth-utils/mechanisms/basic"></a>
## http-auth-utils/mechanisms/basic
* [http-auth-utils/mechanisms/basic](#module_http-auth-utils/mechanisms/basic)
* [~BASIC](#module_http-auth-utils/mechanisms/basic..BASIC) : <code>Object</code>
* [.type](#module_http-auth-utils/mechanisms/basic..BASIC.type) : <code>String</code>
* [.parseWWWAuthenticateRest(rest)](#module_http-auth-utils/mechanisms/basic..BASIC.parseWWWAuthenticateRest) ⇒ <code>Object</code>
* [.buildWWWAuthenticateRest(data)](#module_http-auth-utils/mechanisms/basic..BASIC.buildWWWAuthenticateRest) ⇒ <code>String</code>
* [.parseAuthorizationRest(rest)](#module_http-auth-utils/mechanisms/basic..BASIC.parseAuthorizationRest) ⇒ <code>Object</code>
* [.buildAuthorizationRest(content)](#module_http-auth-utils/mechanisms/basic..BASIC.buildAuthorizationRest) ⇒ <code>String</code>
* [.computeHash(credentials)](#module_http-auth-utils/mechanisms/basic..BASIC.computeHash) ⇒ <code>String</code>
* [.decodeHash(hash)](#module_http-auth-utils/mechanisms/basic..BASIC.decodeHash) ⇒ <code>Object</code>
<a name="module_http-auth-utils/mechanisms/basic..BASIC"></a>
### http-auth-utils/mechanisms/basic~BASIC : <code>Object</code>
Basic authentication mechanism.
**Kind**: inner constant of [<code>http-auth-utils/mechanisms/basic</code>](#module_http-auth-utils/mechanisms/basic)
**See**: http://tools.ietf.org/html/rfc2617#section-2
* [~BASIC](#module_http-auth-utils/mechanisms/basic..BASIC) : <code>Object</code>
* [.type](#module_http-auth-utils/mechanisms/basic..BASIC.type) : <code>String</code>
* [.parseWWWAuthenticateRest(rest)](#module_http-auth-utils/mechanisms/basic..BASIC.parseWWWAuthenticateRest) ⇒ <code>Object</code>
* [.buildWWWAuthenticateRest(data)](#module_http-auth-utils/mechanisms/basic..BASIC.buildWWWAuthenticateRest) ⇒ <code>String</code>
* [.parseAuthorizationRest(rest)](#module_http-auth-utils/mechanisms/basic..BASIC.parseAuthorizationRest) ⇒ <code>Object</code>
* [.buildAuthorizationRest(content)](#module_http-auth-utils/mechanisms/basic..BASIC.buildAuthorizationRest) ⇒ <code>String</code>
* [.computeHash(credentials)](#module_http-auth-utils/mechanisms/basic..BASIC.computeHash) ⇒ <code>String</code>
* [.decodeHash(hash)](#module_http-auth-utils/mechanisms/basic..BASIC.decodeHash) ⇒ <code>Object</code>
<a name="module_http-auth-utils/mechanisms/basic..BASIC.type"></a>
#### BASIC.type : <code>String</code>
The Basic auth mechanism prefix.
**Kind**: static property of [<code>BASIC</code>](#module_http-auth-utils/mechanisms/basic..BASIC)
<a name="module_http-auth-utils/mechanisms/basic..BASIC.parseWWWAuthenticateRest"></a>
#### BASIC.parseWWWAuthenticateRest(rest) ⇒ <code>Object</code>
Parse the WWW Authenticate header rest.
**Kind**: static method of [<code>BASIC</code>](#module_http-auth-utils/mechanisms/basic..BASIC)
**Returns**: <code>Object</code> - Object representing the result of the parse operation.
**Api**: public
| Param | Type | Description |
| --- | --- | --- |
| rest | <code>String</code> | The header rest (string after the authentication mechanism prefix). |
**Example**
```js
assert.deepEqual(
BASIC.parseWWWAuthenticateRest('realm="perlinpinpin"'), {
realm: 'perlinpinpin'
}
);
```
<a name="module_http-auth-utils/mechanisms/basic..BASIC.buildWWWAuthenticateRest"></a>
#### BASIC.buildWWWAuthenticateRest(data) ⇒ <code>String</code>
Build the WWW Authenticate header rest.
**Kind**: static method of [<code>BASIC</code>](#module_http-auth-utils/mechanisms/basic..BASIC)
**Returns**: <code>String</code> - The built rest.
**Api**: public
| Param | Type | Description |
| --- | --- | --- |
| data | <code>Object</code> | The content from wich to build the rest. |
**Example**
```js
assert.equal(
BASIC.buildWWWAuthenticateRest({
realm: 'perlinpinpin'
}),
'realm="perlinpinpin"'
);
```
<a name="module_http-auth-utils/mechanisms/basic..BASIC.parseAuthorizationRest"></a>
#### BASIC.parseAuthorizationRest(rest) ⇒ <code>Object</code>
Parse the Authorization header rest.
**Kind**: static method of [<code>BASIC</code>](#module_http-auth-utils/mechanisms/basic..BASIC)
**Returns**: <code>Object</code> - Object representing the result of the parse operation {hash}.
**Api**: public
| Param | Type | Description |
| --- | --- | --- |
| rest | <code>String</code> | The header rest (string after the authentication mechanism prefix).) |
**Example**
```js
assert.deepEqual(
BASIC.parseAuthorizationRest('QWxpIEJhYmE6b3BlbiBzZXNhbWU='), {
hash: 'QWxpIEJhYmE6b3BlbiBzZXNhbWU=',
username: 'Ali Baba',
password: 'open sesame'
}
);
```
<a name="module_http-auth-utils/mechanisms/basic..BASIC.buildAuthorizationRest"></a>
#### BASIC.buildAuthorizationRest(content) ⇒ <code>String</code>
Build the Authorization header rest.
**Kind**: static method of [<code>BASIC</code>](#module_http-auth-utils/mechanisms/basic..BASIC)
**Returns**: <code>String</code> - The rest built.
**Api**: public
| Param | Type | Description |
| --- | --- | --- |
| content | <code>Object</code> | The content from wich to build the rest. |
**Example**
```js
assert.equal(
BASIC.buildAuthorizationRest({
hash: 'QWxpIEJhYmE6b3BlbiBzZXNhbWU='
}),
'QWxpIEJhYmE6b3BlbiBzZXNhbWU='
);
```
<a name="module_http-auth-utils/mechanisms/basic..BASIC.computeHash"></a>
#### BASIC.computeHash(credentials) ⇒ <code>String</code>
Compute the Basic authentication hash from the given credentials.
**Kind**: static method of [<code>BASIC</code>](#module_http-auth-utils/mechanisms/basic..BASIC)
**Returns**: <code>String</code> - The hash representing the credentials.
**Api**: public
| Param | Type | Description |
| --- | --- | --- |
| credentials | <code>Object</code> | The credentials to encode {username, password}. |
**Example**
```js
assert.equal(
BASIC.computeHash({
username: 'Ali Baba',
password: 'open sesame'
}),
'QWxpIEJhYmE6b3BlbiBzZXNhbWU='
);
```
<a name="module_http-auth-utils/mechanisms/basic..BASIC.decodeHash"></a>
#### BASIC.decodeHash(hash) ⇒ <code>Object</code>
Decode the Basic hash and return the corresponding credentials.
**Kind**: static method of [<code>BASIC</code>](#module_http-auth-utils/mechanisms/basic..BASIC)
**Returns**: <code>Object</code> - Object representing the credentials {username, password}.
**Api**: public
| Param | Type | Description |
| --- | --- | --- |
| hash | <code>String</code> | The hash. |
**Example**
```js
assert.deepEqual(
BASIC.decodeHash('QWxpIEJhYmE6b3BlbiBzZXNhbWU='), {
username: 'Ali Baba',
password: 'open sesame'
}
);
```
<a name="module_http-auth-utils/mechanisms/bearer"></a>
## http-auth-utils/mechanisms/bearer
* [http-auth-utils/mechanisms/bearer](#module_http-auth-utils/mechanisms/bearer)
* [~BEARER](#module_http-auth-utils/mechanisms/bearer..BEARER) : <code>Object</code>
* [.type](#module_http-auth-utils/mechanisms/bearer..BEARER.type) : <code>String</code>
* [.parseWWWAuthenticateRest(rest)](#module_http-auth-utils/mechanisms/bearer..BEARER.parseWWWAuthenticateRest) ⇒ <code>Object</code>
* [.buildWWWAuthenticateRest(data)](#module_http-auth-utils/mechanisms/bearer..BEARER.buildWWWAuthenticateRest) ⇒ <code>String</code>
* [.parseAuthorizationRest(rest)](#module_http-auth-utils/mechanisms/bearer..BEARER.parseAuthorizationRest) ⇒ <code>Object</code>
* [.buildAuthorizationRest(content)](#module_http-auth-utils/mechanisms/bearer..BEARER.buildAuthorizationRest) ⇒ <code>String</code>
<a name="module_http-auth-utils/mechanisms/bearer..BEARER"></a>
### http-auth-utils/mechanisms/bearer~BEARER : <code>Object</code>
Bearer authentication mechanism.
**Kind**: inner constant of [<code>http-auth-utils/mechanisms/bearer</code>](#module_http-auth-utils/mechanisms/bearer)
**See**: https://tools.ietf.org/html/rfc6750#section-3
* [~BEARER](#module_http-auth-utils/mechanisms/bearer..BEARER) : <code>Object</code>
* [.type](#module_http-auth-utils/mechanisms/bearer..BEARER.type) : <code>String</code>
* [.parseWWWAuthenticateRest(rest)](#module_http-auth-utils/mechanisms/bearer..BEARER.parseWWWAuthenticateRest) ⇒ <code>Object</code>
* [.buildWWWAuthenticateRest(data)](#module_http-auth-utils/mechanisms/bearer..BEARER.buildWWWAuthenticateRest) ⇒ <code>String</code>
* [.parseAuthorizationRest(rest)](#module_http-auth-utils/mechanisms/bearer..BEARER.parseAuthorizationRest) ⇒ <code>Object</code>
* [.buildAuthorizationRest(content)](#module_http-auth-utils/mechanisms/bearer..BEARER.buildAuthorizationRest) ⇒ <code>String</code>
<a name="module_http-auth-utils/mechanisms/bearer..BEARER.type"></a>
#### BEARER.type : <code>String</code>
The Digest auth mechanism prefix.
**Kind**: static property of [<code>BEARER</code>](#module_http-auth-utils/mechanisms/bearer..BEARER)
<a name="module_http-auth-utils/mechanisms/bearer..BEARER.parseWWWAuthenticateRest"></a>
#### BEARER.parseWWWAuthenticateRest(rest) ⇒ <code>Object</code>
Parse the WWW Authenticate header rest.
**Kind**: static method of [<code>BEARER</code>](#module_http-auth-utils/mechanisms/bearer..BEARER)
**Returns**: <code>Object</code> - Object representing the result of the parse operation.
**Api**: public
| Param | Type | Description |
| --- | --- | --- |
| rest | <code>String</code> | The header rest (string after the authentication mechanism prefix). |
**Example**
```js
assert.deepEqual(
BEARER.parseWWWAuthenticateRest(
'realm="testrealm@host.com", ' +
'scope="openid profile email"'
), {
realm: 'testrealm@host.com',
scope: 'openid profile email',
}
);
```
<a name="module_http-auth-utils/mechanisms/bearer..BEARER.buildWWWAuthenticateRest"></a>
#### BEARER.buildWWWAuthenticateRest(data) ⇒ <code>String</code>
Build the WWW Authenticate header rest.
**Kind**: static method of [<code>BEARER</code>](#module_http-auth-utils/mechanisms/bearer..BEARER)
**Returns**: <code>String</code> - The built rest.
**Api**: public
| Param | Type | Description |
| --- | --- | --- |
| data | <code>Object</code> | The content from wich to build the rest. |
**Example**
```js
assert.equal(
BEARER.buildWWWAuthenticateRest({
realm: 'testrealm@host.com',
error: 'invalid_request',
error_description: 'The access token expired',
}),
'realm="testrealm@host.com", ' +
'error="invalid_request", ' +
'error_description="The access token expired"'
);
```
<a name="module_http-auth-utils/mechanisms/bearer..BEARER.parseAuthorizationRest"></a>
#### BEARER.parseAuthorizationRest(rest) ⇒ <code>Object</code>
Parse the Authorization header rest.
**Kind**: static method of [<code>BEARER</code>](#module_http-auth-utils/mechanisms/bearer..BEARER)
**Returns**: <code>Object</code> - Object representing the result of the parse operation {hash}.
**Api**: public
| Param | Type | Description |
| --- | --- | --- |
| rest | <code>String</code> | The header rest (string after the authentication mechanism prefix).) |
**Example**
```js
assert.deepEqual(
BEARER.parseAuthorizationRest('mF_9.B5f-4.1JqM'), {
hash: 'mF_9.B5f-4.1JqM',
}
);
```
<a name="module_http-auth-utils/mechanisms/bearer..BEARER.buildAuthorizationRest"></a>
#### BEARER.buildAuthorizationRest(content) ⇒ <code>String</code>
Build the Authorization header rest.
**Kind**: static method of [<code>BEARER</code>](#module_http-auth-utils/mechanisms/bearer..BEARER)
**Returns**: <code>String</code> - The rest built.
**Api**: public
| Param | Type | Description |
| --- | --- | --- |
| content | <code>Object</code> | The content from wich to build the rest. |
**Example**
```js
assert.equal(
BEARER.buildAuthorizationRest({
hash: 'mF_9.B5f-4.1JqM'
}),
'mF_9.B5f-4.1JqM=='
);
```
<a name="module_http-auth-utils/mechanisms/digest"></a>
## http-auth-utils/mechanisms/digest
* [http-auth-utils/mechanisms/digest](#module_http-auth-utils/mechanisms/digest)
* [~DIGEST](#module_http-auth-utils/mechanisms/digest..DIGEST) : <code>Object</code>
* [.type](#module_http-auth-utils/mechanisms/digest..DIGEST.type) : <code>String</code>
* [.parseWWWAuthenticateRest(rest)](#module_http-auth-utils/mechanisms/digest..DIGEST.parseWWWAuthenticateRest) ⇒ <code>Object</code>
* [.buildWWWAuthenticateRest(data)](#module_http-auth-utils/mechanisms/digest..DIGEST.buildWWWAuthenticateRest) ⇒ <code>String</code>
* [.parseAuthorizationRest(rest)](#module_http-auth-utils/mechanisms/digest..DIGEST.parseAuthorizationRest) ⇒ <code>Object</code>
* [.buildAuthorizationRest(data)](#module_http-auth-utils/mechanisms/digest..DIGEST.buildAuthorizationRest) ⇒ <code>String</code>
* [.computeHash(data)](#module_http-auth-utils/mechanisms/digest..DIGEST.computeHash) ⇒ <code>String</code>
<a name="module_http-auth-utils/mechanisms/digest..DIGEST"></a>
### http-auth-utils/mechanisms/digest~DIGEST : <code>Object</code>
Digest authentication mechanism.
**Kind**: inner constant of [<code>http-auth-utils/mechanisms/digest</code>](#module_http-auth-utils/mechanisms/digest)
**See**
- http://tools.ietf.org/html/rfc2617#section-3
- http://tools.ietf.org/html/rfc2069#section-2
* [~DIGEST](#module_http-auth-utils/mechanisms/digest..DIGEST) : <code>Object</code>
* [.type](#module_http-auth-utils/mechanisms/digest..DIGEST.type) : <code>String</code>
* [.parseWWWAuthenticateRest(rest)](#module_http-auth-utils/mechanisms/digest..DIGEST.parseWWWAuthenticateRest) ⇒ <code>Object</code>
* [.buildWWWAuthenticateRest(data)](#module_http-auth-utils/mechanisms/digest..DIGEST.buildWWWAuthenticateRest) ⇒ <code>String</code>
* [.parseAuthorizationRest(rest)](#module_http-auth-utils/mechanisms/digest..DIGEST.parseAuthorizationRest) ⇒ <code>Object</code>
* [.buildAuthorizationRest(data)](#module_http-auth-utils/mechanisms/digest..DIGEST.buildAuthorizationRest) ⇒ <code>String</code>
* [.computeHash(data)](#module_http-auth-utils/mechanisms/digest..DIGEST.computeHash) ⇒ <code>String</code>
<a name="module_http-auth-utils/mechanisms/digest..DIGEST.type"></a>
#### DIGEST.type : <code>String</code>
The Digest auth mechanism prefix.
**Kind**: static property of [<code>DIGEST</code>](#module_http-auth-utils/mechanisms/digest..DIGEST)
<a name="module_http-auth-utils/mechanisms/digest..DIGEST.parseWWWAuthenticateRest"></a>
#### DIGEST.parseWWWAuthenticateRest(rest) ⇒ <code>Object</code>
Parse the WWW Authenticate header rest.
**Kind**: static method of [<code>DIGEST</code>](#module_http-auth-utils/mechanisms/digest..DIGEST)
**Returns**: <code>Object</code> - Object representing the result of the parse operation.
**Api**: public
| Param | Type | Description |
| --- | --- | --- |
| rest | <code>String</code> | The header rest (string after the authentication mechanism prefix). |
**Example**
```js
assert.deepEqual(
DIGEST.parseWWWAuthenticateRest(
'realm="testrealm@host.com", ' +
'qop="auth, auth-int", ' +
'nonce="dcd98b7102dd2f0e8b11d0f600bfb0c093", ' +
'opaque="5ccc069c403ebaf9f0171e9517f40e41"'
), {
realm: 'testrealm@host.com',
qop: 'auth, auth-int',
nonce: 'dcd98b7102dd2f0e8b11d0f600bfb0c093',
opaque: '5ccc069c403ebaf9f0171e9517f40e41'
}
);
```
<a name="module_http-auth-utils/mechanisms/digest..DIGEST.buildWWWAuthenticateRest"></a>
#### DIGEST.buildWWWAuthenticateRest(data) ⇒ <code>String</code>
Build the WWW Authenticate header rest.
**Kind**: static method of [<code>DIGEST</code>](#module_http-auth-utils/mechanisms/digest..DIGEST)
**Returns**: <code>String</code> - The built rest.
**Api**: public
| Param | Type | Description |
| --- | --- | --- |
| data | <code>Object</code> | The content from wich to build the rest. |
**Example**
```js
assert.equal(
DIGEST.buildWWWAuthenticateRest({
realm: 'testrealm@host.com',
qop: 'auth, auth-int',
nonce: 'dcd98b7102dd2f0e8b11d0f600bfb0c093',
opaque: '5ccc069c403ebaf9f0171e9517f40e41'
}),
'realm="testrealm@host.com", ' +
'qop="auth, auth-int", ' +
'nonce="dcd98b7102dd2f0e8b11d0f600bfb0c093", ' +
'opaque="5ccc069c403ebaf9f0171e9517f40e41"'
);
```
<a name="module_http-auth-utils/mechanisms/digest..DIGEST.parseAuthorizationRest"></a>
#### DIGEST.parseAuthorizationRest(rest) ⇒ <code>Object</code>
Parse the Authorization header rest.
**Kind**: static method of [<code>DIGEST</code>](#module_http-auth-utils/mechanisms/digest..DIGEST)
**Returns**: <code>Object</code> - Object representing the result of the parse operation {hash}.
**Api**: public
| Param | Type | Description |
| --- | --- | --- |
| rest | <code>String</code> | The header rest (string after the authentication mechanism prefix).) |
**Example**
```js
assert.deepEqual(
DIGEST.parseAuthorizationRest(
'username="Mufasa",' +
'realm="testrealm@host.com",' +
'nonce="dcd98b7102dd2f0e8b11d0f600bfb0c093",' +
'uri="/dir/index.html",' +
'qop="auth",' +
'nc="00000001",' +
'cnonce="0a4f113b",' +
'response="6629fae49393a05397450978507c4ef1",' +
'opaque="5ccc069c403ebaf9f0171e9517f40e41"'
), {
username: "Mufasa",
realm: 'testrealm@host.com',
nonce: "dcd98b7102dd2f0e8b11d0f600bfb0c093",
uri: "/dir/index.html",
qop: 'auth',
nc: '00000001',
cnonce: "0a4f113b",
response: "6629fae49393a05397450978507c4ef1",
opaque: "5ccc069c403ebaf9f0171e9517f40e41"
}
);
```
<a name="module_http-auth-utils/mechanisms/digest..DIGEST.buildAuthorizationRest"></a>
#### DIGEST.buildAuthorizationRest(data) ⇒ <code>String</code>
Build the Authorization header rest.
**Kind**: static method of [<code>DIGEST</code>](#module_http-auth-utils/mechanisms/digest..DIGEST)
**Returns**: <code>String</code> - The rest built.
**Api**: public
| Param | Type | Description |
| --- | --- | --- |
| data | <code>Object</code> | The content from wich to build the rest. |
**Example**
```js
assert.equal(
DIGEST.buildAuthorizationRest({
username: "Mufasa",
realm: 'testrealm@host.com',
nonce: "dcd98b7102dd2f0e8b11d0f600bfb0c093",
uri: "/dir/index.html",
qop: 'auth',
nc: '00000001',
cnonce: "0a4f113b",
response: "6629fae49393a05397450978507c4ef1",
opaque: "5ccc069c403ebaf9f0171e9517f40e41"
}),
'username="Mufasa", ' +
'realm="testrealm@host.com", ' +
'nonce="dcd98b7102dd2f0e8b11d0f600bfb0c093", ' +
'uri="/dir/index.html", ' +
'response="6629fae49393a05397450978507c4ef1", ' +
'cnonce="0a4f113b", ' +
'opaque="5ccc069c403ebaf9f0171e9517f40e41", ' +
'qop="auth", ' +
'nc="00000001"'
);
```
<a name="module_http-auth-utils/mechanisms/digest..DIGEST.computeHash"></a>
#### DIGEST.computeHash(data) ⇒ <code>String</code>
Compute the Digest authentication hash from the given credentials.
**Kind**: static method of [<code>DIGEST</code>](#module_http-auth-utils/mechanisms/digest..DIGEST)
**Returns**: <code>String</code> - The hash representing the credentials.
**Api**: public
| Param | Type | Description |
| --- | --- | --- |
| data | <code>Object</code> | The credentials to encode and other encoding details. |
**Example**
```js
assert.equal(
DIGEST.computeHash({
username: 'Mufasa',
realm: 'testrealm@host.com',
password: 'Circle Of Life',
method: 'GET',
uri: '/dir/index.html',
nonce: 'dcd98b7102dd2f0e8b11d0f600bfb0c093',
nc: '00000001',
cnonce: '0a4f113b',
qop: 'auth',
algorithm: 'md5'
}),
'6629fae49393a05397450978507c4ef1'
);
```
[//]: # (::contents:end)
# API
## Modules
<dl>
<dt><a href="#module_http-auth-utils">http-auth-utils</a></dt>
<dd></dd>
<dt><a href="#module_http-auth-utils/mechanisms/basic">http-auth-utils/mechanisms/basic</a></dt>
<dd></dd>
<dt><a href="#module_http-auth-utils/mechanisms/bearer">http-auth-utils/mechanisms/bearer</a></dt>
<dd></dd>
<dt><a href="#module_http-auth-utils/mechanisms/digest">http-auth-utils/mechanisms/digest</a></dt>
<dd></dd>
</dl>
<a name="module_http-auth-utils"></a>
## http-auth-utils
* [http-auth-utils](#module_http-auth-utils)
* _static_
* [.parseWWWAuthenticateHeader(header, [authMechanisms])](#module_http-auth-utils.parseWWWAuthenticateHeader) ⇒ <code>Object</code>
* [.parseAuthorizationHeader(header, [authMechanisms])](#module_http-auth-utils.parseAuthorizationHeader) ⇒ <code>Object</code>
* _inner_
* [~mechanisms](#module_http-auth-utils..mechanisms) : <code>Array</code>
<a name="module_http-auth-utils.parseWWWAuthenticateHeader"></a>
### http-auth-utils.parseWWWAuthenticateHeader(header, [authMecanisms]) ⇒ <code>Object</code>
### http-auth-utils.parseWWWAuthenticateHeader(header, [authMechanisms]) ⇒ <code>Object</code>
Parse HTTP WWW-Authenticate header contents.

@@ -67,3 +652,3 @@

| header | <code>string</code> | | The WWW-Authenticate header contents |
| [authMecanisms] | <code>Array</code> | <code>[BASIC, DIGEST]</code> | Allow providing custom authentication mecanisms. |
| [authMechanisms] | <code>Array</code> | <code>[BASIC, DIGEST]</code> | Allow providing custom authentication mechanisms. |

@@ -83,3 +668,3 @@ **Example**

### http-auth-utils.parseAuthorizationHeader(header, [authMecanisms]) ⇒ <code>Object</code>
### http-auth-utils.parseAuthorizationHeader(header, [authMechanisms]) ⇒ <code>Object</code>
Parse HTTP Authorization header contents.

@@ -94,3 +679,3 @@

| header | <code>string</code> | | The Authorization header contents |
| [authMecanisms] | <code>Array</code> | <code>[BASIC, DIGEST, BEARER]</code> | Allow custom authentication mecanisms. |
| [authMechanisms] | <code>Array</code> | <code>[BASIC, DIGEST, BEARER]</code> | Allow custom authentication mechanisms. |

@@ -108,40 +693,46 @@ **Example**

```
<a name="module_http-auth-utils/mecanisms/basic"></a>
<a name="module_http-auth-utils..mechanisms"></a>
## http-auth-utils/mecanisms/basic
### http-auth-utils~mechanisms : <code>Array</code>
Natively supported authentication mechanisms.
* [http-auth-utils/mecanisms/basic](#module_http-auth-utils/mecanisms/basic)
* [~BASIC](#module_http-auth-utils/mecanisms/basic..BASIC) : <code>Object</code>
* [.type](#module_http-auth-utils/mecanisms/basic..BASIC.type) : <code>String</code>
* [.parseWWWAuthenticateRest(rest)](#module_http-auth-utils/mecanisms/basic..BASIC.parseWWWAuthenticateRest) ⇒ <code>Object</code>
* [.buildWWWAuthenticateRest(data)](#module_http-auth-utils/mecanisms/basic..BASIC.buildWWWAuthenticateRest) ⇒ <code>String</code>
* [.parseAuthorizationRest(rest)](#module_http-auth-utils/mecanisms/basic..BASIC.parseAuthorizationRest) ⇒ <code>Object</code>
* [.buildAuthorizationRest(content)](#module_http-auth-utils/mecanisms/basic..BASIC.buildAuthorizationRest) ⇒ <code>String</code>
* [.computeHash(credentials)](#module_http-auth-utils/mecanisms/basic..BASIC.computeHash) ⇒ <code>String</code>
* [.decodeHash(hash)](#module_http-auth-utils/mecanisms/basic..BASIC.decodeHash) ⇒ <code>Object</code>
**Kind**: inner constant of [<code>http-auth-utils</code>](#module_http-auth-utils)
<a name="module_http-auth-utils/mechanisms/basic"></a>
<a name="module_http-auth-utils/mecanisms/basic..BASIC"></a>
## http-auth-utils/mechanisms/basic
### http-auth-utils/mecanisms/basic~BASIC : <code>Object</code>
Basic authentication mecanism.
* [http-auth-utils/mechanisms/basic](#module_http-auth-utils/mechanisms/basic)
* [~BASIC](#module_http-auth-utils/mechanisms/basic..BASIC) : <code>Object</code>
* [.type](#module_http-auth-utils/mechanisms/basic..BASIC.type) : <code>String</code>
* [.parseWWWAuthenticateRest(rest)](#module_http-auth-utils/mechanisms/basic..BASIC.parseWWWAuthenticateRest) ⇒ <code>Object</code>
* [.buildWWWAuthenticateRest(data)](#module_http-auth-utils/mechanisms/basic..BASIC.buildWWWAuthenticateRest) ⇒ <code>String</code>
* [.parseAuthorizationRest(rest)](#module_http-auth-utils/mechanisms/basic..BASIC.parseAuthorizationRest) ⇒ <code>Object</code>
* [.buildAuthorizationRest(content)](#module_http-auth-utils/mechanisms/basic..BASIC.buildAuthorizationRest) ⇒ <code>String</code>
* [.computeHash(credentials)](#module_http-auth-utils/mechanisms/basic..BASIC.computeHash) ⇒ <code>String</code>
* [.decodeHash(hash)](#module_http-auth-utils/mechanisms/basic..BASIC.decodeHash) ⇒ <code>Object</code>
**Kind**: inner constant of [<code>http-auth-utils/mecanisms/basic</code>](#module_http-auth-utils/mecanisms/basic)
<a name="module_http-auth-utils/mechanisms/basic..BASIC"></a>
### http-auth-utils/mechanisms/basic~BASIC : <code>Object</code>
Basic authentication mechanism.
**Kind**: inner constant of [<code>http-auth-utils/mechanisms/basic</code>](#module_http-auth-utils/mechanisms/basic)
**See**: http://tools.ietf.org/html/rfc2617#section-2
* [~BASIC](#module_http-auth-utils/mecanisms/basic..BASIC) : <code>Object</code>
* [.type](#module_http-auth-utils/mecanisms/basic..BASIC.type) : <code>String</code>
* [.parseWWWAuthenticateRest(rest)](#module_http-auth-utils/mecanisms/basic..BASIC.parseWWWAuthenticateRest) ⇒ <code>Object</code>
* [.buildWWWAuthenticateRest(data)](#module_http-auth-utils/mecanisms/basic..BASIC.buildWWWAuthenticateRest) ⇒ <code>String</code>
* [.parseAuthorizationRest(rest)](#module_http-auth-utils/mecanisms/basic..BASIC.parseAuthorizationRest) ⇒ <code>Object</code>
* [.buildAuthorizationRest(content)](#module_http-auth-utils/mecanisms/basic..BASIC.buildAuthorizationRest) ⇒ <code>String</code>
* [.computeHash(credentials)](#module_http-auth-utils/mecanisms/basic..BASIC.computeHash) ⇒ <code>String</code>
* [.decodeHash(hash)](#module_http-auth-utils/mecanisms/basic..BASIC.decodeHash) ⇒ <code>Object</code>
* [~BASIC](#module_http-auth-utils/mechanisms/basic..BASIC) : <code>Object</code>
* [.type](#module_http-auth-utils/mechanisms/basic..BASIC.type) : <code>String</code>
* [.parseWWWAuthenticateRest(rest)](#module_http-auth-utils/mechanisms/basic..BASIC.parseWWWAuthenticateRest) ⇒ <code>Object</code>
* [.buildWWWAuthenticateRest(data)](#module_http-auth-utils/mechanisms/basic..BASIC.buildWWWAuthenticateRest) ⇒ <code>String</code>
* [.parseAuthorizationRest(rest)](#module_http-auth-utils/mechanisms/basic..BASIC.parseAuthorizationRest) ⇒ <code>Object</code>
* [.buildAuthorizationRest(content)](#module_http-auth-utils/mechanisms/basic..BASIC.buildAuthorizationRest) ⇒ <code>String</code>
* [.computeHash(credentials)](#module_http-auth-utils/mechanisms/basic..BASIC.computeHash) ⇒ <code>String</code>
* [.decodeHash(hash)](#module_http-auth-utils/mechanisms/basic..BASIC.decodeHash) ⇒ <code>Object</code>
<a name="module_http-auth-utils/mecanisms/basic..BASIC.type"></a>
<a name="module_http-auth-utils/mechanisms/basic..BASIC.type"></a>
#### BASIC.type : <code>String</code>
The Basic auth mecanism prefix.
The Basic auth mechanism prefix.
**Kind**: static property of [<code>BASIC</code>](#module_http-auth-utils/mecanisms/basic..BASIC)
<a name="module_http-auth-utils/mecanisms/basic..BASIC.parseWWWAuthenticateRest"></a>
**Kind**: static property of [<code>BASIC</code>](#module_http-auth-utils/mechanisms/basic..BASIC)
<a name="module_http-auth-utils/mechanisms/basic..BASIC.parseWWWAuthenticateRest"></a>

@@ -151,3 +742,3 @@ #### BASIC.parseWWWAuthenticateRest(rest) ⇒ <code>Object</code>

**Kind**: static method of [<code>BASIC</code>](#module_http-auth-utils/mecanisms/basic..BASIC)
**Kind**: static method of [<code>BASIC</code>](#module_http-auth-utils/mechanisms/basic..BASIC)
**Returns**: <code>Object</code> - Object representing the result of the parse operation.

@@ -158,3 +749,3 @@ **Api**: public

| --- | --- | --- |
| rest | <code>String</code> | The header rest (string after the authentication mecanism prefix). |
| rest | <code>String</code> | The header rest (string after the authentication mechanism prefix). |

@@ -169,3 +760,3 @@ **Example**

```
<a name="module_http-auth-utils/mecanisms/basic..BASIC.buildWWWAuthenticateRest"></a>
<a name="module_http-auth-utils/mechanisms/basic..BASIC.buildWWWAuthenticateRest"></a>

@@ -175,3 +766,3 @@ #### BASIC.buildWWWAuthenticateRest(data) ⇒ <code>String</code>

**Kind**: static method of [<code>BASIC</code>](#module_http-auth-utils/mecanisms/basic..BASIC)
**Kind**: static method of [<code>BASIC</code>](#module_http-auth-utils/mechanisms/basic..BASIC)
**Returns**: <code>String</code> - The built rest.

@@ -193,3 +784,3 @@ **Api**: public

```
<a name="module_http-auth-utils/mecanisms/basic..BASIC.parseAuthorizationRest"></a>
<a name="module_http-auth-utils/mechanisms/basic..BASIC.parseAuthorizationRest"></a>

@@ -199,3 +790,3 @@ #### BASIC.parseAuthorizationRest(rest) ⇒ <code>Object</code>

**Kind**: static method of [<code>BASIC</code>](#module_http-auth-utils/mecanisms/basic..BASIC)
**Kind**: static method of [<code>BASIC</code>](#module_http-auth-utils/mechanisms/basic..BASIC)
**Returns**: <code>Object</code> - Object representing the result of the parse operation {hash}.

@@ -206,3 +797,3 @@ **Api**: public

| --- | --- | --- |
| rest | <code>String</code> | The header rest (string after the authentication mecanism prefix).) |
| rest | <code>String</code> | The header rest (string after the authentication mechanism prefix).) |

@@ -219,3 +810,3 @@ **Example**

```
<a name="module_http-auth-utils/mecanisms/basic..BASIC.buildAuthorizationRest"></a>
<a name="module_http-auth-utils/mechanisms/basic..BASIC.buildAuthorizationRest"></a>

@@ -225,3 +816,3 @@ #### BASIC.buildAuthorizationRest(content) ⇒ <code>String</code>

**Kind**: static method of [<code>BASIC</code>](#module_http-auth-utils/mecanisms/basic..BASIC)
**Kind**: static method of [<code>BASIC</code>](#module_http-auth-utils/mechanisms/basic..BASIC)
**Returns**: <code>String</code> - The rest built.

@@ -243,3 +834,3 @@ **Api**: public

```
<a name="module_http-auth-utils/mecanisms/basic..BASIC.computeHash"></a>
<a name="module_http-auth-utils/mechanisms/basic..BASIC.computeHash"></a>

@@ -249,3 +840,3 @@ #### BASIC.computeHash(credentials) ⇒ <code>String</code>

**Kind**: static method of [<code>BASIC</code>](#module_http-auth-utils/mecanisms/basic..BASIC)
**Kind**: static method of [<code>BASIC</code>](#module_http-auth-utils/mechanisms/basic..BASIC)
**Returns**: <code>String</code> - The hash representing the credentials.

@@ -268,3 +859,3 @@ **Api**: public

```
<a name="module_http-auth-utils/mecanisms/basic..BASIC.decodeHash"></a>
<a name="module_http-auth-utils/mechanisms/basic..BASIC.decodeHash"></a>

@@ -274,3 +865,3 @@ #### BASIC.decodeHash(hash) ⇒ <code>Object</code>

**Kind**: static method of [<code>BASIC</code>](#module_http-auth-utils/mecanisms/basic..BASIC)
**Kind**: static method of [<code>BASIC</code>](#module_http-auth-utils/mechanisms/basic..BASIC)
**Returns**: <code>Object</code> - Object representing the credentials {username, password}.

@@ -292,36 +883,36 @@ **Api**: public

```
<a name="module_http-auth-utils/mecanisms/bearer"></a>
<a name="module_http-auth-utils/mechanisms/bearer"></a>
## http-auth-utils/mecanisms/bearer
## http-auth-utils/mechanisms/bearer
* [http-auth-utils/mecanisms/bearer](#module_http-auth-utils/mecanisms/bearer)
* [~BEARER](#module_http-auth-utils/mecanisms/bearer..BEARER) : <code>Object</code>
* [.type](#module_http-auth-utils/mecanisms/bearer..BEARER.type) : <code>String</code>
* [.parseWWWAuthenticateRest(rest)](#module_http-auth-utils/mecanisms/bearer..BEARER.parseWWWAuthenticateRest) ⇒ <code>Object</code>
* [.buildWWWAuthenticateRest(data)](#module_http-auth-utils/mecanisms/bearer..BEARER.buildWWWAuthenticateRest) ⇒ <code>String</code>
* [.parseAuthorizationRest(rest)](#module_http-auth-utils/mecanisms/bearer..BEARER.parseAuthorizationRest) ⇒ <code>Object</code>
* [.buildAuthorizationRest(content)](#module_http-auth-utils/mecanisms/bearer..BEARER.buildAuthorizationRest) ⇒ <code>String</code>
* [http-auth-utils/mechanisms/bearer](#module_http-auth-utils/mechanisms/bearer)
* [~BEARER](#module_http-auth-utils/mechanisms/bearer..BEARER) : <code>Object</code>
* [.type](#module_http-auth-utils/mechanisms/bearer..BEARER.type) : <code>String</code>
* [.parseWWWAuthenticateRest(rest)](#module_http-auth-utils/mechanisms/bearer..BEARER.parseWWWAuthenticateRest) ⇒ <code>Object</code>
* [.buildWWWAuthenticateRest(data)](#module_http-auth-utils/mechanisms/bearer..BEARER.buildWWWAuthenticateRest) ⇒ <code>String</code>
* [.parseAuthorizationRest(rest)](#module_http-auth-utils/mechanisms/bearer..BEARER.parseAuthorizationRest) ⇒ <code>Object</code>
* [.buildAuthorizationRest(content)](#module_http-auth-utils/mechanisms/bearer..BEARER.buildAuthorizationRest) ⇒ <code>String</code>
<a name="module_http-auth-utils/mecanisms/bearer..BEARER"></a>
<a name="module_http-auth-utils/mechanisms/bearer..BEARER"></a>
### http-auth-utils/mecanisms/bearer~BEARER : <code>Object</code>
Bearer authentication mecanism.
### http-auth-utils/mechanisms/bearer~BEARER : <code>Object</code>
Bearer authentication mechanism.
**Kind**: inner constant of [<code>http-auth-utils/mecanisms/bearer</code>](#module_http-auth-utils/mecanisms/bearer)
**Kind**: inner constant of [<code>http-auth-utils/mechanisms/bearer</code>](#module_http-auth-utils/mechanisms/bearer)
**See**: https://tools.ietf.org/html/rfc6750#section-3
* [~BEARER](#module_http-auth-utils/mecanisms/bearer..BEARER) : <code>Object</code>
* [.type](#module_http-auth-utils/mecanisms/bearer..BEARER.type) : <code>String</code>
* [.parseWWWAuthenticateRest(rest)](#module_http-auth-utils/mecanisms/bearer..BEARER.parseWWWAuthenticateRest) ⇒ <code>Object</code>
* [.buildWWWAuthenticateRest(data)](#module_http-auth-utils/mecanisms/bearer..BEARER.buildWWWAuthenticateRest) ⇒ <code>String</code>
* [.parseAuthorizationRest(rest)](#module_http-auth-utils/mecanisms/bearer..BEARER.parseAuthorizationRest) ⇒ <code>Object</code>
* [.buildAuthorizationRest(content)](#module_http-auth-utils/mecanisms/bearer..BEARER.buildAuthorizationRest) ⇒ <code>String</code>
* [~BEARER](#module_http-auth-utils/mechanisms/bearer..BEARER) : <code>Object</code>
* [.type](#module_http-auth-utils/mechanisms/bearer..BEARER.type) : <code>String</code>
* [.parseWWWAuthenticateRest(rest)](#module_http-auth-utils/mechanisms/bearer..BEARER.parseWWWAuthenticateRest) ⇒ <code>Object</code>
* [.buildWWWAuthenticateRest(data)](#module_http-auth-utils/mechanisms/bearer..BEARER.buildWWWAuthenticateRest) ⇒ <code>String</code>
* [.parseAuthorizationRest(rest)](#module_http-auth-utils/mechanisms/bearer..BEARER.parseAuthorizationRest) ⇒ <code>Object</code>
* [.buildAuthorizationRest(content)](#module_http-auth-utils/mechanisms/bearer..BEARER.buildAuthorizationRest) ⇒ <code>String</code>
<a name="module_http-auth-utils/mecanisms/bearer..BEARER.type"></a>
<a name="module_http-auth-utils/mechanisms/bearer..BEARER.type"></a>
#### BEARER.type : <code>String</code>
The Digest auth mecanism prefix.
The Digest auth mechanism prefix.
**Kind**: static property of [<code>BEARER</code>](#module_http-auth-utils/mecanisms/bearer..BEARER)
<a name="module_http-auth-utils/mecanisms/bearer..BEARER.parseWWWAuthenticateRest"></a>
**Kind**: static property of [<code>BEARER</code>](#module_http-auth-utils/mechanisms/bearer..BEARER)
<a name="module_http-auth-utils/mechanisms/bearer..BEARER.parseWWWAuthenticateRest"></a>

@@ -331,3 +922,3 @@ #### BEARER.parseWWWAuthenticateRest(rest) ⇒ <code>Object</code>

**Kind**: static method of [<code>BEARER</code>](#module_http-auth-utils/mecanisms/bearer..BEARER)
**Kind**: static method of [<code>BEARER</code>](#module_http-auth-utils/mechanisms/bearer..BEARER)
**Returns**: <code>Object</code> - Object representing the result of the parse operation.

@@ -338,3 +929,3 @@ **Api**: public

| --- | --- | --- |
| rest | <code>String</code> | The header rest (string after the authentication mecanism prefix). |
| rest | <code>String</code> | The header rest (string after the authentication mechanism prefix). |

@@ -353,3 +944,3 @@ **Example**

```
<a name="module_http-auth-utils/mecanisms/bearer..BEARER.buildWWWAuthenticateRest"></a>
<a name="module_http-auth-utils/mechanisms/bearer..BEARER.buildWWWAuthenticateRest"></a>

@@ -359,3 +950,3 @@ #### BEARER.buildWWWAuthenticateRest(data) ⇒ <code>String</code>

**Kind**: static method of [<code>BEARER</code>](#module_http-auth-utils/mecanisms/bearer..BEARER)
**Kind**: static method of [<code>BEARER</code>](#module_http-auth-utils/mechanisms/bearer..BEARER)
**Returns**: <code>String</code> - The built rest.

@@ -381,3 +972,3 @@ **Api**: public

```
<a name="module_http-auth-utils/mecanisms/bearer..BEARER.parseAuthorizationRest"></a>
<a name="module_http-auth-utils/mechanisms/bearer..BEARER.parseAuthorizationRest"></a>

@@ -387,3 +978,3 @@ #### BEARER.parseAuthorizationRest(rest) ⇒ <code>Object</code>

**Kind**: static method of [<code>BEARER</code>](#module_http-auth-utils/mecanisms/bearer..BEARER)
**Kind**: static method of [<code>BEARER</code>](#module_http-auth-utils/mechanisms/bearer..BEARER)
**Returns**: <code>Object</code> - Object representing the result of the parse operation {hash}.

@@ -394,3 +985,3 @@ **Api**: public

| --- | --- | --- |
| rest | <code>String</code> | The header rest (string after the authentication mecanism prefix).) |
| rest | <code>String</code> | The header rest (string after the authentication mechanism prefix).) |

@@ -405,3 +996,3 @@ **Example**

```
<a name="module_http-auth-utils/mecanisms/bearer..BEARER.buildAuthorizationRest"></a>
<a name="module_http-auth-utils/mechanisms/bearer..BEARER.buildAuthorizationRest"></a>

@@ -411,3 +1002,3 @@ #### BEARER.buildAuthorizationRest(content) ⇒ <code>String</code>

**Kind**: static method of [<code>BEARER</code>](#module_http-auth-utils/mecanisms/bearer..BEARER)
**Kind**: static method of [<code>BEARER</code>](#module_http-auth-utils/mechanisms/bearer..BEARER)
**Returns**: <code>String</code> - The rest built.

@@ -429,21 +1020,21 @@ **Api**: public

```
<a name="module_http-auth-utils/mecanisms/digest"></a>
<a name="module_http-auth-utils/mechanisms/digest"></a>
## http-auth-utils/mecanisms/digest
## http-auth-utils/mechanisms/digest
* [http-auth-utils/mecanisms/digest](#module_http-auth-utils/mecanisms/digest)
* [~DIGEST](#module_http-auth-utils/mecanisms/digest..DIGEST) : <code>Object</code>
* [.type](#module_http-auth-utils/mecanisms/digest..DIGEST.type) : <code>String</code>
* [.parseWWWAuthenticateRest(rest)](#module_http-auth-utils/mecanisms/digest..DIGEST.parseWWWAuthenticateRest) ⇒ <code>Object</code>
* [.buildWWWAuthenticateRest(data)](#module_http-auth-utils/mecanisms/digest..DIGEST.buildWWWAuthenticateRest) ⇒ <code>String</code>
* [.parseAuthorizationRest(rest)](#module_http-auth-utils/mecanisms/digest..DIGEST.parseAuthorizationRest) ⇒ <code>Object</code>
* [.buildAuthorizationRest(data)](#module_http-auth-utils/mecanisms/digest..DIGEST.buildAuthorizationRest) ⇒ <code>String</code>
* [.computeHash(data)](#module_http-auth-utils/mecanisms/digest..DIGEST.computeHash) ⇒ <code>String</code>
* [http-auth-utils/mechanisms/digest](#module_http-auth-utils/mechanisms/digest)
* [~DIGEST](#module_http-auth-utils/mechanisms/digest..DIGEST) : <code>Object</code>
* [.type](#module_http-auth-utils/mechanisms/digest..DIGEST.type) : <code>String</code>
* [.parseWWWAuthenticateRest(rest)](#module_http-auth-utils/mechanisms/digest..DIGEST.parseWWWAuthenticateRest) ⇒ <code>Object</code>
* [.buildWWWAuthenticateRest(data)](#module_http-auth-utils/mechanisms/digest..DIGEST.buildWWWAuthenticateRest) ⇒ <code>String</code>
* [.parseAuthorizationRest(rest)](#module_http-auth-utils/mechanisms/digest..DIGEST.parseAuthorizationRest) ⇒ <code>Object</code>
* [.buildAuthorizationRest(data)](#module_http-auth-utils/mechanisms/digest..DIGEST.buildAuthorizationRest) ⇒ <code>String</code>
* [.computeHash(data)](#module_http-auth-utils/mechanisms/digest..DIGEST.computeHash) ⇒ <code>String</code>
<a name="module_http-auth-utils/mecanisms/digest..DIGEST"></a>
<a name="module_http-auth-utils/mechanisms/digest..DIGEST"></a>
### http-auth-utils/mecanisms/digest~DIGEST : <code>Object</code>
Digest authentication mecanism.
### http-auth-utils/mechanisms/digest~DIGEST : <code>Object</code>
Digest authentication mechanism.
**Kind**: inner constant of [<code>http-auth-utils/mecanisms/digest</code>](#module_http-auth-utils/mecanisms/digest)
**Kind**: inner constant of [<code>http-auth-utils/mechanisms/digest</code>](#module_http-auth-utils/mechanisms/digest)
**See**

@@ -455,17 +1046,17 @@

* [~DIGEST](#module_http-auth-utils/mecanisms/digest..DIGEST) : <code>Object</code>
* [.type](#module_http-auth-utils/mecanisms/digest..DIGEST.type) : <code>String</code>
* [.parseWWWAuthenticateRest(rest)](#module_http-auth-utils/mecanisms/digest..DIGEST.parseWWWAuthenticateRest) ⇒ <code>Object</code>
* [.buildWWWAuthenticateRest(data)](#module_http-auth-utils/mecanisms/digest..DIGEST.buildWWWAuthenticateRest) ⇒ <code>String</code>
* [.parseAuthorizationRest(rest)](#module_http-auth-utils/mecanisms/digest..DIGEST.parseAuthorizationRest) ⇒ <code>Object</code>
* [.buildAuthorizationRest(data)](#module_http-auth-utils/mecanisms/digest..DIGEST.buildAuthorizationRest) ⇒ <code>String</code>
* [.computeHash(data)](#module_http-auth-utils/mecanisms/digest..DIGEST.computeHash) ⇒ <code>String</code>
* [~DIGEST](#module_http-auth-utils/mechanisms/digest..DIGEST) : <code>Object</code>
* [.type](#module_http-auth-utils/mechanisms/digest..DIGEST.type) : <code>String</code>
* [.parseWWWAuthenticateRest(rest)](#module_http-auth-utils/mechanisms/digest..DIGEST.parseWWWAuthenticateRest) ⇒ <code>Object</code>
* [.buildWWWAuthenticateRest(data)](#module_http-auth-utils/mechanisms/digest..DIGEST.buildWWWAuthenticateRest) ⇒ <code>String</code>
* [.parseAuthorizationRest(rest)](#module_http-auth-utils/mechanisms/digest..DIGEST.parseAuthorizationRest) ⇒ <code>Object</code>
* [.buildAuthorizationRest(data)](#module_http-auth-utils/mechanisms/digest..DIGEST.buildAuthorizationRest) ⇒ <code>String</code>
* [.computeHash(data)](#module_http-auth-utils/mechanisms/digest..DIGEST.computeHash) ⇒ <code>String</code>
<a name="module_http-auth-utils/mecanisms/digest..DIGEST.type"></a>
<a name="module_http-auth-utils/mechanisms/digest..DIGEST.type"></a>
#### DIGEST.type : <code>String</code>
The Digest auth mecanism prefix.
The Digest auth mechanism prefix.
**Kind**: static property of [<code>DIGEST</code>](#module_http-auth-utils/mecanisms/digest..DIGEST)
<a name="module_http-auth-utils/mecanisms/digest..DIGEST.parseWWWAuthenticateRest"></a>
**Kind**: static property of [<code>DIGEST</code>](#module_http-auth-utils/mechanisms/digest..DIGEST)
<a name="module_http-auth-utils/mechanisms/digest..DIGEST.parseWWWAuthenticateRest"></a>

@@ -475,3 +1066,3 @@ #### DIGEST.parseWWWAuthenticateRest(rest) ⇒ <code>Object</code>

**Kind**: static method of [<code>DIGEST</code>](#module_http-auth-utils/mecanisms/digest..DIGEST)
**Kind**: static method of [<code>DIGEST</code>](#module_http-auth-utils/mechanisms/digest..DIGEST)
**Returns**: <code>Object</code> - Object representing the result of the parse operation.

@@ -482,3 +1073,3 @@ **Api**: public

| --- | --- | --- |
| rest | <code>String</code> | The header rest (string after the authentication mecanism prefix). |
| rest | <code>String</code> | The header rest (string after the authentication mechanism prefix). |

@@ -501,3 +1092,3 @@ **Example**

```
<a name="module_http-auth-utils/mecanisms/digest..DIGEST.buildWWWAuthenticateRest"></a>
<a name="module_http-auth-utils/mechanisms/digest..DIGEST.buildWWWAuthenticateRest"></a>

@@ -507,3 +1098,3 @@ #### DIGEST.buildWWWAuthenticateRest(data) ⇒ <code>String</code>

**Kind**: static method of [<code>DIGEST</code>](#module_http-auth-utils/mecanisms/digest..DIGEST)
**Kind**: static method of [<code>DIGEST</code>](#module_http-auth-utils/mechanisms/digest..DIGEST)
**Returns**: <code>String</code> - The built rest.

@@ -531,3 +1122,3 @@ **Api**: public

```
<a name="module_http-auth-utils/mecanisms/digest..DIGEST.parseAuthorizationRest"></a>
<a name="module_http-auth-utils/mechanisms/digest..DIGEST.parseAuthorizationRest"></a>

@@ -537,3 +1128,3 @@ #### DIGEST.parseAuthorizationRest(rest) ⇒ <code>Object</code>

**Kind**: static method of [<code>DIGEST</code>](#module_http-auth-utils/mecanisms/digest..DIGEST)
**Kind**: static method of [<code>DIGEST</code>](#module_http-auth-utils/mechanisms/digest..DIGEST)
**Returns**: <code>Object</code> - Object representing the result of the parse operation {hash}.

@@ -544,3 +1135,3 @@ **Api**: public

| --- | --- | --- |
| rest | <code>String</code> | The header rest (string after the authentication mecanism prefix).) |
| rest | <code>String</code> | The header rest (string after the authentication mechanism prefix).) |

@@ -573,3 +1164,3 @@ **Example**

```
<a name="module_http-auth-utils/mecanisms/digest..DIGEST.buildAuthorizationRest"></a>
<a name="module_http-auth-utils/mechanisms/digest..DIGEST.buildAuthorizationRest"></a>

@@ -579,3 +1170,3 @@ #### DIGEST.buildAuthorizationRest(data) ⇒ <code>String</code>

**Kind**: static method of [<code>DIGEST</code>](#module_http-auth-utils/mecanisms/digest..DIGEST)
**Kind**: static method of [<code>DIGEST</code>](#module_http-auth-utils/mechanisms/digest..DIGEST)
**Returns**: <code>String</code> - The rest built.

@@ -613,3 +1204,3 @@ **Api**: public

```
<a name="module_http-auth-utils/mecanisms/digest..DIGEST.computeHash"></a>
<a name="module_http-auth-utils/mechanisms/digest..DIGEST.computeHash"></a>

@@ -619,3 +1210,3 @@ #### DIGEST.computeHash(data) ⇒ <code>String</code>

**Kind**: static method of [<code>DIGEST</code>](#module_http-auth-utils/mecanisms/digest..DIGEST)
**Kind**: static method of [<code>DIGEST</code>](#module_http-auth-utils/mechanisms/digest..DIGEST)
**Returns**: <code>String</code> - The hash representing the credentials.

@@ -622,0 +1213,0 @@ **Api**: public

import YError from 'yerror';
import BASIC from './mecanisms/basic';
import DIGEST from './mecanisms/digest';
import BEARER from './mecanisms/bearer';
import BASIC from './mechanisms/basic';
import DIGEST from './mechanisms/digest';
import BEARER from './mechanisms/bearer';

@@ -12,28 +12,30 @@ /**

/**
* Basic authentication mecanism.
* @type {Object}
* @see {@link module:http-auth-utils/mecanisms/basic}
* Natively supported authentication mechanisms.
* @type {Array}
*/
export { BASIC };
const mechanisms = [BASIC, DIGEST, BEARER];
/**
* Digest authentication mecanism.
* Basic authentication mechanism.
* @type {Object}
* @see {@link module:http-auth-utils/mecanisms/digest}
* @see {@link module:http-auth-utils/mechanisms/basic}
*/
export { DIGEST };
BASIC;
/**
* Bearer authentication mecanism.
* Digest authentication mechanism.
* @type {Object}
* @see {@link module:http-auth-utils/mecanisms/digest}
* @see {@link module:http-auth-utils/mechanisms/digest}
*/
export { BEARER };
DIGEST;
/**
* Natively supported authentication mecanisms.
* @type {Array}
* Bearer authentication mechanism.
* @type {Object}
* @see {@link module:http-auth-utils/mechanisms/digest}
*/
export const mecanisms = [BASIC, DIGEST, BEARER];
BEARER;
export { BASIC, DIGEST, BEARER, mechanisms };
/**

@@ -43,3 +45,3 @@ * Parse HTTP WWW-Authenticate header contents.

* @param {string} header The WWW-Authenticate header contents
* @param {Array} [authMecanisms=[BASIC, DIGEST]] Allow providing custom authentication mecanisms.
* @param {Array} [authMechanisms=[BASIC, DIGEST]] Allow providing custom authentication mechanisms.
* @return {Object} Result of the contents parse.

@@ -57,11 +59,14 @@ * @api public

*/
export function parseWWWAuthenticateHeader(header, authMecanisms = mecanisms) {
export function parseWWWAuthenticateHeader(
header,
authMechanisms = mechanisms,
) {
let result = null;
authMecanisms.some(authMecanism => {
if (0 === header.indexOf(authMecanism.type + ' ')) {
authMechanisms.some(authMechanism => {
if (0 === header.indexOf(authMechanism.type + ' ')) {
result = {
type: authMecanism.type,
data: authMecanism.parseWWWAuthenticateRest(
header.substr(authMecanism.type.length + 1),
type: authMechanism.type,
data: authMechanism.parseWWWAuthenticateRest(
header.substr(authMechanism.type.length + 1),
),

@@ -74,3 +79,3 @@ };

if (!result) {
throw new YError('E_UNKNOWN_AUTH_MECANISM', header);
throw new YError('E_UNKNOWN_AUTH_MECHANISM', header);
}

@@ -84,3 +89,3 @@ return result;

* @param {string} header The Authorization header contents
* @param {Array} [authMecanisms=[BASIC, DIGEST, BEARER]] Allow custom authentication mecanisms.
* @param {Array} [authMechanisms=[BASIC, DIGEST, BEARER]] Allow custom authentication mechanisms.
* @return {Object} Result of the contents parse.

@@ -98,11 +103,11 @@ * @api public

*/
export function parseAuthorizationHeader(header, authMecanisms = mecanisms) {
export function parseAuthorizationHeader(header, authMechanisms = mechanisms) {
let result = null;
authMecanisms.some(function(authMecanism) {
if (0 === header.indexOf(authMecanism.type + ' ')) {
authMechanisms.some(function(authMechanism) {
if (0 === header.indexOf(authMechanism.type + ' ')) {
result = {
type: authMecanism.type,
data: authMecanism.parseAuthorizationRest(
header.substr(authMecanism.type.length + 1),
type: authMechanism.type,
data: authMechanism.parseAuthorizationRest(
header.substr(authMechanism.type.length + 1),
),

@@ -117,3 +122,3 @@ };

}
throw new YError('E_UNKNOWN_AUTH_MECANISM', header);
throw new YError('E_UNKNOWN_AUTH_MECHANISM', header);
}

@@ -6,3 +6,3 @@ import assert from 'assert';

parseAuthorizationHeader,
mecanisms,
mechanisms,
BASIC,

@@ -23,2 +23,17 @@ DIGEST,

});
it('should parse Basic headers', () => {
neatequal(parseWWWAuthenticateHeader('Basic realm="test"', mechanisms), {
type: 'Basic',
data: {
realm: 'test',
},
});
});
it('should fail with unknown headers', () => {
assert.throws(
() => parseWWWAuthenticateHeader('Kikoolol realm="test"'),
/E_UNKNOWN_AUTH_MECHANISM/,
);
});
});

@@ -41,2 +56,16 @@

parseAuthorizationHeader(
'Basic QWxpIEJhYmE6b3BlbiBzZXNhbWU=',
mechanisms,
),
{
type: 'Basic',
data: {
username: 'Ali Baba',
password: 'open sesame',
hash: 'QWxpIEJhYmE6b3BlbiBzZXNhbWU=',
},
},
);
neatequal(
parseAuthorizationHeader(
'Basic bmljb2xhcy5mcm9pZHVyZUBzaW1wbGlmaWVsZC5jb206dGVzdA==',

@@ -65,10 +94,17 @@ ),

});
it('should fail with unknown headers', () => {
assert.throws(
() => parseAuthorizationHeader('Kikoolol ddd'),
/E_UNKNOWN_AUTH_MECHANISM/,
);
});
});
describe('mecanisms', () => {
it('should export bot DIGEST and BASIC mecanisms', () => {
assert.equal(mecanisms.length, 3);
describe('mechanisms', () => {
it('should export bot DIGEST and BASIC mechanisms', () => {
assert.equal(mechanisms.length, 3);
});
it('should export DIGEST BASIC and BEARER mecanisms', () => {
it('should export DIGEST BASIC and BEARER mechanisms', () => {
assert(BASIC);

@@ -75,0 +111,0 @@ assert(DIGEST);

@@ -69,3 +69,3 @@ import YError from 'yerror';

requiredKeys.forEach(name => {
if ('undefined' !== typeof data[name]) {
if ('undefined' === typeof data[name]) {
throw new YError('E_REQUIRED_KEY', name);

@@ -72,0 +72,0 @@ }

@@ -18,2 +18,3 @@ import assert from 'assert';

['realm', 'qop', 'nonce', 'opaque'],
['realm', 'qop', 'nonce', 'opaque'],
),

@@ -28,2 +29,23 @@ {

});
it('should fail with bad quoted value pair', () => {
assert.throws(
() => parseHTTPHeadersQuotedKeyValueSet('realm'),
/E_MALFORMED_QUOTEDKEYVALUE/,
);
});
it('should fail with bad quoted value pair', () => {
assert.throws(
() => parseHTTPHeadersQuotedKeyValueSet('realm="dsad"', []),
/E_UNAUTHORIZED_KEY/,
);
});
it('should fail with bad quoted value pair', () => {
assert.throws(
() => parseHTTPHeadersQuotedKeyValueSet('realm=dsad', ['realm']),
/E_UNQUOTED_VALUE/,
);
});
});

@@ -39,13 +61,46 @@

nonce: 'dcd98b7102dd2f0e8b11d0f600bfb0c093',
opaque: '5ccc069c403ebaf9f0171e9517f40e41',
},
['realm', 'qop', 'nonce', 'opaque'],
['realm', 'qop', 'nonce'],
),
'realm="testrealm@host.com", ' +
'qop="auth, auth-int", ' +
'nonce="dcd98b7102dd2f0e8b11d0f600bfb0c093", ' +
'opaque="5ccc069c403ebaf9f0171e9517f40e41"',
'nonce="dcd98b7102dd2f0e8b11d0f600bfb0c093"',
);
});
it('should work with unused keys', () => {
assert.equal(
buildHTTPHeadersQuotedKeyValueSet(
{
realm: 'testrealm@host.com',
qop: 'auth, auth-int',
nonce: 'dcd98b7102dd2f0e8b11d0f600bfb0c093',
opaque: '5ccc069c403ebaf9f0171e9517f40e41',
},
['realm', 'qop', 'nonce'],
),
'realm="testrealm@host.com", ' +
'qop="auth, auth-int", ' +
'nonce="dcd98b7102dd2f0e8b11d0f600bfb0c093"',
);
});
it('should fail without required keys', () => {
assert.throws(() =>
buildHTTPHeadersQuotedKeyValueSet(
{
realm: 'testrealm@host.com',
qop: 'auth, auth-int',
},
['realm', 'qop', 'nonce'],
['realm', 'qop', 'nonce'],
'realm="testrealm@host.com", ' +
'qop="auth, auth-int", ' +
'nonce="dcd98b7102dd2f0e8b11d0f600bfb0c093"',
/E_UNQUOTED_VALUE/,
),
);
});
});
});

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc