@versini/auth-common 2.8.0 → 2.9.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 +34 -33
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,24 +1,25 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
@versini/auth-common v2.
|
|
2
|
+
@versini/auth-common v2.9.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.9.0",
|
|
8
|
+
buildTime: "06/28/2024 09:16 AM EDT",
|
|
9
9
|
homepage: "https://github.com/aversini/auth-client",
|
|
10
10
|
license: "MIT"
|
|
11
11
|
});
|
|
12
12
|
} catch {
|
|
13
13
|
}
|
|
14
|
-
const
|
|
14
|
+
const Ue = {
|
|
15
15
|
ID_TOKEN: "id_token",
|
|
16
16
|
ACCESS_TOKEN: "token",
|
|
17
17
|
ID_AND_ACCESS_TOKEN: "id_token token",
|
|
18
|
-
CODE: "code"
|
|
18
|
+
CODE: "code",
|
|
19
|
+
REFRESH_TOKEN: "refresh_token"
|
|
19
20
|
}, De = {
|
|
20
21
|
CLIENT_ID: "X-Auth-ClientId"
|
|
21
|
-
},
|
|
22
|
+
}, U = {
|
|
22
23
|
ALG: "RS256",
|
|
23
24
|
USER_ID_KEY: "sub",
|
|
24
25
|
TOKEN_ID_KEY: "__raw",
|
|
@@ -341,14 +342,14 @@ async function ue(e, t, n) {
|
|
|
341
342
|
throw new TypeError('"spki" must be SPKI formatted string');
|
|
342
343
|
return de(e, t);
|
|
343
344
|
}
|
|
344
|
-
const
|
|
345
|
+
const fe = (e, t) => {
|
|
345
346
|
if (!(t instanceof Uint8Array)) {
|
|
346
347
|
if (!Y(t))
|
|
347
348
|
throw new TypeError(G(e, t, ...E, "Uint8Array"));
|
|
348
349
|
if (t.type !== "secret")
|
|
349
350
|
throw new TypeError(`${E.join(" or ")} instances for symmetric algorithms must be of type "secret"`);
|
|
350
351
|
}
|
|
351
|
-
},
|
|
352
|
+
}, le = (e, t, n) => {
|
|
352
353
|
if (!Y(t))
|
|
353
354
|
throw new TypeError(G(e, t, ...E));
|
|
354
355
|
if (t.type === "secret")
|
|
@@ -358,7 +359,7 @@ const le = (e, t) => {
|
|
|
358
359
|
if (t.algorithm && n === "encrypt" && t.type === "private")
|
|
359
360
|
throw new TypeError(`${E.join(" or ")} instances for asymmetric algorithm encryption must be of type "public"`);
|
|
360
361
|
}, he = (e, t, n) => {
|
|
361
|
-
e.startsWith("HS") || e === "dir" || e.startsWith("PBES2") || /^A\d{3}(?:GCM)?KW$/.test(e) ?
|
|
362
|
+
e.startsWith("HS") || e === "dir" || e.startsWith("PBES2") || /^A\d{3}(?:GCM)?KW$/.test(e) ? fe(e, t) : le(e, t, n);
|
|
362
363
|
};
|
|
363
364
|
function pe(e, t, n, r, o) {
|
|
364
365
|
if (o.crit !== void 0 && (r == null ? void 0 : r.crit) === void 0)
|
|
@@ -474,13 +475,13 @@ async function we(e, t, n) {
|
|
|
474
475
|
let p = !1;
|
|
475
476
|
typeof t == "function" && (t = await t(r, e), p = !0), he(c, t, "verify");
|
|
476
477
|
const w = j(g.encode(e.protected ?? ""), g.encode("."), typeof e.payload == "string" ? g.encode(e.payload) : e.payload);
|
|
477
|
-
let
|
|
478
|
+
let l;
|
|
478
479
|
try {
|
|
479
|
-
|
|
480
|
+
l = R(e.signature);
|
|
480
481
|
} catch {
|
|
481
482
|
throw new u("Failed to base64url decode the signature");
|
|
482
483
|
}
|
|
483
|
-
if (!await Ee(c, t,
|
|
484
|
+
if (!await Ee(c, t, l, w))
|
|
484
485
|
throw new te();
|
|
485
486
|
let y;
|
|
486
487
|
if (a)
|
|
@@ -491,8 +492,8 @@ async function we(e, t, n) {
|
|
|
491
492
|
}
|
|
492
493
|
else
|
|
493
494
|
typeof e.payload == "string" ? y = g.encode(e.payload) : y = e.payload;
|
|
494
|
-
const
|
|
495
|
-
return e.protected !== void 0 && (
|
|
495
|
+
const f = { payload: y };
|
|
496
|
+
return e.protected !== void 0 && (f.protectedHeader = r), e.header !== void 0 && (f.unprotectedHeader = e.header), p ? { ...f, key: t } : f;
|
|
496
497
|
}
|
|
497
498
|
async function be(e, t, n) {
|
|
498
499
|
if (e instanceof Uint8Array && (e = _.decode(e)), typeof e != "string")
|
|
@@ -559,49 +560,49 @@ const ge = (e) => Math.floor(e.getTime() / 1e3), q = 60, z = q * 60, J = z * 24,
|
|
|
559
560
|
throw new h('unexpected "typ" JWT header value', r, "typ", "check_failed");
|
|
560
561
|
const { requiredClaims: i = [], issuer: a, subject: c, audience: s, maxTokenAge: p } = n, w = [...i];
|
|
561
562
|
p !== void 0 && w.push("iat"), s !== void 0 && w.push("aud"), c !== void 0 && w.push("sub"), a !== void 0 && w.push("iss");
|
|
562
|
-
for (const
|
|
563
|
-
if (!(
|
|
564
|
-
throw new h(`missing required "${
|
|
563
|
+
for (const f of new Set(w.reverse()))
|
|
564
|
+
if (!(f in r))
|
|
565
|
+
throw new h(`missing required "${f}" claim`, r, f, "missing");
|
|
565
566
|
if (a && !(Array.isArray(a) ? a : [a]).includes(r.iss))
|
|
566
567
|
throw new h('unexpected "iss" claim value', r, "iss", "check_failed");
|
|
567
568
|
if (c && r.sub !== c)
|
|
568
569
|
throw new h('unexpected "sub" claim value', r, "sub", "check_failed");
|
|
569
570
|
if (s && !Ce(r.aud, typeof s == "string" ? [s] : s))
|
|
570
571
|
throw new h('unexpected "aud" claim value', r, "aud", "check_failed");
|
|
571
|
-
let
|
|
572
|
+
let l;
|
|
572
573
|
switch (typeof n.clockTolerance) {
|
|
573
574
|
case "string":
|
|
574
|
-
|
|
575
|
+
l = W(n.clockTolerance);
|
|
575
576
|
break;
|
|
576
577
|
case "number":
|
|
577
|
-
|
|
578
|
+
l = n.clockTolerance;
|
|
578
579
|
break;
|
|
579
580
|
case "undefined":
|
|
580
|
-
|
|
581
|
+
l = 0;
|
|
581
582
|
break;
|
|
582
583
|
default:
|
|
583
584
|
throw new TypeError("Invalid clockTolerance option type");
|
|
584
585
|
}
|
|
585
|
-
const { currentDate:
|
|
586
|
+
const { currentDate: K } = n, y = ge(K || /* @__PURE__ */ new Date());
|
|
586
587
|
if ((r.iat !== void 0 || p) && typeof r.iat != "number")
|
|
587
588
|
throw new h('"iat" claim must be a number', r, "iat", "invalid");
|
|
588
589
|
if (r.nbf !== void 0) {
|
|
589
590
|
if (typeof r.nbf != "number")
|
|
590
591
|
throw new h('"nbf" claim must be a number', r, "nbf", "invalid");
|
|
591
|
-
if (r.nbf > y +
|
|
592
|
+
if (r.nbf > y + l)
|
|
592
593
|
throw new h('"nbf" claim timestamp check failed', r, "nbf", "check_failed");
|
|
593
594
|
}
|
|
594
595
|
if (r.exp !== void 0) {
|
|
595
596
|
if (typeof r.exp != "number")
|
|
596
597
|
throw new h('"exp" claim must be a number', r, "exp", "invalid");
|
|
597
|
-
if (r.exp <= y -
|
|
598
|
+
if (r.exp <= y - l)
|
|
598
599
|
throw new D('"exp" claim timestamp check failed', r, "exp", "check_failed");
|
|
599
600
|
}
|
|
600
601
|
if (p) {
|
|
601
|
-
const
|
|
602
|
-
if (
|
|
602
|
+
const f = y - r.iat, T = typeof p == "number" ? p : W(p);
|
|
603
|
+
if (f - l > T)
|
|
603
604
|
throw new D('"iat" claim timestamp check failed (too far in the past)', r, "iat", "check_failed");
|
|
604
|
-
if (
|
|
605
|
+
if (f < 0 - l)
|
|
605
606
|
throw new h('"iat" claim timestamp check failed (it should be in the past)', r, "iat", "check_failed");
|
|
606
607
|
}
|
|
607
608
|
return r;
|
|
@@ -616,9 +617,9 @@ async function Re(e, t, n) {
|
|
|
616
617
|
}
|
|
617
618
|
const We = async (e) => {
|
|
618
619
|
try {
|
|
619
|
-
const t =
|
|
620
|
+
const t = U.ALG, r = await ue(X, t);
|
|
620
621
|
return await Re(e, r, {
|
|
621
|
-
issuer:
|
|
622
|
+
issuer: U.ISSUER
|
|
622
623
|
});
|
|
623
624
|
} catch {
|
|
624
625
|
return;
|
|
@@ -647,7 +648,7 @@ function k(e, t, n) {
|
|
|
647
648
|
var r = e.random || (e.rng || xe)();
|
|
648
649
|
return r[6] = r[6] & 15 | 64, r[8] = r[8] & 63 | 128, ve(r);
|
|
649
650
|
}
|
|
650
|
-
const M = globalThis.crypto, Je = (e) => `${k()}${k()}`.slice(0, e),
|
|
651
|
+
const M = globalThis.crypto, Je = (e) => `${k()}${k()}`.slice(0, e), Ke = (e) => btoa(
|
|
651
652
|
[...new Uint8Array(e)].map((t) => String.fromCharCode(t)).join("")
|
|
652
653
|
);
|
|
653
654
|
async function Q(e) {
|
|
@@ -656,7 +657,7 @@ async function Q(e) {
|
|
|
656
657
|
"crypto.subtle is available only in secure contexts (HTTPS)."
|
|
657
658
|
);
|
|
658
659
|
const t = new TextEncoder().encode(e), n = await M.subtle.digest("SHA-256", t);
|
|
659
|
-
return
|
|
660
|
+
return Ke(n).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
660
661
|
}
|
|
661
662
|
async function $e(e) {
|
|
662
663
|
const t = e || 43;
|
|
@@ -673,9 +674,9 @@ async function Le(e, t) {
|
|
|
673
674
|
}
|
|
674
675
|
export {
|
|
675
676
|
Ne as API_TYPE,
|
|
676
|
-
|
|
677
|
+
Ue as AUTH_TYPES,
|
|
677
678
|
De as HEADERS,
|
|
678
|
-
|
|
679
|
+
U as JWT,
|
|
679
680
|
X as JWT_PUBLIC_KEY,
|
|
680
681
|
He as TOKEN_EXPIRATION,
|
|
681
682
|
Q as generateCodeChallenge,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@versini/auth-common",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.9.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Arno Versini",
|
|
6
6
|
"publishConfig": {
|
|
@@ -35,5 +35,5 @@
|
|
|
35
35
|
"jose": "5.4.1",
|
|
36
36
|
"uuid": "10.0.0"
|
|
37
37
|
},
|
|
38
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "48c8a3b48dc2d614be43f407e6c72fd433530afc"
|
|
39
39
|
}
|