kauth-sdk-node 0.0.1794213761-dev.1 → 0.0.1794924476-dev.1
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/dist/authenticator/provider.js +23 -20
- package/package.json +1 -1
|
@@ -10,6 +10,27 @@ const manager_1 = require("./manager");
|
|
|
10
10
|
const Exp = 'exp';
|
|
11
11
|
const Sub = 'sub';
|
|
12
12
|
const Iat = 'iat';
|
|
13
|
+
function refreshVerifiedToken(token, secret, defaultDuration) {
|
|
14
|
+
let verified;
|
|
15
|
+
try {
|
|
16
|
+
verified = jsonwebtoken_1.default.verify(token, secret, { algorithms: ['HS256', 'HS384', 'HS512'] });
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
if (typeof verified !== 'object' || !verified || typeof verified.iat !== 'number') {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
const { [Iat]: iat, [Exp]: exp, ...claims } = verified;
|
|
25
|
+
// Preserve the original lifetime, including tokens issued with a dynamic duration.
|
|
26
|
+
const duration = exp && iat ? exp - iat : defaultDuration;
|
|
27
|
+
const elapsed = Math.floor(Date.now() / 1000) - iat;
|
|
28
|
+
if (elapsed > duration / 2 && elapsed < duration) {
|
|
29
|
+
claims[Exp] = (0, dayjs_1.default)().add(duration, 'second').unix();
|
|
30
|
+
return jsonwebtoken_1.default.sign(claims, secret);
|
|
31
|
+
}
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
13
34
|
class JsonWebTokenSubjectProvider {
|
|
14
35
|
secret;
|
|
15
36
|
duration;
|
|
@@ -27,16 +48,7 @@ class JsonWebTokenSubjectProvider {
|
|
|
27
48
|
}
|
|
28
49
|
}
|
|
29
50
|
refresh(token) {
|
|
30
|
-
|
|
31
|
-
// jwt life duration from claims
|
|
32
|
-
const duration = exp && iat ? exp - iat : this.duration;
|
|
33
|
-
const elapsed = Math.floor(Date.now() / 1000) - iat;
|
|
34
|
-
if (elapsed > duration / 2 && elapsed < duration) {
|
|
35
|
-
const exp = (0, dayjs_1.default)().add(duration, 'second').unix();
|
|
36
|
-
claims[Exp] = exp;
|
|
37
|
-
return jsonwebtoken_1.default.sign(claims, this.secret);
|
|
38
|
-
}
|
|
39
|
-
return null;
|
|
51
|
+
return refreshVerifiedToken(token, this.secret, this.duration);
|
|
40
52
|
}
|
|
41
53
|
}
|
|
42
54
|
exports.JsonWebTokenSubjectProvider = JsonWebTokenSubjectProvider;
|
|
@@ -60,16 +72,7 @@ class JsonWebTokenAuthenticationProvider {
|
|
|
60
72
|
}
|
|
61
73
|
}
|
|
62
74
|
refresh(token) {
|
|
63
|
-
|
|
64
|
-
// jwt life duration from claims
|
|
65
|
-
const duration = exp && iat ? exp - iat : this.duration;
|
|
66
|
-
const elapsed = Math.floor(Date.now() / 1000) - iat;
|
|
67
|
-
if (elapsed > duration / 2 && elapsed < duration) {
|
|
68
|
-
const exp = (0, dayjs_1.default)().add(duration, 'second').unix();
|
|
69
|
-
claims[Exp] = exp;
|
|
70
|
-
return jsonwebtoken_1.default.sign(claims, this.secret);
|
|
71
|
-
}
|
|
72
|
-
return null;
|
|
75
|
+
return refreshVerifiedToken(token, this.secret, this.duration);
|
|
73
76
|
}
|
|
74
77
|
authenticate(authenticationInformation, dynamicDuration) {
|
|
75
78
|
const exp = (0, dayjs_1.default)()
|