@saurbit/oauth2-jwt 0.1.2 → 0.1.4
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.
package/README.md
CHANGED
|
@@ -132,7 +132,7 @@ const authority = new JoseJwksAuthority(store, 8.64e+6); // 100 days key TTL
|
|
|
132
132
|
|
|
133
133
|
const rotator = new JwksRotator({
|
|
134
134
|
keyGenerator: authority,
|
|
135
|
-
|
|
135
|
+
rotationTimestampStore: store,
|
|
136
136
|
rotationIntervalMs: 7.884e9, // 91 days
|
|
137
137
|
});
|
|
138
138
|
```
|
package/esm/jwks_rotator.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ export interface JwksRotatorOptions {
|
|
|
6
6
|
/** The key generator used to produce new signing key pairs during rotation. */
|
|
7
7
|
keyGenerator: KeyGenerator;
|
|
8
8
|
/** The store used to read and persist the last rotation timestamp. */
|
|
9
|
-
|
|
9
|
+
rotationTimestampStore: JwksRotationTimestampStore;
|
|
10
10
|
/** How often (in milliseconds) new keys should be generated. For example, `7.884e9` for 91 days. */
|
|
11
11
|
rotationIntervalMs: number;
|
|
12
12
|
}
|
|
@@ -20,12 +20,12 @@ export interface JwksRotatorOptions {
|
|
|
20
20
|
*/
|
|
21
21
|
export declare class JwksRotator {
|
|
22
22
|
private readonly keyGenerator;
|
|
23
|
-
private readonly
|
|
23
|
+
private readonly rotationTimestampStore;
|
|
24
24
|
private readonly rotationIntervalMs;
|
|
25
25
|
/**
|
|
26
26
|
* @param options - Rotation configuration: key generator, timestamp store, and interval.
|
|
27
27
|
*/
|
|
28
|
-
constructor({ keyGenerator, rotationIntervalMs,
|
|
28
|
+
constructor({ keyGenerator, rotationIntervalMs, rotationTimestampStore }: JwksRotatorOptions);
|
|
29
29
|
/**
|
|
30
30
|
* Checks if rotation is due, and performs rotation if necessary.
|
|
31
31
|
* Should be called at service startup or on a schedule (e.g. every hour).
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jwks_rotator.d.ts","sourceRoot":"","sources":["../src/jwks_rotator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,0BAA0B,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAEtE;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,+EAA+E;IAC/E,YAAY,EAAE,YAAY,CAAC;IAC3B,sEAAsE;IACtE,
|
|
1
|
+
{"version":3,"file":"jwks_rotator.d.ts","sourceRoot":"","sources":["../src/jwks_rotator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,0BAA0B,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAEtE;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,+EAA+E;IAC/E,YAAY,EAAE,YAAY,CAAC;IAC3B,sEAAsE;IACtE,sBAAsB,EAAE,0BAA0B,CAAC;IACnD,oGAAoG;IACpG,kBAAkB,EAAE,MAAM,CAAC;CAC5B;AAED;;;;;;;GAOG;AACH,qBAAa,WAAW;IACtB,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAe;IAC5C,OAAO,CAAC,QAAQ,CAAC,sBAAsB,CAA6B;IACpE,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAS;IAE5C;;OAEG;gBACS,EAAE,YAAY,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,EAAE,kBAAkB;IAM5F;;;OAGG;IACU,kBAAkB,IAAI,OAAO,CAAC,IAAI,CAAC;YAYlC,UAAU;CAGzB"}
|
package/esm/jwks_rotator.js
CHANGED
|
@@ -10,14 +10,14 @@ export class JwksRotator {
|
|
|
10
10
|
/**
|
|
11
11
|
* @param options - Rotation configuration: key generator, timestamp store, and interval.
|
|
12
12
|
*/
|
|
13
|
-
constructor({ keyGenerator, rotationIntervalMs,
|
|
13
|
+
constructor({ keyGenerator, rotationIntervalMs, rotationTimestampStore }) {
|
|
14
14
|
Object.defineProperty(this, "keyGenerator", {
|
|
15
15
|
enumerable: true,
|
|
16
16
|
configurable: true,
|
|
17
17
|
writable: true,
|
|
18
18
|
value: void 0
|
|
19
19
|
});
|
|
20
|
-
Object.defineProperty(this, "
|
|
20
|
+
Object.defineProperty(this, "rotationTimestampStore", {
|
|
21
21
|
enumerable: true,
|
|
22
22
|
configurable: true,
|
|
23
23
|
writable: true,
|
|
@@ -31,7 +31,7 @@ export class JwksRotator {
|
|
|
31
31
|
});
|
|
32
32
|
this.keyGenerator = keyGenerator;
|
|
33
33
|
this.rotationIntervalMs = rotationIntervalMs;
|
|
34
|
-
this.
|
|
34
|
+
this.rotationTimestampStore = rotationTimestampStore;
|
|
35
35
|
}
|
|
36
36
|
/**
|
|
37
37
|
* Checks if rotation is due, and performs rotation if necessary.
|
|
@@ -39,10 +39,10 @@ export class JwksRotator {
|
|
|
39
39
|
*/
|
|
40
40
|
async checkAndRotateKeys() {
|
|
41
41
|
const now = Date.now();
|
|
42
|
-
const lastRotation = await this.
|
|
42
|
+
const lastRotation = await this.rotationTimestampStore.getLastRotationTimestamp();
|
|
43
43
|
if (isNaN(lastRotation) || now - lastRotation >= this.rotationIntervalMs) {
|
|
44
44
|
await this.rotateKeys();
|
|
45
|
-
await this.
|
|
45
|
+
await this.rotationTimestampStore.setLastRotationTimestamp(now);
|
|
46
46
|
}
|
|
47
47
|
else {
|
|
48
48
|
const _nextIn = this.rotationIntervalMs - (now - lastRotation);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@saurbit/oauth2-jwt",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"description": "JWT utilities for @saurbit/oauth2 (jose-based)",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"oauth2",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"jose": "^6.2.2"
|
|
28
28
|
},
|
|
29
29
|
"peerDependencies": {
|
|
30
|
-
"@saurbit/oauth2": "^0.1.
|
|
30
|
+
"@saurbit/oauth2": "^0.1.6"
|
|
31
31
|
},
|
|
32
32
|
"_generatedBy": "dnt@dev"
|
|
33
33
|
}
|
package/script/jwks_rotator.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ export interface JwksRotatorOptions {
|
|
|
6
6
|
/** The key generator used to produce new signing key pairs during rotation. */
|
|
7
7
|
keyGenerator: KeyGenerator;
|
|
8
8
|
/** The store used to read and persist the last rotation timestamp. */
|
|
9
|
-
|
|
9
|
+
rotationTimestampStore: JwksRotationTimestampStore;
|
|
10
10
|
/** How often (in milliseconds) new keys should be generated. For example, `7.884e9` for 91 days. */
|
|
11
11
|
rotationIntervalMs: number;
|
|
12
12
|
}
|
|
@@ -20,12 +20,12 @@ export interface JwksRotatorOptions {
|
|
|
20
20
|
*/
|
|
21
21
|
export declare class JwksRotator {
|
|
22
22
|
private readonly keyGenerator;
|
|
23
|
-
private readonly
|
|
23
|
+
private readonly rotationTimestampStore;
|
|
24
24
|
private readonly rotationIntervalMs;
|
|
25
25
|
/**
|
|
26
26
|
* @param options - Rotation configuration: key generator, timestamp store, and interval.
|
|
27
27
|
*/
|
|
28
|
-
constructor({ keyGenerator, rotationIntervalMs,
|
|
28
|
+
constructor({ keyGenerator, rotationIntervalMs, rotationTimestampStore }: JwksRotatorOptions);
|
|
29
29
|
/**
|
|
30
30
|
* Checks if rotation is due, and performs rotation if necessary.
|
|
31
31
|
* Should be called at service startup or on a schedule (e.g. every hour).
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jwks_rotator.d.ts","sourceRoot":"","sources":["../src/jwks_rotator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,0BAA0B,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAEtE;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,+EAA+E;IAC/E,YAAY,EAAE,YAAY,CAAC;IAC3B,sEAAsE;IACtE,
|
|
1
|
+
{"version":3,"file":"jwks_rotator.d.ts","sourceRoot":"","sources":["../src/jwks_rotator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,0BAA0B,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAEtE;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,+EAA+E;IAC/E,YAAY,EAAE,YAAY,CAAC;IAC3B,sEAAsE;IACtE,sBAAsB,EAAE,0BAA0B,CAAC;IACnD,oGAAoG;IACpG,kBAAkB,EAAE,MAAM,CAAC;CAC5B;AAED;;;;;;;GAOG;AACH,qBAAa,WAAW;IACtB,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAe;IAC5C,OAAO,CAAC,QAAQ,CAAC,sBAAsB,CAA6B;IACpE,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAS;IAE5C;;OAEG;gBACS,EAAE,YAAY,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,EAAE,kBAAkB;IAM5F;;;OAGG;IACU,kBAAkB,IAAI,OAAO,CAAC,IAAI,CAAC;YAYlC,UAAU;CAGzB"}
|
package/script/jwks_rotator.js
CHANGED
|
@@ -13,14 +13,14 @@ class JwksRotator {
|
|
|
13
13
|
/**
|
|
14
14
|
* @param options - Rotation configuration: key generator, timestamp store, and interval.
|
|
15
15
|
*/
|
|
16
|
-
constructor({ keyGenerator, rotationIntervalMs,
|
|
16
|
+
constructor({ keyGenerator, rotationIntervalMs, rotationTimestampStore }) {
|
|
17
17
|
Object.defineProperty(this, "keyGenerator", {
|
|
18
18
|
enumerable: true,
|
|
19
19
|
configurable: true,
|
|
20
20
|
writable: true,
|
|
21
21
|
value: void 0
|
|
22
22
|
});
|
|
23
|
-
Object.defineProperty(this, "
|
|
23
|
+
Object.defineProperty(this, "rotationTimestampStore", {
|
|
24
24
|
enumerable: true,
|
|
25
25
|
configurable: true,
|
|
26
26
|
writable: true,
|
|
@@ -34,7 +34,7 @@ class JwksRotator {
|
|
|
34
34
|
});
|
|
35
35
|
this.keyGenerator = keyGenerator;
|
|
36
36
|
this.rotationIntervalMs = rotationIntervalMs;
|
|
37
|
-
this.
|
|
37
|
+
this.rotationTimestampStore = rotationTimestampStore;
|
|
38
38
|
}
|
|
39
39
|
/**
|
|
40
40
|
* Checks if rotation is due, and performs rotation if necessary.
|
|
@@ -42,10 +42,10 @@ class JwksRotator {
|
|
|
42
42
|
*/
|
|
43
43
|
async checkAndRotateKeys() {
|
|
44
44
|
const now = Date.now();
|
|
45
|
-
const lastRotation = await this.
|
|
45
|
+
const lastRotation = await this.rotationTimestampStore.getLastRotationTimestamp();
|
|
46
46
|
if (isNaN(lastRotation) || now - lastRotation >= this.rotationIntervalMs) {
|
|
47
47
|
await this.rotateKeys();
|
|
48
|
-
await this.
|
|
48
|
+
await this.rotationTimestampStore.setLastRotationTimestamp(now);
|
|
49
49
|
}
|
|
50
50
|
else {
|
|
51
51
|
const _nextIn = this.rotationIntervalMs - (now - lastRotation);
|