http-auth-utils
Advanced tools
Comparing version 2.1.0 to 2.2.0
@@ -0,1 +1,11 @@ | ||
# [2.2.0](https://github.com/nfroidure/http-auth-utils/compare/v2.1.0...v2.2.0) (2019-03-07) | ||
### Features | ||
* **buildAuthorizationHeader:** dd a way to build Authorization headers too ([1294584](https://github.com/nfroidure/http-auth-utils/commit/1294584)) | ||
* **buildWWWAuthenticateHeader:** Add a way to build WWW Authenticate headers too ([cc51ac1](https://github.com/nfroidure/http-auth-utils/commit/cc51ac1)) | ||
# [2.1.0](https://github.com/nfroidure/http-auth-utils/compare/v2.0.0...v2.1.0) (2019-02-14) | ||
@@ -2,0 +12,0 @@ |
@@ -8,2 +8,4 @@ "use strict"; | ||
exports.parseAuthorizationHeader = parseAuthorizationHeader; | ||
exports.buildWWWAuthenticateHeader = buildWWWAuthenticateHeader; | ||
exports.buildAuthorizationHeader = buildAuthorizationHeader; | ||
Object.defineProperty(exports, "BASIC", { | ||
@@ -148,2 +150,44 @@ enumerable: true, | ||
throw new _yerror.default('E_UNKNOWN_AUTH_MECHANISM', header); | ||
} | ||
/** | ||
* Build HTTP WWW-Authenticate header value. | ||
* @type {Function} | ||
* @param {Object} authMechanism The mechanism to use | ||
* @param {Object} | ||
* The WWW-Authenticate header contents to base the value on. | ||
* @return {string} The header value. | ||
* @api public | ||
* @example | ||
* assert.deepEqual( | ||
* buildWWWAuthenticateHeader(BASIC, { | ||
* realm: 'test' | ||
* }), | ||
* 'Basic realm="test"' | ||
* ); | ||
*/ | ||
function buildWWWAuthenticateHeader(authMechanism, data) { | ||
return `${authMechanism.type} ${authMechanism.buildWWWAuthenticateRest(data)}`; | ||
} | ||
/** | ||
* Build HTTP Authorization header value. | ||
* @type {Function} | ||
* @param {Object} authMechanism The mechanism to use | ||
* @param {Object} | ||
* The Authorization header contents to base the value on. | ||
* @return {string} The header value. | ||
* @api public | ||
* @example | ||
* assert.deepEqual( | ||
* buildAuthorizationHeader(BASIC, { | ||
* realm: 'test' | ||
* }), | ||
* 'Basic realm="test"' | ||
* ); | ||
*/ | ||
function buildAuthorizationHeader(authMechanism, data) { | ||
return `${authMechanism.type} ${authMechanism.buildAuthorizationRest(data)}`; | ||
} |
@@ -74,2 +74,23 @@ "use strict"; | ||
}); | ||
describe('buildWWWAuthenticateHeader', () => { | ||
it('should build Basic headers', () => { | ||
_assert.default.equal((0, _index.buildWWWAuthenticateHeader)(_index.BASIC, { | ||
realm: 'test' | ||
}), 'Basic realm="test"'); | ||
}); | ||
it('should be reentrant', () => { | ||
_assert.default.equal((0, _index.buildWWWAuthenticateHeader)(_index.BASIC, (0, _index.parseWWWAuthenticateHeader)('Basic realm="test"').data), 'Basic realm="test"'); | ||
}); | ||
}); | ||
describe('buildAuthorizationHeader', () => { | ||
it('should build Basic headers', () => { | ||
_assert.default.equal((0, _index.buildAuthorizationHeader)(_index.BASIC, { | ||
username: 'John', | ||
password: 'R:U:kidding?' | ||
}), 'Basic Sm9objpSOlU6a2lkZGluZz8='); | ||
}); | ||
it('should be reentrant', () => { | ||
_assert.default.equal((0, _index.buildAuthorizationHeader)(_index.BASIC, (0, _index.parseAuthorizationHeader)('Basic Sm9objpSOlU6a2lkZGluZz8=').data), 'Basic Sm9objpSOlU6a2lkZGluZz8='); | ||
}); | ||
}); | ||
describe('mechanisms', () => { | ||
@@ -76,0 +97,0 @@ it('should export bot DIGEST and BASIC mechanisms', () => { |
{ | ||
"name": "http-auth-utils", | ||
"version": "2.1.0", | ||
"version": "2.2.0", | ||
"description": "Parse, build and deal with HTTP authorization headers.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -107,2 +107,4 @@ [//]: # ( ) | ||
* [.parseAuthorizationHeader(header, [authMechanisms])](#module_http-auth-utils.parseAuthorizationHeader) ⇒ <code>Object</code> | ||
* [.buildWWWAuthenticateHeader(authMechanism, The)](#module_http-auth-utils.buildWWWAuthenticateHeader) ⇒ <code>string</code> | ||
* [.buildAuthorizationHeader(authMechanism, The)](#module_http-auth-utils.buildAuthorizationHeader) ⇒ <code>string</code> | ||
* _inner_ | ||
@@ -161,2 +163,48 @@ * [~mechanisms](#module_http-auth-utils..mechanisms) : <code>Array</code> | ||
``` | ||
<a name="module_http-auth-utils.buildWWWAuthenticateHeader"></a> | ||
### http-auth-utils.buildWWWAuthenticateHeader(authMechanism, The) ⇒ <code>string</code> | ||
Build HTTP WWW-Authenticate header value. | ||
**Kind**: static method of [<code>http-auth-utils</code>](#module_http-auth-utils) | ||
**Returns**: <code>string</code> - The header value. | ||
**Api**: public | ||
| Param | Type | Description | | ||
| --- | --- | --- | | ||
| authMechanism | <code>Object</code> | The mechanism to use | | ||
| The | <code>Object</code> | WWW-Authenticate header contents to base the value on. | | ||
**Example** | ||
```js | ||
assert.deepEqual( | ||
buildWWWAuthenticateHeader(BASIC, { | ||
realm: 'test' | ||
}), | ||
'Basic realm="test"' | ||
); | ||
``` | ||
<a name="module_http-auth-utils.buildAuthorizationHeader"></a> | ||
### http-auth-utils.buildAuthorizationHeader(authMechanism, The) ⇒ <code>string</code> | ||
Build HTTP Authorization header value. | ||
**Kind**: static method of [<code>http-auth-utils</code>](#module_http-auth-utils) | ||
**Returns**: <code>string</code> - The header value. | ||
**Api**: public | ||
| Param | Type | Description | | ||
| --- | --- | --- | | ||
| authMechanism | <code>Object</code> | The mechanism to use | | ||
| The | <code>Object</code> | Authorization header contents to base the value on. | | ||
**Example** | ||
```js | ||
assert.deepEqual( | ||
buildAuthorizationHeader(BASIC, { | ||
realm: 'test' | ||
}), | ||
'Basic realm="test"' | ||
); | ||
``` | ||
<a name="module_http-auth-utils..mechanisms"></a> | ||
@@ -163,0 +211,0 @@ |
@@ -5,6 +5,6 @@ type Mechanism = { | ||
declare const BASIC : Mechanism; | ||
declare const DIGEST : Mechanism; | ||
declare const BEARER : Mechanism; | ||
declare const mechanisms : Array<Mechanism>; | ||
declare const BASIC: Mechanism; | ||
declare const DIGEST: Mechanism; | ||
declare const BEARER: Mechanism; | ||
declare const mechanisms: Array<Mechanism>; | ||
@@ -29,2 +29,14 @@ declare function parseAuthorizationHeader( | ||
}; | ||
declare function buildWWWAuthenticateHeader( | ||
authMechanism: Mechanism, | ||
data: { | ||
[prop: string]: any; | ||
}, | ||
): string; | ||
declare function buildAuthorizationHeader( | ||
authMechanism: Mechanism, | ||
data: { | ||
[prop: string]: any; | ||
}, | ||
): string; | ||
@@ -34,2 +46,4 @@ export { | ||
parseAuthorizationHeader, | ||
buildWWWAuthenticateHeader, | ||
buildAuthorizationHeader, | ||
BASIC, | ||
@@ -36,0 +50,0 @@ DIGEST, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
79309
1117
721
0