jose 4.6.2 → 4.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -15,15 +15,20 @@ class RemoteJWKSet extends LocalJWKSet {
|
|
|
15
15
|
typeof (options === null || options === void 0 ? void 0 : options.timeoutDuration) === 'number' ? options === null || options === void 0 ? void 0 : options.timeoutDuration : 5000;
|
|
16
16
|
this._cooldownDuration =
|
|
17
17
|
typeof (options === null || options === void 0 ? void 0 : options.cooldownDuration) === 'number' ? options === null || options === void 0 ? void 0 : options.cooldownDuration : 30000;
|
|
18
|
+
this._cacheMaxAge = typeof (options === null || options === void 0 ? void 0 : options.cacheMaxAge) === 'number' ? options === null || options === void 0 ? void 0 : options.cacheMaxAge : 600000;
|
|
18
19
|
}
|
|
19
20
|
coolingDown() {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
return typeof this._jwksTimestamp === 'number'
|
|
22
|
+
? Date.now() < this._jwksTimestamp + this._cooldownDuration
|
|
23
|
+
: false;
|
|
24
|
+
}
|
|
25
|
+
fresh() {
|
|
26
|
+
return typeof this._jwksTimestamp === 'number'
|
|
27
|
+
? Date.now() < this._jwksTimestamp + this._cacheMaxAge
|
|
28
|
+
: false;
|
|
24
29
|
}
|
|
25
30
|
async getKey(protectedHeader, token) {
|
|
26
|
-
if (!this._jwks) {
|
|
31
|
+
if (!this._jwks || !this.fresh()) {
|
|
27
32
|
await this.reload();
|
|
28
33
|
}
|
|
29
34
|
try {
|
|
@@ -60,7 +65,7 @@ class RemoteJWKSet extends LocalJWKSet {
|
|
|
60
65
|
throw new JWKSInvalid('JSON Web Key Set malformed');
|
|
61
66
|
}
|
|
62
67
|
this._jwks = { keys: json.keys };
|
|
63
|
-
this.
|
|
68
|
+
this._jwksTimestamp = Date.now();
|
|
64
69
|
this._pendingFetch = undefined;
|
|
65
70
|
})
|
|
66
71
|
.catch((err) => {
|
|
@@ -18,15 +18,20 @@ class RemoteJWKSet extends local_js_1.LocalJWKSet {
|
|
|
18
18
|
typeof (options === null || options === void 0 ? void 0 : options.timeoutDuration) === 'number' ? options === null || options === void 0 ? void 0 : options.timeoutDuration : 5000;
|
|
19
19
|
this._cooldownDuration =
|
|
20
20
|
typeof (options === null || options === void 0 ? void 0 : options.cooldownDuration) === 'number' ? options === null || options === void 0 ? void 0 : options.cooldownDuration : 30000;
|
|
21
|
+
this._cacheMaxAge = typeof (options === null || options === void 0 ? void 0 : options.cacheMaxAge) === 'number' ? options === null || options === void 0 ? void 0 : options.cacheMaxAge : 600000;
|
|
21
22
|
}
|
|
22
23
|
coolingDown() {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
return typeof this._jwksTimestamp === 'number'
|
|
25
|
+
? Date.now() < this._jwksTimestamp + this._cooldownDuration
|
|
26
|
+
: false;
|
|
27
|
+
}
|
|
28
|
+
fresh() {
|
|
29
|
+
return typeof this._jwksTimestamp === 'number'
|
|
30
|
+
? Date.now() < this._jwksTimestamp + this._cacheMaxAge
|
|
31
|
+
: false;
|
|
27
32
|
}
|
|
28
33
|
async getKey(protectedHeader, token) {
|
|
29
|
-
if (!this._jwks) {
|
|
34
|
+
if (!this._jwks || !this.fresh()) {
|
|
30
35
|
await this.reload();
|
|
31
36
|
}
|
|
32
37
|
try {
|
|
@@ -63,7 +68,7 @@ class RemoteJWKSet extends local_js_1.LocalJWKSet {
|
|
|
63
68
|
throw new errors_js_1.JWKSInvalid('JSON Web Key Set malformed');
|
|
64
69
|
}
|
|
65
70
|
this._jwks = { keys: json.keys };
|
|
66
|
-
this.
|
|
71
|
+
this._jwksTimestamp = Date.now();
|
|
67
72
|
this._pendingFetch = undefined;
|
|
68
73
|
})
|
|
69
74
|
.catch((err) => {
|
|
@@ -15,15 +15,20 @@ class RemoteJWKSet extends LocalJWKSet {
|
|
|
15
15
|
typeof (options === null || options === void 0 ? void 0 : options.timeoutDuration) === 'number' ? options === null || options === void 0 ? void 0 : options.timeoutDuration : 5000;
|
|
16
16
|
this._cooldownDuration =
|
|
17
17
|
typeof (options === null || options === void 0 ? void 0 : options.cooldownDuration) === 'number' ? options === null || options === void 0 ? void 0 : options.cooldownDuration : 30000;
|
|
18
|
+
this._cacheMaxAge = typeof (options === null || options === void 0 ? void 0 : options.cacheMaxAge) === 'number' ? options === null || options === void 0 ? void 0 : options.cacheMaxAge : 600000;
|
|
18
19
|
}
|
|
19
20
|
coolingDown() {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
return typeof this._jwksTimestamp === 'number'
|
|
22
|
+
? Date.now() < this._jwksTimestamp + this._cooldownDuration
|
|
23
|
+
: false;
|
|
24
|
+
}
|
|
25
|
+
fresh() {
|
|
26
|
+
return typeof this._jwksTimestamp === 'number'
|
|
27
|
+
? Date.now() < this._jwksTimestamp + this._cacheMaxAge
|
|
28
|
+
: false;
|
|
24
29
|
}
|
|
25
30
|
async getKey(protectedHeader, token) {
|
|
26
|
-
if (!this._jwks) {
|
|
31
|
+
if (!this._jwks || !this.fresh()) {
|
|
27
32
|
await this.reload();
|
|
28
33
|
}
|
|
29
34
|
try {
|
|
@@ -60,7 +65,7 @@ class RemoteJWKSet extends LocalJWKSet {
|
|
|
60
65
|
throw new JWKSInvalid('JSON Web Key Set malformed');
|
|
61
66
|
}
|
|
62
67
|
this._jwks = { keys: json.keys };
|
|
63
|
-
this.
|
|
68
|
+
this._jwksTimestamp = Date.now();
|
|
64
69
|
this._pendingFetch = undefined;
|
|
65
70
|
})
|
|
66
71
|
.catch((err) => {
|
|
@@ -4,23 +4,32 @@ import type { JWSHeaderParameters, FlattenedJWSInput, GetKeyFunction } from '../
|
|
|
4
4
|
*/
|
|
5
5
|
export interface RemoteJWKSetOptions {
|
|
6
6
|
/**
|
|
7
|
-
* Timeout (in milliseconds) for the HTTP request. When reached the request
|
|
8
|
-
* aborted and the verification will fail. Default is 5000
|
|
7
|
+
* Timeout (in milliseconds) for the HTTP request. When reached the request
|
|
8
|
+
* will be aborted and the verification will fail. Default is 5000 (5
|
|
9
|
+
* seconds).
|
|
9
10
|
*/
|
|
10
11
|
timeoutDuration?: number;
|
|
11
12
|
/**
|
|
12
|
-
* Duration (in milliseconds) for which no more HTTP requests will be
|
|
13
|
-
* after a previous successful fetch. Default is 30000.
|
|
13
|
+
* Duration (in milliseconds) for which no more HTTP requests will be
|
|
14
|
+
* triggered after a previous successful fetch. Default is 30000 (30 seconds).
|
|
14
15
|
*/
|
|
15
16
|
cooldownDuration?: number;
|
|
16
17
|
/**
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
*
|
|
23
|
-
*
|
|
18
|
+
* Maximum time (in milliseconds) between successful HTTP requests. Default is
|
|
19
|
+
* 600000 (10 minutes).
|
|
20
|
+
*/
|
|
21
|
+
cacheMaxAge?: number | typeof Infinity;
|
|
22
|
+
/**
|
|
23
|
+
* An instance of
|
|
24
|
+
* [http.Agent](https://nodejs.org/api/http.html#http_class_http_agent) or
|
|
25
|
+
* [https.Agent](https://nodejs.org/api/https.html#https_class_https_agent) to
|
|
26
|
+
* pass to the
|
|
27
|
+
* [http.get](https://nodejs.org/api/http.html#http_http_get_options_callback)
|
|
28
|
+
* or
|
|
29
|
+
* [https.get](https://nodejs.org/api/https.html#https_https_get_options_callback)
|
|
30
|
+
* method's options. Use when behind an http(s) proxy. This is a Node.js
|
|
31
|
+
* runtime specific option, it is ignored when used outside of Node.js
|
|
32
|
+
* runtime.
|
|
24
33
|
*/
|
|
25
34
|
agent?: any;
|
|
26
35
|
}
|