@versini/auth-common 2.5.0 → 2.6.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.
- package/dist/index.d.ts +1 -0
- package/dist/index.js +25 -24
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -12,6 +12,7 @@ declare const JWT: {
|
|
|
12
12
|
ALG: string;
|
|
13
13
|
USER_ID_KEY: string;
|
|
14
14
|
TOKEN_ID_KEY: string;
|
|
15
|
+
NONCE_KEY: string;
|
|
15
16
|
ISSUER: string;
|
|
16
17
|
};
|
|
17
18
|
declare const JWT_PUBLIC_KEY = "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAsF6i3Jd9fY/3COqCw/m7\nw5PKyTYLGAI2I6SIIdpe6i6DOCbEkmDz7LdVsBqwNtVi8gvWYIj+8ol6rU3qu1v5\ni1Jd45GSK4kzkVdgCmQZbM5ak0KI99q5wsrAIzUd+LRJ2HRvWtr5IYdsIiXaQjle\naMwPFOIcJH+rKfFgNcHLcaS5syp7zU1ANwZ+trgR+DifBr8TLVkBynmNeTyhDm2+\nl0haqjMk0UoNPPE8iYBWUHQJJE1Dqstj65d6Eh5g64Pao25y4cmYJbKjiblIGEkE\nsjqybA9mARAqh9k/eiIopecWSiffNQTwVQVd2I9ZH3BalhEXHlqFgrjz51kFqg81\nawIDAQAB\n-----END PUBLIC KEY-----";
|
package/dist/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
@versini/auth-common v2.
|
|
2
|
+
@versini/auth-common v2.6.0
|
|
3
3
|
© 2024 gizmette.com
|
|
4
4
|
*/
|
|
5
5
|
try {
|
|
6
6
|
window.__VERSINI_AUTH_COMMON__ || (window.__VERSINI_AUTH_COMMON__ = {
|
|
7
|
-
version: "2.
|
|
8
|
-
buildTime: "06/
|
|
7
|
+
version: "2.6.0",
|
|
8
|
+
buildTime: "06/26/2024 08:40 AM EDT",
|
|
9
9
|
homepage: "https://github.com/aversini/auth-client",
|
|
10
10
|
license: "MIT"
|
|
11
11
|
});
|
|
@@ -66,7 +66,7 @@ class G extends w {
|
|
|
66
66
|
return "ERR_JOSE_ALG_NOT_ALLOWED";
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
|
-
class
|
|
69
|
+
class _ extends w {
|
|
70
70
|
constructor() {
|
|
71
71
|
super(...arguments), this.code = "ERR_JOSE_NOT_SUPPORTED";
|
|
72
72
|
}
|
|
@@ -90,7 +90,7 @@ class k extends w {
|
|
|
90
90
|
return "ERR_JWT_INVALID";
|
|
91
91
|
}
|
|
92
92
|
}
|
|
93
|
-
class
|
|
93
|
+
class Y extends w {
|
|
94
94
|
constructor() {
|
|
95
95
|
super(...arguments), this.code = "ERR_JWS_SIGNATURE_VERIFICATION_FAILED", this.message = "signature verification failed";
|
|
96
96
|
}
|
|
@@ -107,7 +107,7 @@ function b(e, t) {
|
|
|
107
107
|
function T(e) {
|
|
108
108
|
return parseInt(e.name.slice(4), 10);
|
|
109
109
|
}
|
|
110
|
-
function
|
|
110
|
+
function q(e) {
|
|
111
111
|
switch (e) {
|
|
112
112
|
case "ES256":
|
|
113
113
|
return "P-256";
|
|
@@ -172,7 +172,7 @@ function Q(e, t, ...n) {
|
|
|
172
172
|
case "ES512": {
|
|
173
173
|
if (!b(e.algorithm, "ECDSA"))
|
|
174
174
|
throw p("ECDSA");
|
|
175
|
-
const r =
|
|
175
|
+
const r = q(t);
|
|
176
176
|
if (e.algorithm.namedCurve !== r)
|
|
177
177
|
throw p(r, "algorithm.namedCurve");
|
|
178
178
|
break;
|
|
@@ -257,7 +257,7 @@ const Z = (e, t) => {
|
|
|
257
257
|
case y(e, [43, 101, 113]):
|
|
258
258
|
return "Ed448";
|
|
259
259
|
default:
|
|
260
|
-
throw new
|
|
260
|
+
throw new _("Invalid or unsupported EC Key Curve or OKP Key Sub Type");
|
|
261
261
|
}
|
|
262
262
|
}, ee = async (e, t, n, r, o) => {
|
|
263
263
|
let i, a;
|
|
@@ -303,7 +303,7 @@ const Z = (e, t) => {
|
|
|
303
303
|
i = { name: K(c) }, a = ["verify"];
|
|
304
304
|
break;
|
|
305
305
|
default:
|
|
306
|
-
throw new
|
|
306
|
+
throw new _('Invalid or unsupported "alg" (Algorithm) value');
|
|
307
307
|
}
|
|
308
308
|
return P.subtle.importKey(t, c, i, !1, a);
|
|
309
309
|
}, te = (e, t, n) => ee(/(?:-----(?:BEGIN|END) PUBLIC KEY-----|\s)/g, "spki", e, t);
|
|
@@ -342,7 +342,7 @@ function ie(e, t, n, r, o) {
|
|
|
342
342
|
n !== void 0 ? i = new Map([...Object.entries(n), ...t.entries()]) : i = t;
|
|
343
343
|
for (const a of r.crit) {
|
|
344
344
|
if (!i.has(a))
|
|
345
|
-
throw new
|
|
345
|
+
throw new _(`Extension Header Parameter "${a}" is not recognized`);
|
|
346
346
|
if (o[a] === void 0)
|
|
347
347
|
throw new e(`Extension Header Parameter "${a}" is missing`);
|
|
348
348
|
if (i.get(a) && r[a] === void 0)
|
|
@@ -378,7 +378,7 @@ function se(e, t) {
|
|
|
378
378
|
case "EdDSA":
|
|
379
379
|
return { name: t.name };
|
|
380
380
|
default:
|
|
381
|
-
throw new
|
|
381
|
+
throw new _(`alg ${e} is not supported either by JOSE or your javascript runtime`);
|
|
382
382
|
}
|
|
383
383
|
}
|
|
384
384
|
function de(e, t, n) {
|
|
@@ -417,8 +417,8 @@ async function fe(e, t, n) {
|
|
|
417
417
|
let r = {};
|
|
418
418
|
if (e.protected)
|
|
419
419
|
try {
|
|
420
|
-
const
|
|
421
|
-
r = JSON.parse(g.decode(
|
|
420
|
+
const I = C(e.protected);
|
|
421
|
+
r = JSON.parse(g.decode(I));
|
|
422
422
|
} catch {
|
|
423
423
|
throw new d("JWS Protected Header is invalid");
|
|
424
424
|
}
|
|
@@ -452,7 +452,7 @@ async function fe(e, t, n) {
|
|
|
452
452
|
throw new d("Failed to base64url decode the signature");
|
|
453
453
|
}
|
|
454
454
|
if (!await ue(c, t, f, E))
|
|
455
|
-
throw new
|
|
455
|
+
throw new Y();
|
|
456
456
|
let m;
|
|
457
457
|
if (a)
|
|
458
458
|
try {
|
|
@@ -474,7 +474,7 @@ async function he(e, t, n) {
|
|
|
474
474
|
const c = await fe({ payload: o, protected: r, signature: i }, t, n), s = { payload: c.payload, protectedHeader: c.protectedHeader };
|
|
475
475
|
return typeof t == "function" ? { ...s, key: c.key } : s;
|
|
476
476
|
}
|
|
477
|
-
const le = (e) => Math.floor(e.getTime() / 1e3), M = 60, B = M * 60, v = B * 24, pe = v * 7, me = v * 365.25, ye = /^(\+|\-)? ?(\d+|\d+\.\d+) ?(seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)(?: (ago|from now))?$/i,
|
|
477
|
+
const le = (e) => Math.floor(e.getTime() / 1e3), M = 60, B = M * 60, v = B * 24, pe = v * 7, me = v * 365.25, ye = /^(\+|\-)? ?(\d+|\d+\.\d+) ?(seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)(?: (ago|from now))?$/i, N = (e) => {
|
|
478
478
|
const t = ye.exec(e);
|
|
479
479
|
if (!t || t[4] && t[1])
|
|
480
480
|
throw new TypeError("Invalid time period format");
|
|
@@ -517,7 +517,7 @@ const le = (e) => Math.floor(e.getTime() / 1e3), M = 60, B = M * 60, v = B * 24,
|
|
|
517
517
|
break;
|
|
518
518
|
}
|
|
519
519
|
return t[1] === "-" || t[4] === "ago" ? -o : o;
|
|
520
|
-
},
|
|
520
|
+
}, W = (e) => e.toLowerCase().replace(/^application\//, ""), Se = (e, t) => typeof e == "string" ? t.includes(e) : Array.isArray(e) ? t.some(Set.prototype.has.bind(new Set(e))) : !1, Ee = (e, t, n = {}) => {
|
|
521
521
|
let r;
|
|
522
522
|
try {
|
|
523
523
|
r = JSON.parse(g.decode(t));
|
|
@@ -526,7 +526,7 @@ const le = (e) => Math.floor(e.getTime() / 1e3), M = 60, B = M * 60, v = B * 24,
|
|
|
526
526
|
if (!R(r))
|
|
527
527
|
throw new k("JWT Claims Set must be a top-level JSON object");
|
|
528
528
|
const { typ: o } = n;
|
|
529
|
-
if (o && (typeof e.typ != "string" ||
|
|
529
|
+
if (o && (typeof e.typ != "string" || W(e.typ) !== W(o)))
|
|
530
530
|
throw new h('unexpected "typ" JWT header value', r, "typ", "check_failed");
|
|
531
531
|
const { requiredClaims: i = [], issuer: a, subject: c, audience: s, maxTokenAge: l } = n, E = [...i];
|
|
532
532
|
l !== void 0 && E.push("iat"), s !== void 0 && E.push("aud"), c !== void 0 && E.push("sub"), a !== void 0 && E.push("iss");
|
|
@@ -542,7 +542,7 @@ const le = (e) => Math.floor(e.getTime() / 1e3), M = 60, B = M * 60, v = B * 24,
|
|
|
542
542
|
let f;
|
|
543
543
|
switch (typeof n.clockTolerance) {
|
|
544
544
|
case "string":
|
|
545
|
-
f =
|
|
545
|
+
f = N(n.clockTolerance);
|
|
546
546
|
break;
|
|
547
547
|
case "number":
|
|
548
548
|
f = n.clockTolerance;
|
|
@@ -569,8 +569,8 @@ const le = (e) => Math.floor(e.getTime() / 1e3), M = 60, B = M * 60, v = B * 24,
|
|
|
569
569
|
throw new O('"exp" claim timestamp check failed', r, "exp", "check_failed");
|
|
570
570
|
}
|
|
571
571
|
if (l) {
|
|
572
|
-
const u = m - r.iat,
|
|
573
|
-
if (u - f >
|
|
572
|
+
const u = m - r.iat, I = typeof l == "number" ? l : N(l);
|
|
573
|
+
if (u - f > I)
|
|
574
574
|
throw new O('"iat" claim timestamp check failed (too far in the past)', r, "iat", "check_failed");
|
|
575
575
|
if (u < 0 - f)
|
|
576
576
|
throw new h('"iat" claim timestamp check failed (it should be in the past)', r, "iat", "check_failed");
|
|
@@ -595,6 +595,7 @@ const be = {
|
|
|
595
595
|
ALG: "RS256",
|
|
596
596
|
USER_ID_KEY: "_id",
|
|
597
597
|
TOKEN_ID_KEY: "__raw",
|
|
598
|
+
NONCE_KEY: "_nonce",
|
|
598
599
|
ISSUER: "gizmette.com"
|
|
599
600
|
}, Ae = `-----BEGIN PUBLIC KEY-----
|
|
600
601
|
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAsF6i3Jd9fY/3COqCw/m7
|
|
@@ -604,10 +605,10 @@ aMwPFOIcJH+rKfFgNcHLcaS5syp7zU1ANwZ+trgR+DifBr8TLVkBynmNeTyhDm2+
|
|
|
604
605
|
l0haqjMk0UoNPPE8iYBWUHQJJE1Dqstj65d6Eh5g64Pao25y4cmYJbKjiblIGEkE
|
|
605
606
|
sjqybA9mARAqh9k/eiIopecWSiffNQTwVQVd2I9ZH3BalhEXHlqFgrjz51kFqg81
|
|
606
607
|
awIDAQAB
|
|
607
|
-
-----END PUBLIC KEY-----`,
|
|
608
|
+
-----END PUBLIC KEY-----`, _e = {
|
|
608
609
|
ACCESS: "5m",
|
|
609
610
|
ID: "90d"
|
|
610
|
-
},
|
|
611
|
+
}, Ie = async (e, t) => {
|
|
611
612
|
try {
|
|
612
613
|
const n = H.ALG, o = await re(Ae, n);
|
|
613
614
|
return await we(e, o, {
|
|
@@ -623,6 +624,6 @@ export {
|
|
|
623
624
|
ge as HEADERS,
|
|
624
625
|
H as JWT,
|
|
625
626
|
Ae as JWT_PUBLIC_KEY,
|
|
626
|
-
|
|
627
|
-
|
|
627
|
+
_e as TOKEN_EXPIRATION,
|
|
628
|
+
Ie as verifyAndExtractToken
|
|
628
629
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@versini/auth-common",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.6.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Arno Versini",
|
|
6
6
|
"publishConfig": {
|
|
@@ -32,5 +32,5 @@
|
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"jose": "5.4.1"
|
|
34
34
|
},
|
|
35
|
-
"gitHead": "
|
|
35
|
+
"gitHead": "c88e96be92c0d2dcf576d1c71a4971025178ac79"
|
|
36
36
|
}
|