@versini/auth-common 2.12.0 → 2.12.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/index.d.ts +1 -0
- package/dist/index.js +56 -55
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -17,6 +17,7 @@ declare const JWT: {
|
|
|
17
17
|
TOKEN_ID_KEY: string;
|
|
18
18
|
NONCE_KEY: string;
|
|
19
19
|
USERNAME_KEY: string;
|
|
20
|
+
AUTH_TYPE_KEY: string;
|
|
20
21
|
ISSUER: string;
|
|
21
22
|
};
|
|
22
23
|
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.12.
|
|
2
|
+
@versini/auth-common v2.12.1
|
|
3
3
|
© 2024 gizmette.com
|
|
4
4
|
*/
|
|
5
5
|
try {
|
|
6
6
|
window.__VERSINI_AUTH_COMMON__ || (window.__VERSINI_AUTH_COMMON__ = {
|
|
7
|
-
version: "2.12.
|
|
8
|
-
buildTime: "07/15/2024
|
|
7
|
+
version: "2.12.1",
|
|
8
|
+
buildTime: "07/15/2024 10:32 AM EDT",
|
|
9
9
|
homepage: "https://github.com/aversini/auth-client",
|
|
10
10
|
license: "MIT"
|
|
11
11
|
});
|
|
@@ -26,6 +26,7 @@ const Qe = {
|
|
|
26
26
|
TOKEN_ID_KEY: "__raw",
|
|
27
27
|
NONCE_KEY: "_nonce",
|
|
28
28
|
USERNAME_KEY: "username",
|
|
29
|
+
AUTH_TYPE_KEY: "auth_type",
|
|
29
30
|
ISSUER: "gizmette.com"
|
|
30
31
|
}, ne = `-----BEGIN PUBLIC KEY-----
|
|
31
32
|
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAsF6i3Jd9fY/3COqCw/m7
|
|
@@ -43,7 +44,7 @@ awIDAQAB
|
|
|
43
44
|
AUTHENTICATE: "authenticate",
|
|
44
45
|
CODE: "code",
|
|
45
46
|
LOGOUT: "logout"
|
|
46
|
-
},
|
|
47
|
+
}, K = crypto, q = (e) => e instanceof CryptoKey, v = new TextEncoder(), C = new TextDecoder();
|
|
47
48
|
function ae(...e) {
|
|
48
49
|
const t = e.reduce((a, { length: i }) => a + i, 0), r = new Uint8Array(t);
|
|
49
50
|
let n = 0;
|
|
@@ -213,7 +214,7 @@ function ue(e, t, ...r) {
|
|
|
213
214
|
}
|
|
214
215
|
de(e, r);
|
|
215
216
|
}
|
|
216
|
-
function
|
|
217
|
+
function z(e, t, ...r) {
|
|
217
218
|
var n;
|
|
218
219
|
if (r.length > 2) {
|
|
219
220
|
const a = r.pop();
|
|
@@ -221,11 +222,11 @@ function G(e, t, ...r) {
|
|
|
221
222
|
} else r.length === 2 ? e += `one of type ${r[0]} or ${r[1]}.` : e += `of type ${r[0]}.`;
|
|
222
223
|
return t == null ? e += ` Received ${t}` : typeof t == "function" && t.name ? e += ` Received function ${t.name}` : typeof t == "object" && t != null && (n = t.constructor) != null && n.name && (e += ` Received an instance of ${t.constructor.name}`), e;
|
|
223
224
|
}
|
|
224
|
-
const L = (e, ...t) =>
|
|
225
|
-
function
|
|
226
|
-
return
|
|
225
|
+
const L = (e, ...t) => z("Key must be ", e, ...t);
|
|
226
|
+
function G(e, t, ...r) {
|
|
227
|
+
return z(`Key for the ${e} algorithm must be `, t, ...r);
|
|
227
228
|
}
|
|
228
|
-
const Q = (e) =>
|
|
229
|
+
const Q = (e) => q(e) ? !0 : (e == null ? void 0 : e[Symbol.toStringTag]) === "KeyObject", R = ["CryptoKey"], le = (...e) => {
|
|
229
230
|
const t = e.filter(Boolean);
|
|
230
231
|
if (t.length === 0 || t.length === 1)
|
|
231
232
|
return !0;
|
|
@@ -344,7 +345,7 @@ const me = async (e) => {
|
|
|
344
345
|
e.ext ?? !1,
|
|
345
346
|
e.key_ops ?? r
|
|
346
347
|
], a = { ...e };
|
|
347
|
-
return delete a.alg, delete a.use,
|
|
348
|
+
return delete a.alg, delete a.use, K.subtle.importKey("jwk", a, ...n);
|
|
348
349
|
}, X = (e) => b(e);
|
|
349
350
|
let W, J;
|
|
350
351
|
const Z = (e) => (e == null ? void 0 : e[Symbol.toStringTag]) === "KeyObject", j = async (e, t, r, n) => {
|
|
@@ -437,29 +438,29 @@ const Z = (e) => (e == null ? void 0 : e[Symbol.toStringTag]) === "KeyObject", j
|
|
|
437
438
|
default:
|
|
438
439
|
throw new w('Invalid or unsupported "alg" (Algorithm) value');
|
|
439
440
|
}
|
|
440
|
-
return
|
|
441
|
+
return K.subtle.importKey(t, c, i, !1, o);
|
|
441
442
|
}, ge = (e, t, r) => we(/(?:-----(?:BEGIN|END) PUBLIC KEY-----|\s)/g, "spki", e, t);
|
|
442
443
|
async function Ae(e, t, r) {
|
|
443
444
|
if (e.indexOf("-----BEGIN PUBLIC KEY-----") !== 0)
|
|
444
445
|
throw new TypeError('"spki" must be SPKI formatted string');
|
|
445
446
|
return ge(e, t);
|
|
446
447
|
}
|
|
447
|
-
const
|
|
448
|
+
const I = (e) => e == null ? void 0 : e[Symbol.toStringTag], be = (e, t) => {
|
|
448
449
|
if (!(t instanceof Uint8Array)) {
|
|
449
450
|
if (!Q(t))
|
|
450
|
-
throw new TypeError(
|
|
451
|
+
throw new TypeError(G(e, t, ...R, "Uint8Array"));
|
|
451
452
|
if (t.type !== "secret")
|
|
452
|
-
throw new TypeError(`${
|
|
453
|
+
throw new TypeError(`${I(t)} instances for symmetric algorithms must be of type "secret"`);
|
|
453
454
|
}
|
|
454
455
|
}, Ce = (e, t, r) => {
|
|
455
456
|
if (!Q(t))
|
|
456
|
-
throw new TypeError(
|
|
457
|
+
throw new TypeError(G(e, t, ...R));
|
|
457
458
|
if (t.type === "secret")
|
|
458
|
-
throw new TypeError(`${
|
|
459
|
+
throw new TypeError(`${I(t)} instances for asymmetric algorithms must not be of type "secret"`);
|
|
459
460
|
if (t.algorithm && r === "verify" && t.type === "private")
|
|
460
|
-
throw new TypeError(`${
|
|
461
|
+
throw new TypeError(`${I(t)} instances for asymmetric algorithm verifying must be of type "public"`);
|
|
461
462
|
if (t.algorithm && r === "encrypt" && t.type === "private")
|
|
462
|
-
throw new TypeError(`${
|
|
463
|
+
throw new TypeError(`${I(t)} instances for asymmetric algorithm encryption must be of type "public"`);
|
|
463
464
|
}, ve = (e, t, r) => {
|
|
464
465
|
e.startsWith("HS") || e === "dir" || e.startsWith("PBES2") || /^A\d{3}(?:GCM)?KW$/.test(e) ? be(e, t) : Ce(e, t, r);
|
|
465
466
|
};
|
|
@@ -482,13 +483,13 @@ function Te(e, t, r, n, a) {
|
|
|
482
483
|
}
|
|
483
484
|
return new Set(n.crit);
|
|
484
485
|
}
|
|
485
|
-
const
|
|
486
|
+
const _e = (e, t) => {
|
|
486
487
|
if (t !== void 0 && (!Array.isArray(t) || t.some((r) => typeof r != "string")))
|
|
487
488
|
throw new TypeError(`"${e}" option must be an array of strings`);
|
|
488
489
|
if (t)
|
|
489
490
|
return new Set(t);
|
|
490
491
|
};
|
|
491
|
-
function
|
|
492
|
+
function Ie(e, t) {
|
|
492
493
|
const r = `SHA-${e.slice(-3)}`;
|
|
493
494
|
switch (e) {
|
|
494
495
|
case "HS256":
|
|
@@ -513,27 +514,27 @@ function Re(e, t) {
|
|
|
513
514
|
throw new w(`alg ${e} is not supported either by JOSE or your javascript runtime`);
|
|
514
515
|
}
|
|
515
516
|
}
|
|
516
|
-
async function
|
|
517
|
-
if (t = await Ee.normalizePublicKey(t, e),
|
|
517
|
+
async function Re(e, t, r) {
|
|
518
|
+
if (t = await Ee.normalizePublicKey(t, e), q(t))
|
|
518
519
|
return ue(t, e, r), t;
|
|
519
520
|
if (t instanceof Uint8Array) {
|
|
520
521
|
if (!e.startsWith("HS"))
|
|
521
|
-
throw new TypeError(L(t, ...
|
|
522
|
-
return
|
|
522
|
+
throw new TypeError(L(t, ...R));
|
|
523
|
+
return K.subtle.importKey("raw", t, { hash: `SHA-${e.slice(-3)}`, name: "HMAC" }, !1, [r]);
|
|
523
524
|
}
|
|
524
|
-
throw new TypeError(L(t, ...
|
|
525
|
+
throw new TypeError(L(t, ...R, "Uint8Array"));
|
|
525
526
|
}
|
|
526
527
|
const Pe = async (e, t, r, n) => {
|
|
527
|
-
const a = await
|
|
528
|
+
const a = await Re(e, t, "verify");
|
|
528
529
|
he(e, a);
|
|
529
|
-
const i =
|
|
530
|
+
const i = Ie(e, a.algorithm);
|
|
530
531
|
try {
|
|
531
|
-
return await
|
|
532
|
+
return await K.subtle.verify(i, a, r, n);
|
|
532
533
|
} catch {
|
|
533
534
|
return !1;
|
|
534
535
|
}
|
|
535
536
|
};
|
|
536
|
-
async function
|
|
537
|
+
async function Ke(e, t, r) {
|
|
537
538
|
if (!P(e))
|
|
538
539
|
throw new u("Flattened JWS must be an object");
|
|
539
540
|
if (e.protected === void 0 && e.header === void 0)
|
|
@@ -549,8 +550,8 @@ async function xe(e, t, r) {
|
|
|
549
550
|
let n = {};
|
|
550
551
|
if (e.protected)
|
|
551
552
|
try {
|
|
552
|
-
const
|
|
553
|
-
n = JSON.parse(C.decode(
|
|
553
|
+
const x = b(e.protected);
|
|
554
|
+
n = JSON.parse(C.decode(x));
|
|
554
555
|
} catch {
|
|
555
556
|
throw new u("JWS Protected Header is invalid");
|
|
556
557
|
}
|
|
@@ -566,7 +567,7 @@ async function xe(e, t, r) {
|
|
|
566
567
|
const { alg: c } = a;
|
|
567
568
|
if (typeof c != "string" || !c)
|
|
568
569
|
throw new u('JWS "alg" (Algorithm) Header Parameter missing or invalid');
|
|
569
|
-
const s = r &&
|
|
570
|
+
const s = r && _e("algorithms", r.algorithms);
|
|
570
571
|
if (s && !s.has(c))
|
|
571
572
|
throw new ie('"alg" (Algorithm) Header Parameter value not allowed');
|
|
572
573
|
if (o) {
|
|
@@ -596,17 +597,17 @@ async function xe(e, t, r) {
|
|
|
596
597
|
const l = { payload: y };
|
|
597
598
|
return e.protected !== void 0 && (l.protectedHeader = n), e.header !== void 0 && (l.unprotectedHeader = e.header), p ? { ...l, key: t } : l;
|
|
598
599
|
}
|
|
599
|
-
async function
|
|
600
|
+
async function xe(e, t, r) {
|
|
600
601
|
if (e instanceof Uint8Array && (e = C.decode(e)), typeof e != "string")
|
|
601
602
|
throw new u("Compact JWS must be a string or Uint8Array");
|
|
602
603
|
const { 0: n, 1: a, 2: i, length: o } = e.split(".");
|
|
603
604
|
if (o !== 3)
|
|
604
605
|
throw new u("Invalid Compact JWS");
|
|
605
|
-
const c = await
|
|
606
|
+
const c = await Ke({ payload: a, protected: n, signature: i }, t, r), s = { payload: c.payload, protectedHeader: c.protectedHeader };
|
|
606
607
|
return typeof t == "function" ? { ...s, key: c.key } : s;
|
|
607
608
|
}
|
|
608
|
-
const Oe = (e) => Math.floor(e.getTime() / 1e3), ee = 60, te = ee * 60,
|
|
609
|
-
const t =
|
|
609
|
+
const Oe = (e) => Math.floor(e.getTime() / 1e3), ee = 60, te = ee * 60, D = te * 24, We = D * 7, Je = D * 365.25, He = /^(\+|\-)? ?(\d+|\d+\.\d+) ?(seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)(?: (ago|from now))?$/i, k = (e) => {
|
|
610
|
+
const t = He.exec(e);
|
|
610
611
|
if (!t || t[4] && t[1])
|
|
611
612
|
throw new TypeError("Invalid time period format");
|
|
612
613
|
const r = parseFloat(t[2]), n = t[3].toLowerCase();
|
|
@@ -636,7 +637,7 @@ const Oe = (e) => Math.floor(e.getTime() / 1e3), ee = 60, te = ee * 60, H = te *
|
|
|
636
637
|
case "day":
|
|
637
638
|
case "days":
|
|
638
639
|
case "d":
|
|
639
|
-
a = Math.round(r *
|
|
640
|
+
a = Math.round(r * D);
|
|
640
641
|
break;
|
|
641
642
|
case "week":
|
|
642
643
|
case "weeks":
|
|
@@ -648,7 +649,7 @@ const Oe = (e) => Math.floor(e.getTime() / 1e3), ee = 60, te = ee * 60, H = te *
|
|
|
648
649
|
break;
|
|
649
650
|
}
|
|
650
651
|
return t[1] === "-" || t[4] === "ago" ? -a : a;
|
|
651
|
-
}, V = (e) => e.toLowerCase().replace(/^application\//, ""),
|
|
652
|
+
}, V = (e) => e.toLowerCase().replace(/^application\//, ""), De = (e, t) => typeof e == "string" ? t.includes(e) : Array.isArray(e) ? t.some(Set.prototype.has.bind(new Set(e))) : !1, Ue = (e, t, r = {}) => {
|
|
652
653
|
let n;
|
|
653
654
|
try {
|
|
654
655
|
n = JSON.parse(C.decode(t));
|
|
@@ -668,7 +669,7 @@ const Oe = (e) => Math.floor(e.getTime() / 1e3), ee = 60, te = ee * 60, H = te *
|
|
|
668
669
|
throw new h('unexpected "iss" claim value', n, "iss", "check_failed");
|
|
669
670
|
if (c && n.sub !== c)
|
|
670
671
|
throw new h('unexpected "sub" claim value', n, "sub", "check_failed");
|
|
671
|
-
if (s && !
|
|
672
|
+
if (s && !De(n.aud, typeof s == "string" ? [s] : s))
|
|
672
673
|
throw new h('unexpected "aud" claim value', n, "aud", "check_failed");
|
|
673
674
|
let f;
|
|
674
675
|
switch (typeof r.clockTolerance) {
|
|
@@ -700,8 +701,8 @@ const Oe = (e) => Math.floor(e.getTime() / 1e3), ee = 60, te = ee * 60, H = te *
|
|
|
700
701
|
throw new $('"exp" claim timestamp check failed', n, "exp", "check_failed");
|
|
701
702
|
}
|
|
702
703
|
if (p) {
|
|
703
|
-
const l = y - n.iat,
|
|
704
|
-
if (l - f >
|
|
704
|
+
const l = y - n.iat, x = typeof p == "number" ? p : k(p);
|
|
705
|
+
if (l - f > x)
|
|
705
706
|
throw new $('"iat" claim timestamp check failed (too far in the past)', n, "iat", "check_failed");
|
|
706
707
|
if (l < 0 - f)
|
|
707
708
|
throw new h('"iat" claim timestamp check failed (it should be in the past)', n, "iat", "check_failed");
|
|
@@ -710,7 +711,7 @@ const Oe = (e) => Math.floor(e.getTime() / 1e3), ee = 60, te = ee * 60, H = te *
|
|
|
710
711
|
};
|
|
711
712
|
async function Ne(e, t, r) {
|
|
712
713
|
var o;
|
|
713
|
-
const n = await
|
|
714
|
+
const n = await xe(e, t, r);
|
|
714
715
|
if ((o = n.protectedHeader.crit) != null && o.includes("b64") && n.protectedHeader.b64 === !1)
|
|
715
716
|
throw new S("JWTs MUST NOT use unencoded payload");
|
|
716
717
|
const i = { payload: Ue(n.protectedHeader, n.payload, r), protectedHeader: n.protectedHeader };
|
|
@@ -760,16 +761,16 @@ const et = async (e) => {
|
|
|
760
761
|
}
|
|
761
762
|
};
|
|
762
763
|
var d = [];
|
|
763
|
-
for (var
|
|
764
|
-
d.push((
|
|
764
|
+
for (var H = 0; H < 256; ++H)
|
|
765
|
+
d.push((H + 256).toString(16).slice(1));
|
|
765
766
|
function Me(e, t = 0) {
|
|
766
767
|
return (d[e[t + 0]] + d[e[t + 1]] + d[e[t + 2]] + d[e[t + 3]] + "-" + d[e[t + 4]] + d[e[t + 5]] + "-" + d[e[t + 6]] + d[e[t + 7]] + "-" + d[e[t + 8]] + d[e[t + 9]] + "-" + d[e[t + 10]] + d[e[t + 11]] + d[e[t + 12]] + d[e[t + 13]] + d[e[t + 14]] + d[e[t + 15]]).toLowerCase();
|
|
767
768
|
}
|
|
768
|
-
var
|
|
769
|
+
var _, ke = new Uint8Array(16);
|
|
769
770
|
function Ve() {
|
|
770
|
-
if (!
|
|
771
|
+
if (!_ && (_ = typeof crypto < "u" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto), !_))
|
|
771
772
|
throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
|
|
772
|
-
return
|
|
773
|
+
return _(ke);
|
|
773
774
|
}
|
|
774
775
|
var Be = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto);
|
|
775
776
|
const B = {
|
|
@@ -782,16 +783,16 @@ function F(e, t, r) {
|
|
|
782
783
|
var n = e.random || (e.rng || Ve)();
|
|
783
784
|
return n[6] = n[6] & 15 | 64, n[8] = n[8] & 63 | 128, Me(n);
|
|
784
785
|
}
|
|
785
|
-
const
|
|
786
|
+
const Y = globalThis.crypto, Fe = (e) => `${F()}${F()}`.slice(0, e), Ye = (e) => btoa(
|
|
786
787
|
[...new Uint8Array(e)].map((t) => String.fromCharCode(t)).join("")
|
|
787
788
|
);
|
|
788
789
|
async function re(e) {
|
|
789
|
-
if (!
|
|
790
|
+
if (!Y.subtle)
|
|
790
791
|
throw new Error(
|
|
791
792
|
"crypto.subtle is available only in secure contexts (HTTPS)."
|
|
792
793
|
);
|
|
793
|
-
const t = new TextEncoder().encode(e), r = await
|
|
794
|
-
return
|
|
794
|
+
const t = new TextEncoder().encode(e), r = await Y.subtle.digest("SHA-256", t);
|
|
795
|
+
return Ye(r).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
795
796
|
}
|
|
796
797
|
async function rt(e) {
|
|
797
798
|
const t = e || 43;
|
|
@@ -806,13 +807,13 @@ async function rt(e) {
|
|
|
806
807
|
async function nt(e, t) {
|
|
807
808
|
return t === await re(e);
|
|
808
809
|
}
|
|
809
|
-
const
|
|
810
|
+
const qe = /^Bearer (.+)$/i, ze = (e) => {
|
|
810
811
|
if (typeof e.authorization != "string")
|
|
811
812
|
return;
|
|
812
|
-
const t = e.authorization.match(
|
|
813
|
+
const t = e.authorization.match(qe);
|
|
813
814
|
if (t)
|
|
814
815
|
return t[1];
|
|
815
|
-
},
|
|
816
|
+
}, Ge = (e, t) => {
|
|
816
817
|
const r = e.cookie, n = new RegExp(`auth.${t}=(.+?)(?:;|$)`);
|
|
817
818
|
if (typeof r != "string")
|
|
818
819
|
return;
|
|
@@ -820,7 +821,7 @@ const ze = /^Bearer (.+)$/i, Ge = (e) => {
|
|
|
820
821
|
if (a)
|
|
821
822
|
return a[1];
|
|
822
823
|
}, at = (e, t) => {
|
|
823
|
-
const r =
|
|
824
|
+
const r = ze(e), n = Ge(e, t);
|
|
824
825
|
return !n && !r ? "" : n || r;
|
|
825
826
|
};
|
|
826
827
|
export {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@versini/auth-common",
|
|
3
|
-
"version": "2.12.
|
|
3
|
+
"version": "2.12.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Arno Versini",
|
|
6
6
|
"publishConfig": {
|
|
@@ -36,5 +36,5 @@
|
|
|
36
36
|
"jose": "5.6.3",
|
|
37
37
|
"uuid": "10.0.0"
|
|
38
38
|
},
|
|
39
|
-
"gitHead": "
|
|
39
|
+
"gitHead": "a85e00ff8943fae7d4160f582b030962fa68472d"
|
|
40
40
|
}
|