@versini/auth-common 2.7.1 → 2.8.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 +46 -45
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
@versini/auth-common v2.
|
|
2
|
+
@versini/auth-common v2.8.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/27/2024
|
|
7
|
+
version: "2.8.0",
|
|
8
|
+
buildTime: "06/27/2024 06:57 PM EDT",
|
|
9
9
|
homepage: "https://github.com/aversini/auth-client",
|
|
10
10
|
license: "MIT"
|
|
11
11
|
});
|
|
@@ -20,7 +20,7 @@ const Ke = {
|
|
|
20
20
|
CLIENT_ID: "X-Auth-ClientId"
|
|
21
21
|
}, K = {
|
|
22
22
|
ALG: "RS256",
|
|
23
|
-
USER_ID_KEY: "
|
|
23
|
+
USER_ID_KEY: "sub",
|
|
24
24
|
TOKEN_ID_KEY: "__raw",
|
|
25
25
|
NONCE_KEY: "_nonce",
|
|
26
26
|
ISSUER: "gizmette.com"
|
|
@@ -32,14 +32,15 @@ aMwPFOIcJH+rKfFgNcHLcaS5syp7zU1ANwZ+trgR+DifBr8TLVkBynmNeTyhDm2+
|
|
|
32
32
|
l0haqjMk0UoNPPE8iYBWUHQJJE1Dqstj65d6Eh5g64Pao25y4cmYJbKjiblIGEkE
|
|
33
33
|
sjqybA9mARAqh9k/eiIopecWSiffNQTwVQVd2I9ZH3BalhEXHlqFgrjz51kFqg81
|
|
34
34
|
awIDAQAB
|
|
35
|
-
-----END PUBLIC KEY-----`,
|
|
35
|
+
-----END PUBLIC KEY-----`, He = {
|
|
36
36
|
ACCESS: "5m",
|
|
37
|
-
ID: "90d"
|
|
38
|
-
|
|
37
|
+
ID: "90d",
|
|
38
|
+
REFRESH: "90d"
|
|
39
|
+
}, Ne = {
|
|
39
40
|
AUTHENTICATE: "authenticate",
|
|
40
41
|
CODE: "code",
|
|
41
42
|
LOGOUT: "logout"
|
|
42
|
-
}, O = crypto, V = (e) => e instanceof CryptoKey, g = new TextEncoder(),
|
|
43
|
+
}, O = crypto, V = (e) => e instanceof CryptoKey, g = new TextEncoder(), _ = new TextDecoder();
|
|
43
44
|
function j(...e) {
|
|
44
45
|
const t = e.reduce((o, { length: i }) => o + i, 0), n = new Uint8Array(t);
|
|
45
46
|
let r = 0;
|
|
@@ -54,7 +55,7 @@ const Z = (e) => {
|
|
|
54
55
|
return n;
|
|
55
56
|
}, R = (e) => {
|
|
56
57
|
let t = e;
|
|
57
|
-
t instanceof Uint8Array && (t =
|
|
58
|
+
t instanceof Uint8Array && (t = _.decode(t)), t = t.replace(/-/g, "+").replace(/_/g, "/").replace(/\s/g, "");
|
|
58
59
|
try {
|
|
59
60
|
return Z(t);
|
|
60
61
|
} catch {
|
|
@@ -94,7 +95,7 @@ class ee extends b {
|
|
|
94
95
|
return "ERR_JOSE_ALG_NOT_ALLOWED";
|
|
95
96
|
}
|
|
96
97
|
}
|
|
97
|
-
class
|
|
98
|
+
class C extends b {
|
|
98
99
|
constructor() {
|
|
99
100
|
super(...arguments), this.code = "ERR_JOSE_NOT_SUPPORTED";
|
|
100
101
|
}
|
|
@@ -219,11 +220,11 @@ function F(e, t, ...n) {
|
|
|
219
220
|
n.length === 2 ? e += `one of type ${n[0]} or ${n[1]}.` : e += `of type ${n[0]}.`;
|
|
220
221
|
return t == null ? e += ` Received ${t}` : typeof t == "function" && t.name ? e += ` Received function ${t.name}` : typeof t == "object" && t != null && (r = t.constructor) != null && r.name && (e += ` Received an instance of ${t.constructor.name}`), e;
|
|
221
222
|
}
|
|
222
|
-
const
|
|
223
|
+
const H = (e, ...t) => F("Key must be ", e, ...t);
|
|
223
224
|
function G(e, t, ...n) {
|
|
224
225
|
return F(`Key for the ${e} algorithm must be `, t, ...n);
|
|
225
226
|
}
|
|
226
|
-
const Y = (e) => V(e),
|
|
227
|
+
const Y = (e) => V(e), E = ["CryptoKey"], ae = (...e) => {
|
|
227
228
|
const t = e.filter(Boolean);
|
|
228
229
|
if (t.length === 0 || t.length === 1)
|
|
229
230
|
return !0;
|
|
@@ -268,7 +269,7 @@ const ce = (e, t) => {
|
|
|
268
269
|
return !1;
|
|
269
270
|
const o = e.subarray(r, r + t.length);
|
|
270
271
|
return o.length !== t.length ? !1 : o.every((i, a) => i === t[a]) || S(e, t, r + 1);
|
|
271
|
-
},
|
|
272
|
+
}, N = (e) => {
|
|
272
273
|
switch (!0) {
|
|
273
274
|
case S(e, [42, 134, 72, 206, 61, 3, 1, 7]):
|
|
274
275
|
return "P-256";
|
|
@@ -285,7 +286,7 @@ const ce = (e, t) => {
|
|
|
285
286
|
case S(e, [43, 101, 113]):
|
|
286
287
|
return "Ed448";
|
|
287
288
|
default:
|
|
288
|
-
throw new
|
|
289
|
+
throw new C("Invalid or unsupported EC Key Curve or OKP Key Sub Type");
|
|
289
290
|
}
|
|
290
291
|
}, se = async (e, t, n, r, o) => {
|
|
291
292
|
let i, a;
|
|
@@ -323,15 +324,15 @@ const ce = (e, t) => {
|
|
|
323
324
|
case "ECDH-ES+A128KW":
|
|
324
325
|
case "ECDH-ES+A192KW":
|
|
325
326
|
case "ECDH-ES+A256KW": {
|
|
326
|
-
const s =
|
|
327
|
+
const s = N(c);
|
|
327
328
|
i = s.startsWith("P-") ? { name: "ECDH", namedCurve: s } : { name: s }, a = [];
|
|
328
329
|
break;
|
|
329
330
|
}
|
|
330
331
|
case "EdDSA":
|
|
331
|
-
i = { name:
|
|
332
|
+
i = { name: N(c) }, a = ["verify"];
|
|
332
333
|
break;
|
|
333
334
|
default:
|
|
334
|
-
throw new
|
|
335
|
+
throw new C('Invalid or unsupported "alg" (Algorithm) value');
|
|
335
336
|
}
|
|
336
337
|
return O.subtle.importKey(t, c, i, !1, a);
|
|
337
338
|
}, de = (e, t, n) => se(/(?:-----(?:BEGIN|END) PUBLIC KEY-----|\s)/g, "spki", e, t);
|
|
@@ -343,19 +344,19 @@ async function ue(e, t, n) {
|
|
|
343
344
|
const le = (e, t) => {
|
|
344
345
|
if (!(t instanceof Uint8Array)) {
|
|
345
346
|
if (!Y(t))
|
|
346
|
-
throw new TypeError(G(e, t, ...
|
|
347
|
+
throw new TypeError(G(e, t, ...E, "Uint8Array"));
|
|
347
348
|
if (t.type !== "secret")
|
|
348
|
-
throw new TypeError(`${
|
|
349
|
+
throw new TypeError(`${E.join(" or ")} instances for symmetric algorithms must be of type "secret"`);
|
|
349
350
|
}
|
|
350
351
|
}, fe = (e, t, n) => {
|
|
351
352
|
if (!Y(t))
|
|
352
|
-
throw new TypeError(G(e, t, ...
|
|
353
|
+
throw new TypeError(G(e, t, ...E));
|
|
353
354
|
if (t.type === "secret")
|
|
354
|
-
throw new TypeError(`${
|
|
355
|
+
throw new TypeError(`${E.join(" or ")} instances for asymmetric algorithms must not be of type "secret"`);
|
|
355
356
|
if (t.algorithm && n === "verify" && t.type === "private")
|
|
356
|
-
throw new TypeError(`${
|
|
357
|
+
throw new TypeError(`${E.join(" or ")} instances for asymmetric algorithm verifying must be of type "public"`);
|
|
357
358
|
if (t.algorithm && n === "encrypt" && t.type === "private")
|
|
358
|
-
throw new TypeError(`${
|
|
359
|
+
throw new TypeError(`${E.join(" or ")} instances for asymmetric algorithm encryption must be of type "public"`);
|
|
359
360
|
}, he = (e, t, n) => {
|
|
360
361
|
e.startsWith("HS") || e === "dir" || e.startsWith("PBES2") || /^A\d{3}(?:GCM)?KW$/.test(e) ? le(e, t) : fe(e, t, n);
|
|
361
362
|
};
|
|
@@ -370,7 +371,7 @@ function pe(e, t, n, r, o) {
|
|
|
370
371
|
n !== void 0 ? i = new Map([...Object.entries(n), ...t.entries()]) : i = t;
|
|
371
372
|
for (const a of r.crit) {
|
|
372
373
|
if (!i.has(a))
|
|
373
|
-
throw new
|
|
374
|
+
throw new C(`Extension Header Parameter "${a}" is not recognized`);
|
|
374
375
|
if (o[a] === void 0)
|
|
375
376
|
throw new e(`Extension Header Parameter "${a}" is missing`);
|
|
376
377
|
if (i.get(a) && r[a] === void 0)
|
|
@@ -406,7 +407,7 @@ function ye(e, t) {
|
|
|
406
407
|
case "EdDSA":
|
|
407
408
|
return { name: t.name };
|
|
408
409
|
default:
|
|
409
|
-
throw new
|
|
410
|
+
throw new C(`alg ${e} is not supported either by JOSE or your javascript runtime`);
|
|
410
411
|
}
|
|
411
412
|
}
|
|
412
413
|
function Se(e, t, n) {
|
|
@@ -414,12 +415,12 @@ function Se(e, t, n) {
|
|
|
414
415
|
return oe(t, e, n), t;
|
|
415
416
|
if (t instanceof Uint8Array) {
|
|
416
417
|
if (!e.startsWith("HS"))
|
|
417
|
-
throw new TypeError(
|
|
418
|
+
throw new TypeError(H(t, ...E));
|
|
418
419
|
return O.subtle.importKey("raw", t, { hash: `SHA-${e.slice(-3)}`, name: "HMAC" }, !1, [n]);
|
|
419
420
|
}
|
|
420
|
-
throw new TypeError(
|
|
421
|
+
throw new TypeError(H(t, ...E, "Uint8Array"));
|
|
421
422
|
}
|
|
422
|
-
const
|
|
423
|
+
const Ee = async (e, t, n, r) => {
|
|
423
424
|
const o = await Se(e, t, "verify");
|
|
424
425
|
ce(e, o);
|
|
425
426
|
const i = ye(e, o.algorithm);
|
|
@@ -429,7 +430,7 @@ const we = async (e, t, n, r) => {
|
|
|
429
430
|
return !1;
|
|
430
431
|
}
|
|
431
432
|
};
|
|
432
|
-
async function
|
|
433
|
+
async function we(e, t, n) {
|
|
433
434
|
if (!x(e))
|
|
434
435
|
throw new u("Flattened JWS must be an object");
|
|
435
436
|
if (e.protected === void 0 && e.header === void 0)
|
|
@@ -446,7 +447,7 @@ async function Ee(e, t, n) {
|
|
|
446
447
|
if (e.protected)
|
|
447
448
|
try {
|
|
448
449
|
const T = R(e.protected);
|
|
449
|
-
r = JSON.parse(
|
|
450
|
+
r = JSON.parse(_.decode(T));
|
|
450
451
|
} catch {
|
|
451
452
|
throw new u("JWS Protected Header is invalid");
|
|
452
453
|
}
|
|
@@ -472,14 +473,14 @@ async function Ee(e, t, n) {
|
|
|
472
473
|
throw new u("JWS Payload must be a string or an Uint8Array instance");
|
|
473
474
|
let p = !1;
|
|
474
475
|
typeof t == "function" && (t = await t(r, e), p = !0), he(c, t, "verify");
|
|
475
|
-
const
|
|
476
|
+
const w = j(g.encode(e.protected ?? ""), g.encode("."), typeof e.payload == "string" ? g.encode(e.payload) : e.payload);
|
|
476
477
|
let f;
|
|
477
478
|
try {
|
|
478
479
|
f = R(e.signature);
|
|
479
480
|
} catch {
|
|
480
481
|
throw new u("Failed to base64url decode the signature");
|
|
481
482
|
}
|
|
482
|
-
if (!await
|
|
483
|
+
if (!await Ee(c, t, f, w))
|
|
483
484
|
throw new te();
|
|
484
485
|
let y;
|
|
485
486
|
if (a)
|
|
@@ -494,16 +495,16 @@ async function Ee(e, t, n) {
|
|
|
494
495
|
return e.protected !== void 0 && (l.protectedHeader = r), e.header !== void 0 && (l.unprotectedHeader = e.header), p ? { ...l, key: t } : l;
|
|
495
496
|
}
|
|
496
497
|
async function be(e, t, n) {
|
|
497
|
-
if (e instanceof Uint8Array && (e =
|
|
498
|
+
if (e instanceof Uint8Array && (e = _.decode(e)), typeof e != "string")
|
|
498
499
|
throw new u("Compact JWS must be a string or Uint8Array");
|
|
499
500
|
const { 0: r, 1: o, 2: i, length: a } = e.split(".");
|
|
500
501
|
if (a !== 3)
|
|
501
502
|
throw new u("Invalid Compact JWS");
|
|
502
|
-
const c = await
|
|
503
|
+
const c = await we({ payload: o, protected: r, signature: i }, t, n), s = { payload: c.payload, protectedHeader: c.protectedHeader };
|
|
503
504
|
return typeof t == "function" ? { ...s, key: c.key } : s;
|
|
504
505
|
}
|
|
505
|
-
const ge = (e) => Math.floor(e.getTime() / 1e3), q = 60, z = q * 60, J = z * 24, Ae = J * 7, Ie = J * 365.25,
|
|
506
|
-
const t =
|
|
506
|
+
const ge = (e) => Math.floor(e.getTime() / 1e3), q = 60, z = q * 60, J = z * 24, Ae = J * 7, Ie = J * 365.25, _e = /^(\+|\-)? ?(\d+|\d+\.\d+) ?(seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)(?: (ago|from now))?$/i, W = (e) => {
|
|
507
|
+
const t = _e.exec(e);
|
|
507
508
|
if (!t || t[4] && t[1])
|
|
508
509
|
throw new TypeError("Invalid time period format");
|
|
509
510
|
const n = parseFloat(t[2]), r = t[3].toLowerCase();
|
|
@@ -545,10 +546,10 @@ const ge = (e) => Math.floor(e.getTime() / 1e3), q = 60, z = q * 60, J = z * 24,
|
|
|
545
546
|
break;
|
|
546
547
|
}
|
|
547
548
|
return t[1] === "-" || t[4] === "ago" ? -o : o;
|
|
548
|
-
}, $ = (e) => e.toLowerCase().replace(/^application\//, ""),
|
|
549
|
+
}, $ = (e) => e.toLowerCase().replace(/^application\//, ""), Ce = (e, t) => typeof e == "string" ? t.includes(e) : Array.isArray(e) ? t.some(Set.prototype.has.bind(new Set(e))) : !1, Te = (e, t, n = {}) => {
|
|
549
550
|
let r;
|
|
550
551
|
try {
|
|
551
|
-
r = JSON.parse(
|
|
552
|
+
r = JSON.parse(_.decode(t));
|
|
552
553
|
} catch {
|
|
553
554
|
}
|
|
554
555
|
if (!x(r))
|
|
@@ -556,16 +557,16 @@ const ge = (e) => Math.floor(e.getTime() / 1e3), q = 60, z = q * 60, J = z * 24,
|
|
|
556
557
|
const { typ: o } = n;
|
|
557
558
|
if (o && (typeof e.typ != "string" || $(e.typ) !== $(o)))
|
|
558
559
|
throw new h('unexpected "typ" JWT header value', r, "typ", "check_failed");
|
|
559
|
-
const { requiredClaims: i = [], issuer: a, subject: c, audience: s, maxTokenAge: p } = n,
|
|
560
|
-
p !== void 0 &&
|
|
561
|
-
for (const l of new Set(
|
|
560
|
+
const { requiredClaims: i = [], issuer: a, subject: c, audience: s, maxTokenAge: p } = n, w = [...i];
|
|
561
|
+
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 l of new Set(w.reverse()))
|
|
562
563
|
if (!(l in r))
|
|
563
564
|
throw new h(`missing required "${l}" claim`, r, l, "missing");
|
|
564
565
|
if (a && !(Array.isArray(a) ? a : [a]).includes(r.iss))
|
|
565
566
|
throw new h('unexpected "iss" claim value', r, "iss", "check_failed");
|
|
566
567
|
if (c && r.sub !== c)
|
|
567
568
|
throw new h('unexpected "sub" claim value', r, "sub", "check_failed");
|
|
568
|
-
if (s && !
|
|
569
|
+
if (s && !Ce(r.aud, typeof s == "string" ? [s] : s))
|
|
569
570
|
throw new h('unexpected "aud" claim value', r, "aud", "check_failed");
|
|
570
571
|
let f;
|
|
571
572
|
switch (typeof n.clockTolerance) {
|
|
@@ -668,15 +669,15 @@ async function $e(e) {
|
|
|
668
669
|
};
|
|
669
670
|
}
|
|
670
671
|
async function Le(e, t) {
|
|
671
|
-
return await Q(e)
|
|
672
|
+
return t === await Q(e);
|
|
672
673
|
}
|
|
673
674
|
export {
|
|
674
|
-
|
|
675
|
+
Ne as API_TYPE,
|
|
675
676
|
Ke as AUTH_TYPES,
|
|
676
677
|
De as HEADERS,
|
|
677
678
|
K as JWT,
|
|
678
679
|
X as JWT_PUBLIC_KEY,
|
|
679
|
-
|
|
680
|
+
He as TOKEN_EXPIRATION,
|
|
680
681
|
Q as generateCodeChallenge,
|
|
681
682
|
$e as pkceChallengePair,
|
|
682
683
|
We as verifyAndExtractToken,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@versini/auth-common",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.8.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": "2a2665c70c76f0ee6772124b4703ac1bf3446435"
|
|
39
39
|
}
|