@versini/auth-common 2.7.1 → 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 CHANGED
@@ -5,6 +5,7 @@ declare const AUTH_TYPES: {
5
5
  ACCESS_TOKEN: string;
6
6
  ID_AND_ACCESS_TOKEN: string;
7
7
  CODE: string;
8
+ REFRESH_TOKEN: string;
8
9
  };
9
10
  declare const HEADERS: {
10
11
  CLIENT_ID: string;
@@ -20,6 +21,7 @@ declare const JWT_PUBLIC_KEY = "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0B
20
21
  declare const TOKEN_EXPIRATION: {
21
22
  ACCESS: string;
22
23
  ID: string;
24
+ REFRESH: string;
23
25
  };
24
26
  declare const API_TYPE: {
25
27
  AUTHENTICATE: string;
package/dist/index.js CHANGED
@@ -1,26 +1,27 @@
1
1
  /*!
2
- @versini/auth-common v2.7.1
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.7.1",
8
- buildTime: "06/27/2024 02:22 PM EDT",
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 Ke = {
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
- }, K = {
22
+ }, U = {
22
23
  ALG: "RS256",
23
- USER_ID_KEY: "_id",
24
+ USER_ID_KEY: "sub",
24
25
  TOKEN_ID_KEY: "__raw",
25
26
  NONCE_KEY: "_nonce",
26
27
  ISSUER: "gizmette.com"
@@ -32,14 +33,15 @@ aMwPFOIcJH+rKfFgNcHLcaS5syp7zU1ANwZ+trgR+DifBr8TLVkBynmNeTyhDm2+
32
33
  l0haqjMk0UoNPPE8iYBWUHQJJE1Dqstj65d6Eh5g64Pao25y4cmYJbKjiblIGEkE
33
34
  sjqybA9mARAqh9k/eiIopecWSiffNQTwVQVd2I9ZH3BalhEXHlqFgrjz51kFqg81
34
35
  awIDAQAB
35
- -----END PUBLIC KEY-----`, Ne = {
36
+ -----END PUBLIC KEY-----`, He = {
36
37
  ACCESS: "5m",
37
- ID: "90d"
38
- }, He = {
38
+ ID: "90d",
39
+ REFRESH: "90d"
40
+ }, Ne = {
39
41
  AUTHENTICATE: "authenticate",
40
42
  CODE: "code",
41
43
  LOGOUT: "logout"
42
- }, O = crypto, V = (e) => e instanceof CryptoKey, g = new TextEncoder(), C = new TextDecoder();
44
+ }, O = crypto, V = (e) => e instanceof CryptoKey, g = new TextEncoder(), _ = new TextDecoder();
43
45
  function j(...e) {
44
46
  const t = e.reduce((o, { length: i }) => o + i, 0), n = new Uint8Array(t);
45
47
  let r = 0;
@@ -54,7 +56,7 @@ const Z = (e) => {
54
56
  return n;
55
57
  }, R = (e) => {
56
58
  let t = e;
57
- t instanceof Uint8Array && (t = C.decode(t)), t = t.replace(/-/g, "+").replace(/_/g, "/").replace(/\s/g, "");
59
+ t instanceof Uint8Array && (t = _.decode(t)), t = t.replace(/-/g, "+").replace(/_/g, "/").replace(/\s/g, "");
58
60
  try {
59
61
  return Z(t);
60
62
  } catch {
@@ -94,7 +96,7 @@ class ee extends b {
94
96
  return "ERR_JOSE_ALG_NOT_ALLOWED";
95
97
  }
96
98
  }
97
- class _ extends b {
99
+ class C extends b {
98
100
  constructor() {
99
101
  super(...arguments), this.code = "ERR_JOSE_NOT_SUPPORTED";
100
102
  }
@@ -219,11 +221,11 @@ function F(e, t, ...n) {
219
221
  n.length === 2 ? e += `one of type ${n[0]} or ${n[1]}.` : e += `of type ${n[0]}.`;
220
222
  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
223
  }
222
- const N = (e, ...t) => F("Key must be ", e, ...t);
224
+ const H = (e, ...t) => F("Key must be ", e, ...t);
223
225
  function G(e, t, ...n) {
224
226
  return F(`Key for the ${e} algorithm must be `, t, ...n);
225
227
  }
226
- const Y = (e) => V(e), w = ["CryptoKey"], ae = (...e) => {
228
+ const Y = (e) => V(e), E = ["CryptoKey"], ae = (...e) => {
227
229
  const t = e.filter(Boolean);
228
230
  if (t.length === 0 || t.length === 1)
229
231
  return !0;
@@ -268,7 +270,7 @@ const ce = (e, t) => {
268
270
  return !1;
269
271
  const o = e.subarray(r, r + t.length);
270
272
  return o.length !== t.length ? !1 : o.every((i, a) => i === t[a]) || S(e, t, r + 1);
271
- }, H = (e) => {
273
+ }, N = (e) => {
272
274
  switch (!0) {
273
275
  case S(e, [42, 134, 72, 206, 61, 3, 1, 7]):
274
276
  return "P-256";
@@ -285,7 +287,7 @@ const ce = (e, t) => {
285
287
  case S(e, [43, 101, 113]):
286
288
  return "Ed448";
287
289
  default:
288
- throw new _("Invalid or unsupported EC Key Curve or OKP Key Sub Type");
290
+ throw new C("Invalid or unsupported EC Key Curve or OKP Key Sub Type");
289
291
  }
290
292
  }, se = async (e, t, n, r, o) => {
291
293
  let i, a;
@@ -323,15 +325,15 @@ const ce = (e, t) => {
323
325
  case "ECDH-ES+A128KW":
324
326
  case "ECDH-ES+A192KW":
325
327
  case "ECDH-ES+A256KW": {
326
- const s = H(c);
328
+ const s = N(c);
327
329
  i = s.startsWith("P-") ? { name: "ECDH", namedCurve: s } : { name: s }, a = [];
328
330
  break;
329
331
  }
330
332
  case "EdDSA":
331
- i = { name: H(c) }, a = ["verify"];
333
+ i = { name: N(c) }, a = ["verify"];
332
334
  break;
333
335
  default:
334
- throw new _('Invalid or unsupported "alg" (Algorithm) value');
336
+ throw new C('Invalid or unsupported "alg" (Algorithm) value');
335
337
  }
336
338
  return O.subtle.importKey(t, c, i, !1, a);
337
339
  }, de = (e, t, n) => se(/(?:-----(?:BEGIN|END) PUBLIC KEY-----|\s)/g, "spki", e, t);
@@ -340,24 +342,24 @@ async function ue(e, t, n) {
340
342
  throw new TypeError('"spki" must be SPKI formatted string');
341
343
  return de(e, t);
342
344
  }
343
- const le = (e, t) => {
345
+ const fe = (e, t) => {
344
346
  if (!(t instanceof Uint8Array)) {
345
347
  if (!Y(t))
346
- throw new TypeError(G(e, t, ...w, "Uint8Array"));
348
+ throw new TypeError(G(e, t, ...E, "Uint8Array"));
347
349
  if (t.type !== "secret")
348
- throw new TypeError(`${w.join(" or ")} instances for symmetric algorithms must be of type "secret"`);
350
+ throw new TypeError(`${E.join(" or ")} instances for symmetric algorithms must be of type "secret"`);
349
351
  }
350
- }, fe = (e, t, n) => {
352
+ }, le = (e, t, n) => {
351
353
  if (!Y(t))
352
- throw new TypeError(G(e, t, ...w));
354
+ throw new TypeError(G(e, t, ...E));
353
355
  if (t.type === "secret")
354
- throw new TypeError(`${w.join(" or ")} instances for asymmetric algorithms must not be of type "secret"`);
356
+ throw new TypeError(`${E.join(" or ")} instances for asymmetric algorithms must not be of type "secret"`);
355
357
  if (t.algorithm && n === "verify" && t.type === "private")
356
- throw new TypeError(`${w.join(" or ")} instances for asymmetric algorithm verifying must be of type "public"`);
358
+ throw new TypeError(`${E.join(" or ")} instances for asymmetric algorithm verifying must be of type "public"`);
357
359
  if (t.algorithm && n === "encrypt" && t.type === "private")
358
- throw new TypeError(`${w.join(" or ")} instances for asymmetric algorithm encryption must be of type "public"`);
360
+ throw new TypeError(`${E.join(" or ")} instances for asymmetric algorithm encryption must be of type "public"`);
359
361
  }, he = (e, t, n) => {
360
- e.startsWith("HS") || e === "dir" || e.startsWith("PBES2") || /^A\d{3}(?:GCM)?KW$/.test(e) ? le(e, t) : fe(e, t, n);
362
+ e.startsWith("HS") || e === "dir" || e.startsWith("PBES2") || /^A\d{3}(?:GCM)?KW$/.test(e) ? fe(e, t) : le(e, t, n);
361
363
  };
362
364
  function pe(e, t, n, r, o) {
363
365
  if (o.crit !== void 0 && (r == null ? void 0 : r.crit) === void 0)
@@ -370,7 +372,7 @@ function pe(e, t, n, r, o) {
370
372
  n !== void 0 ? i = new Map([...Object.entries(n), ...t.entries()]) : i = t;
371
373
  for (const a of r.crit) {
372
374
  if (!i.has(a))
373
- throw new _(`Extension Header Parameter "${a}" is not recognized`);
375
+ throw new C(`Extension Header Parameter "${a}" is not recognized`);
374
376
  if (o[a] === void 0)
375
377
  throw new e(`Extension Header Parameter "${a}" is missing`);
376
378
  if (i.get(a) && r[a] === void 0)
@@ -406,7 +408,7 @@ function ye(e, t) {
406
408
  case "EdDSA":
407
409
  return { name: t.name };
408
410
  default:
409
- throw new _(`alg ${e} is not supported either by JOSE or your javascript runtime`);
411
+ throw new C(`alg ${e} is not supported either by JOSE or your javascript runtime`);
410
412
  }
411
413
  }
412
414
  function Se(e, t, n) {
@@ -414,12 +416,12 @@ function Se(e, t, n) {
414
416
  return oe(t, e, n), t;
415
417
  if (t instanceof Uint8Array) {
416
418
  if (!e.startsWith("HS"))
417
- throw new TypeError(N(t, ...w));
419
+ throw new TypeError(H(t, ...E));
418
420
  return O.subtle.importKey("raw", t, { hash: `SHA-${e.slice(-3)}`, name: "HMAC" }, !1, [n]);
419
421
  }
420
- throw new TypeError(N(t, ...w, "Uint8Array"));
422
+ throw new TypeError(H(t, ...E, "Uint8Array"));
421
423
  }
422
- const we = async (e, t, n, r) => {
424
+ const Ee = async (e, t, n, r) => {
423
425
  const o = await Se(e, t, "verify");
424
426
  ce(e, o);
425
427
  const i = ye(e, o.algorithm);
@@ -429,7 +431,7 @@ const we = async (e, t, n, r) => {
429
431
  return !1;
430
432
  }
431
433
  };
432
- async function Ee(e, t, n) {
434
+ async function we(e, t, n) {
433
435
  if (!x(e))
434
436
  throw new u("Flattened JWS must be an object");
435
437
  if (e.protected === void 0 && e.header === void 0)
@@ -446,7 +448,7 @@ async function Ee(e, t, n) {
446
448
  if (e.protected)
447
449
  try {
448
450
  const T = R(e.protected);
449
- r = JSON.parse(C.decode(T));
451
+ r = JSON.parse(_.decode(T));
450
452
  } catch {
451
453
  throw new u("JWS Protected Header is invalid");
452
454
  }
@@ -472,14 +474,14 @@ async function Ee(e, t, n) {
472
474
  throw new u("JWS Payload must be a string or an Uint8Array instance");
473
475
  let p = !1;
474
476
  typeof t == "function" && (t = await t(r, e), p = !0), he(c, t, "verify");
475
- const E = j(g.encode(e.protected ?? ""), g.encode("."), typeof e.payload == "string" ? g.encode(e.payload) : e.payload);
476
- let f;
477
+ const w = j(g.encode(e.protected ?? ""), g.encode("."), typeof e.payload == "string" ? g.encode(e.payload) : e.payload);
478
+ let l;
477
479
  try {
478
- f = R(e.signature);
480
+ l = R(e.signature);
479
481
  } catch {
480
482
  throw new u("Failed to base64url decode the signature");
481
483
  }
482
- if (!await we(c, t, f, E))
484
+ if (!await Ee(c, t, l, w))
483
485
  throw new te();
484
486
  let y;
485
487
  if (a)
@@ -490,20 +492,20 @@ async function Ee(e, t, n) {
490
492
  }
491
493
  else
492
494
  typeof e.payload == "string" ? y = g.encode(e.payload) : y = e.payload;
493
- const l = { payload: y };
494
- return e.protected !== void 0 && (l.protectedHeader = r), e.header !== void 0 && (l.unprotectedHeader = e.header), p ? { ...l, key: t } : l;
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;
495
497
  }
496
498
  async function be(e, t, n) {
497
- if (e instanceof Uint8Array && (e = C.decode(e)), typeof e != "string")
499
+ if (e instanceof Uint8Array && (e = _.decode(e)), typeof e != "string")
498
500
  throw new u("Compact JWS must be a string or Uint8Array");
499
501
  const { 0: r, 1: o, 2: i, length: a } = e.split(".");
500
502
  if (a !== 3)
501
503
  throw new u("Invalid Compact JWS");
502
- const c = await Ee({ payload: o, protected: r, signature: i }, t, n), s = { payload: c.payload, protectedHeader: c.protectedHeader };
504
+ const c = await we({ payload: o, protected: r, signature: i }, t, n), s = { payload: c.payload, protectedHeader: c.protectedHeader };
503
505
  return typeof t == "function" ? { ...s, key: c.key } : s;
504
506
  }
505
- const ge = (e) => Math.floor(e.getTime() / 1e3), q = 60, z = q * 60, J = z * 24, Ae = J * 7, Ie = J * 365.25, Ce = /^(\+|\-)? ?(\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) => {
506
- const t = Ce.exec(e);
507
+ 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) => {
508
+ const t = _e.exec(e);
507
509
  if (!t || t[4] && t[1])
508
510
  throw new TypeError("Invalid time period format");
509
511
  const n = parseFloat(t[2]), r = t[3].toLowerCase();
@@ -545,10 +547,10 @@ const ge = (e) => Math.floor(e.getTime() / 1e3), q = 60, z = q * 60, J = z * 24,
545
547
  break;
546
548
  }
547
549
  return t[1] === "-" || t[4] === "ago" ? -o : o;
548
- }, $ = (e) => e.toLowerCase().replace(/^application\//, ""), _e = (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 = {}) => {
550
+ }, $ = (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
551
  let r;
550
552
  try {
551
- r = JSON.parse(C.decode(t));
553
+ r = JSON.parse(_.decode(t));
552
554
  } catch {
553
555
  }
554
556
  if (!x(r))
@@ -556,51 +558,51 @@ const ge = (e) => Math.floor(e.getTime() / 1e3), q = 60, z = q * 60, J = z * 24,
556
558
  const { typ: o } = n;
557
559
  if (o && (typeof e.typ != "string" || $(e.typ) !== $(o)))
558
560
  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, E = [...i];
560
- p !== void 0 && E.push("iat"), s !== void 0 && E.push("aud"), c !== void 0 && E.push("sub"), a !== void 0 && E.push("iss");
561
- for (const l of new Set(E.reverse()))
562
- if (!(l in r))
563
- throw new h(`missing required "${l}" claim`, r, l, "missing");
561
+ const { requiredClaims: i = [], issuer: a, subject: c, audience: s, maxTokenAge: p } = n, w = [...i];
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");
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");
564
566
  if (a && !(Array.isArray(a) ? a : [a]).includes(r.iss))
565
567
  throw new h('unexpected "iss" claim value', r, "iss", "check_failed");
566
568
  if (c && r.sub !== c)
567
569
  throw new h('unexpected "sub" claim value', r, "sub", "check_failed");
568
- if (s && !_e(r.aud, typeof s == "string" ? [s] : s))
570
+ if (s && !Ce(r.aud, typeof s == "string" ? [s] : s))
569
571
  throw new h('unexpected "aud" claim value', r, "aud", "check_failed");
570
- let f;
572
+ let l;
571
573
  switch (typeof n.clockTolerance) {
572
574
  case "string":
573
- f = W(n.clockTolerance);
575
+ l = W(n.clockTolerance);
574
576
  break;
575
577
  case "number":
576
- f = n.clockTolerance;
578
+ l = n.clockTolerance;
577
579
  break;
578
580
  case "undefined":
579
- f = 0;
581
+ l = 0;
580
582
  break;
581
583
  default:
582
584
  throw new TypeError("Invalid clockTolerance option type");
583
585
  }
584
- const { currentDate: U } = n, y = ge(U || /* @__PURE__ */ new Date());
586
+ const { currentDate: K } = n, y = ge(K || /* @__PURE__ */ new Date());
585
587
  if ((r.iat !== void 0 || p) && typeof r.iat != "number")
586
588
  throw new h('"iat" claim must be a number', r, "iat", "invalid");
587
589
  if (r.nbf !== void 0) {
588
590
  if (typeof r.nbf != "number")
589
591
  throw new h('"nbf" claim must be a number', r, "nbf", "invalid");
590
- if (r.nbf > y + f)
592
+ if (r.nbf > y + l)
591
593
  throw new h('"nbf" claim timestamp check failed', r, "nbf", "check_failed");
592
594
  }
593
595
  if (r.exp !== void 0) {
594
596
  if (typeof r.exp != "number")
595
597
  throw new h('"exp" claim must be a number', r, "exp", "invalid");
596
- if (r.exp <= y - f)
598
+ if (r.exp <= y - l)
597
599
  throw new D('"exp" claim timestamp check failed', r, "exp", "check_failed");
598
600
  }
599
601
  if (p) {
600
- const l = y - r.iat, T = typeof p == "number" ? p : W(p);
601
- if (l - f > T)
602
+ const f = y - r.iat, T = typeof p == "number" ? p : W(p);
603
+ if (f - l > T)
602
604
  throw new D('"iat" claim timestamp check failed (too far in the past)', r, "iat", "check_failed");
603
- if (l < 0 - f)
605
+ if (f < 0 - l)
604
606
  throw new h('"iat" claim timestamp check failed (it should be in the past)', r, "iat", "check_failed");
605
607
  }
606
608
  return r;
@@ -615,9 +617,9 @@ async function Re(e, t, n) {
615
617
  }
616
618
  const We = async (e) => {
617
619
  try {
618
- const t = K.ALG, r = await ue(X, t);
620
+ const t = U.ALG, r = await ue(X, t);
619
621
  return await Re(e, r, {
620
- issuer: K.ISSUER
622
+ issuer: U.ISSUER
621
623
  });
622
624
  } catch {
623
625
  return;
@@ -646,7 +648,7 @@ function k(e, t, n) {
646
648
  var r = e.random || (e.rng || xe)();
647
649
  return r[6] = r[6] & 15 | 64, r[8] = r[8] & 63 | 128, ve(r);
648
650
  }
649
- const M = globalThis.crypto, Je = (e) => `${k()}${k()}`.slice(0, e), Ue = (e) => btoa(
651
+ const M = globalThis.crypto, Je = (e) => `${k()}${k()}`.slice(0, e), Ke = (e) => btoa(
650
652
  [...new Uint8Array(e)].map((t) => String.fromCharCode(t)).join("")
651
653
  );
652
654
  async function Q(e) {
@@ -655,7 +657,7 @@ async function Q(e) {
655
657
  "crypto.subtle is available only in secure contexts (HTTPS)."
656
658
  );
657
659
  const t = new TextEncoder().encode(e), n = await M.subtle.digest("SHA-256", t);
658
- return Ue(n).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
660
+ return Ke(n).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
659
661
  }
660
662
  async function $e(e) {
661
663
  const t = e || 43;
@@ -668,15 +670,15 @@ async function $e(e) {
668
670
  };
669
671
  }
670
672
  async function Le(e, t) {
671
- return await Q(e) === t;
673
+ return t === await Q(e);
672
674
  }
673
675
  export {
674
- He as API_TYPE,
675
- Ke as AUTH_TYPES,
676
+ Ne as API_TYPE,
677
+ Ue as AUTH_TYPES,
676
678
  De as HEADERS,
677
- K as JWT,
679
+ U as JWT,
678
680
  X as JWT_PUBLIC_KEY,
679
- Ne as TOKEN_EXPIRATION,
681
+ He as TOKEN_EXPIRATION,
680
682
  Q as generateCodeChallenge,
681
683
  $e as pkceChallengePair,
682
684
  We as verifyAndExtractToken,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@versini/auth-common",
3
- "version": "2.7.1",
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": "1e41e4a8ebc16b39fa416e6eb1aa214475ba2865"
38
+ "gitHead": "48c8a3b48dc2d614be43f407e6c72fd433530afc"
39
39
  }