@versini/auth-provider 5.0.0 → 5.0.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.
Files changed (2) hide show
  1. package/dist/index.js +136 -135
  2. package/package.json +3 -3
package/dist/index.js CHANGED
@@ -1,14 +1,14 @@
1
1
  import { jsx as We } from "react/jsx-runtime";
2
- import * as D from "react";
2
+ import * as U from "react";
3
3
  import { createContext as Je, useState as xe, useCallback as je, useEffect as Me, useContext as Ve } from "react";
4
4
  /*!
5
- @versini/auth-provider v5.0.0
5
+ @versini/auth-provider v5.0.1
6
6
  © 2024 gizmette.com
7
7
  */
8
8
  try {
9
9
  window.__VERSINI_AUTH_CLIENT__ || (window.__VERSINI_AUTH_CLIENT__ = {
10
- version: "5.0.0",
11
- buildTime: "06/29/2024 02:02 PM EDT",
10
+ version: "5.0.1",
11
+ buildTime: "07/03/2024 06:46 PM EDT",
12
12
  homepage: "https://github.com/aversini/auth-client",
13
13
  license: "MIT"
14
14
  });
@@ -21,7 +21,7 @@ try {
21
21
  try {
22
22
  window.__VERSINI_AUTH_COMMON__ || (window.__VERSINI_AUTH_COMMON__ = {
23
23
  version: "2.10.1",
24
- buildTime: "06/29/2024 02:02 PM EDT",
24
+ buildTime: "07/03/2024 06:46 PM EDT",
25
25
  homepage: "https://github.com/aversini/auth-client",
26
26
  license: "MIT"
27
27
  });
@@ -85,7 +85,7 @@ class C extends Error {
85
85
  super(t), this.code = "ERR_JOSE_GENERIC", this.name = this.constructor.name, (r = Error.captureStackTrace) == null || r.call(Error, this, this.constructor);
86
86
  }
87
87
  }
88
- class g extends C {
88
+ class A extends C {
89
89
  static get code() {
90
90
  return "ERR_JWT_CLAIM_VALIDATION_FAILED";
91
91
  }
@@ -93,7 +93,7 @@ class g extends C {
93
93
  super(t), this.code = "ERR_JWT_CLAIM_VALIDATION_FAILED", this.claim = a, this.reason = n, this.payload = r;
94
94
  }
95
95
  }
96
- class ie extends C {
96
+ class ce extends C {
97
97
  static get code() {
98
98
  return "ERR_JWT_EXPIRED";
99
99
  }
@@ -109,7 +109,7 @@ class qe extends C {
109
109
  return "ERR_JOSE_ALG_NOT_ALLOWED";
110
110
  }
111
111
  }
112
- let T = class extends C {
112
+ let k = class extends C {
113
113
  constructor() {
114
114
  super(...arguments), this.code = "ERR_JOSE_NOT_SUPPORTED";
115
115
  }
@@ -233,7 +233,7 @@ function _e(e, t, ...r) {
233
233
  r.length === 2 ? e += `one of type ${r[0]} or ${r[1]}.` : e += `of type ${r[0]}.`;
234
234
  return t == null ? e += ` Received ${t}` : typeof t == "function" && t.name ? e += ` Received function ${t.name}` : typeof t == "object" && t != null && (a = t.constructor) != null && a.name && (e += ` Received an instance of ${t.constructor.name}`), e;
235
235
  }
236
- const ce = (e, ...t) => _e("Key must be ", e, ...t);
236
+ const ie = (e, ...t) => _e("Key must be ", e, ...t);
237
237
  function ve(e, t, ...r) {
238
238
  return _e(`Key for the ${e} algorithm must be `, t, ...r);
239
239
  }
@@ -301,7 +301,7 @@ function at(e) {
301
301
  }, r = e.d ? ["decrypt", "unwrapKey"] : ["encrypt", "wrapKey"];
302
302
  break;
303
303
  default:
304
- throw new T('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
304
+ throw new k('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
305
305
  }
306
306
  break;
307
307
  }
@@ -323,7 +323,7 @@ function at(e) {
323
323
  t = { name: "ECDH", namedCurve: e.crv }, r = e.d ? ["deriveBits"] : [];
324
324
  break;
325
325
  default:
326
- throw new T('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
326
+ throw new k('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
327
327
  }
328
328
  break;
329
329
  }
@@ -339,12 +339,12 @@ function at(e) {
339
339
  t = { name: e.crv }, r = e.d ? ["deriveBits"] : [];
340
340
  break;
341
341
  default:
342
- throw new T('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
342
+ throw new k('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
343
343
  }
344
344
  break;
345
345
  }
346
346
  default:
347
- throw new T('Invalid or unsupported JWK "kty" (Key Type) Parameter value');
347
+ throw new k('Invalid or unsupported JWK "kty" (Key Type) Parameter value');
348
348
  }
349
349
  return { algorithm: t, keyUsages: r };
350
350
  }
@@ -377,35 +377,35 @@ const Re = (e) => (e == null ? void 0 : e[Symbol.toStringTag]) === "KeyObject",
377
377
  return r.k ? ke(r.k) : (Q || (Q = /* @__PURE__ */ new WeakMap()), Ie(Q, e, r, t));
378
378
  }
379
379
  return e;
380
- }, it = { normalizePublicKey: ot, normalizePrivateKey: st }, v = (e, t, r = 0) => {
380
+ }, ct = { normalizePublicKey: ot, normalizePrivateKey: st }, T = (e, t, r = 0) => {
381
381
  r === 0 && (t.unshift(t.length), t.unshift(6));
382
382
  const a = e.indexOf(t[0], r);
383
383
  if (a === -1)
384
384
  return !1;
385
385
  const n = e.subarray(a, a + t.length);
386
- return n.length !== t.length ? !1 : n.every((s, o) => s === t[o]) || v(e, t, a + 1);
386
+ return n.length !== t.length ? !1 : n.every((s, o) => s === t[o]) || T(e, t, a + 1);
387
387
  }, ue = (e) => {
388
388
  switch (!0) {
389
- case v(e, [42, 134, 72, 206, 61, 3, 1, 7]):
389
+ case T(e, [42, 134, 72, 206, 61, 3, 1, 7]):
390
390
  return "P-256";
391
- case v(e, [43, 129, 4, 0, 34]):
391
+ case T(e, [43, 129, 4, 0, 34]):
392
392
  return "P-384";
393
- case v(e, [43, 129, 4, 0, 35]):
393
+ case T(e, [43, 129, 4, 0, 35]):
394
394
  return "P-521";
395
- case v(e, [43, 101, 110]):
395
+ case T(e, [43, 101, 110]):
396
396
  return "X25519";
397
- case v(e, [43, 101, 111]):
397
+ case T(e, [43, 101, 111]):
398
398
  return "X448";
399
- case v(e, [43, 101, 112]):
399
+ case T(e, [43, 101, 112]):
400
400
  return "Ed25519";
401
- case v(e, [43, 101, 113]):
401
+ case T(e, [43, 101, 113]):
402
402
  return "Ed448";
403
403
  default:
404
- throw new T("Invalid or unsupported EC Key Curve or OKP Key Sub Type");
404
+ throw new k("Invalid or unsupported EC Key Curve or OKP Key Sub Type");
405
405
  }
406
- }, ct = async (e, t, r, a, n) => {
406
+ }, it = async (e, t, r, a, n) => {
407
407
  let s, o;
408
- const c = new Uint8Array(atob(r.replace(e, "")).split("").map((i) => i.charCodeAt(0)));
408
+ const i = new Uint8Array(atob(r.replace(e, "")).split("").map((c) => c.charCodeAt(0)));
409
409
  switch (a) {
410
410
  case "PS256":
411
411
  case "PS384":
@@ -439,18 +439,18 @@ const Re = (e) => (e == null ? void 0 : e[Symbol.toStringTag]) === "KeyObject",
439
439
  case "ECDH-ES+A128KW":
440
440
  case "ECDH-ES+A192KW":
441
441
  case "ECDH-ES+A256KW": {
442
- const i = ue(c);
443
- s = i.startsWith("P-") ? { name: "ECDH", namedCurve: i } : { name: i }, o = [];
442
+ const c = ue(i);
443
+ s = c.startsWith("P-") ? { name: "ECDH", namedCurve: c } : { name: c }, o = [];
444
444
  break;
445
445
  }
446
446
  case "EdDSA":
447
- s = { name: ue(c) }, o = ["verify"];
447
+ s = { name: ue(i) }, o = ["verify"];
448
448
  break;
449
449
  default:
450
- throw new T('Invalid or unsupported "alg" (Algorithm) value');
450
+ throw new k('Invalid or unsupported "alg" (Algorithm) value');
451
451
  }
452
- return G.subtle.importKey(t, c, s, !1, o);
453
- }, ut = (e, t, r) => ct(/(?:-----(?:BEGIN|END) PUBLIC KEY-----|\s)/g, "spki", e, t);
452
+ return G.subtle.importKey(t, i, s, !1, o);
453
+ }, ut = (e, t, r) => it(/(?:-----(?:BEGIN|END) PUBLIC KEY-----|\s)/g, "spki", e, t);
454
454
  async function dt(e, t, r) {
455
455
  if (e.indexOf("-----BEGIN PUBLIC KEY-----") !== 0)
456
456
  throw new TypeError('"spki" must be SPKI formatted string');
@@ -486,7 +486,7 @@ function yt(e, t, r, a, n) {
486
486
  r !== void 0 ? s = new Map([...Object.entries(r), ...t.entries()]) : s = t;
487
487
  for (const o of a.crit) {
488
488
  if (!s.has(o))
489
- throw new T(`Extension Header Parameter "${o}" is not recognized`);
489
+ throw new k(`Extension Header Parameter "${o}" is not recognized`);
490
490
  if (n[o] === void 0)
491
491
  throw new e(`Extension Header Parameter "${o}" is missing`);
492
492
  if (s.get(o) && a[o] === void 0)
@@ -522,18 +522,18 @@ function mt(e, t) {
522
522
  case "EdDSA":
523
523
  return { name: t.name };
524
524
  default:
525
- throw new T(`alg ${e} is not supported either by JOSE or your javascript runtime`);
525
+ throw new k(`alg ${e} is not supported either by JOSE or your javascript runtime`);
526
526
  }
527
527
  }
528
528
  async function wt(e, t, r) {
529
- if (t = await it.normalizePublicKey(t, e), Ae(t))
529
+ if (t = await ct.normalizePublicKey(t, e), Ae(t))
530
530
  return Ze(t, e, r), t;
531
531
  if (t instanceof Uint8Array) {
532
532
  if (!e.startsWith("HS"))
533
- throw new TypeError(ce(t, ...Y));
533
+ throw new TypeError(ie(t, ...Y));
534
534
  return G.subtle.importKey("raw", t, { hash: `SHA-${e.slice(-3)}`, name: "HMAC" }, !1, [r]);
535
535
  }
536
- throw new TypeError(ce(t, ...Y, "Uint8Array"));
536
+ throw new TypeError(ie(t, ...Y, "Uint8Array"));
537
537
  }
538
538
  const Et = async (e, t, r, a) => {
539
539
  const n = await wt(e, t, "verify");
@@ -561,8 +561,8 @@ async function St(e, t, r) {
561
561
  let a = {};
562
562
  if (e.protected)
563
563
  try {
564
- const w = M(e.protected);
565
- a = JSON.parse(q.decode(w));
564
+ const E = M(e.protected);
565
+ a = JSON.parse(q.decode(E));
566
566
  } catch {
567
567
  throw new h("JWS Protected Header is invalid");
568
568
  }
@@ -575,11 +575,11 @@ async function St(e, t, r) {
575
575
  let o = !0;
576
576
  if (s.has("b64") && (o = a.b64, typeof o != "boolean"))
577
577
  throw new h('The "b64" (base64url-encode payload) Header Parameter must be a boolean');
578
- const { alg: c } = n;
579
- if (typeof c != "string" || !c)
578
+ const { alg: i } = n;
579
+ if (typeof i != "string" || !i)
580
580
  throw new h('JWS "alg" (Algorithm) Header Parameter missing or invalid');
581
- const i = r && ft("algorithms", r.algorithms);
582
- if (i && !i.has(c))
581
+ const c = r && ft("algorithms", r.algorithms);
582
+ if (c && !c.has(i))
583
583
  throw new qe('"alg" (Algorithm) Header Parameter value not allowed');
584
584
  if (o) {
585
585
  if (typeof e.payload != "string")
@@ -587,15 +587,15 @@ async function St(e, t, r) {
587
587
  } else if (typeof e.payload != "string" && !(e.payload instanceof Uint8Array))
588
588
  throw new h("JWS Payload must be a string or an Uint8Array instance");
589
589
  let u = !1;
590
- typeof t == "function" && (t = await t(a, e), u = !0), pt(c, t, "verify");
591
- const m = Fe(N.encode(e.protected ?? ""), N.encode("."), typeof e.payload == "string" ? N.encode(e.payload) : e.payload);
590
+ typeof t == "function" && (t = await t(a, e), u = !0), pt(i, t, "verify");
591
+ const w = Fe(N.encode(e.protected ?? ""), N.encode("."), typeof e.payload == "string" ? N.encode(e.payload) : e.payload);
592
592
  let y;
593
593
  try {
594
594
  y = M(e.signature);
595
595
  } catch {
596
596
  throw new h("Failed to base64url decode the signature");
597
597
  }
598
- if (!await Et(c, t, y, m))
598
+ if (!await Et(i, t, y, w))
599
599
  throw new ze();
600
600
  let _;
601
601
  if (o)
@@ -606,8 +606,8 @@ async function St(e, t, r) {
606
606
  }
607
607
  else
608
608
  typeof e.payload == "string" ? _ = N.encode(e.payload) : _ = e.payload;
609
- const E = { payload: _ };
610
- return e.protected !== void 0 && (E.protectedHeader = a), e.header !== void 0 && (E.unprotectedHeader = e.header), u ? { ...E, key: t } : E;
609
+ const S = { payload: _ };
610
+ return e.protected !== void 0 && (S.protectedHeader = a), e.header !== void 0 && (S.unprotectedHeader = e.header), u ? { ...S, key: t } : S;
611
611
  }
612
612
  async function gt(e, t, r) {
613
613
  if (e instanceof Uint8Array && (e = q.decode(e)), typeof e != "string")
@@ -615,8 +615,8 @@ async function gt(e, t, r) {
615
615
  const { 0: a, 1: n, 2: s, length: o } = e.split(".");
616
616
  if (o !== 3)
617
617
  throw new h("Invalid Compact JWS");
618
- const c = await St({ payload: n, protected: a, signature: s }, t, r), i = { payload: c.payload, protectedHeader: c.protectedHeader };
619
- return typeof t == "function" ? { ...i, key: c.key } : i;
618
+ const i = await St({ payload: n, protected: a, signature: s }, t, r), c = { payload: i.payload, protectedHeader: i.protectedHeader };
619
+ return typeof t == "function" ? { ...c, key: i.key } : c;
620
620
  }
621
621
  const At = (e) => Math.floor(e.getTime() / 1e3), Ce = 60, Pe = Ce * 60, oe = Pe * 24, bt = oe * 7, _t = oe * 365.25, vt = /^(\+|\-)? ?(\d+|\d+\.\d+) ?(seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)(?: (ago|from now))?$/i, de = (e) => {
622
622
  const t = vt.exec(e);
@@ -671,18 +671,18 @@ const At = (e) => Math.floor(e.getTime() / 1e3), Ce = 60, Pe = Ce * 60, oe = Pe
671
671
  throw new be("JWT Claims Set must be a top-level JSON object");
672
672
  const { typ: n } = r;
673
673
  if (n && (typeof e.typ != "string" || le(e.typ) !== le(n)))
674
- throw new g('unexpected "typ" JWT header value', a, "typ", "check_failed");
675
- const { requiredClaims: s = [], issuer: o, subject: c, audience: i, maxTokenAge: u } = r, m = [...s];
676
- u !== void 0 && m.push("iat"), i !== void 0 && m.push("aud"), c !== void 0 && m.push("sub"), o !== void 0 && m.push("iss");
677
- for (const w of new Set(m.reverse()))
678
- if (!(w in a))
679
- throw new g(`missing required "${w}" claim`, a, w, "missing");
674
+ throw new A('unexpected "typ" JWT header value', a, "typ", "check_failed");
675
+ const { requiredClaims: s = [], issuer: o, subject: i, audience: c, maxTokenAge: u } = r, w = [...s];
676
+ u !== void 0 && w.push("iat"), c !== void 0 && w.push("aud"), i !== void 0 && w.push("sub"), o !== void 0 && w.push("iss");
677
+ for (const E of new Set(w.reverse()))
678
+ if (!(E in a))
679
+ throw new A(`missing required "${E}" claim`, a, E, "missing");
680
680
  if (o && !(Array.isArray(o) ? o : [o]).includes(a.iss))
681
- throw new g('unexpected "iss" claim value', a, "iss", "check_failed");
682
- if (c && a.sub !== c)
683
- throw new g('unexpected "sub" claim value', a, "sub", "check_failed");
684
- if (i && !Tt(a.aud, typeof i == "string" ? [i] : i))
685
- throw new g('unexpected "aud" claim value', a, "aud", "check_failed");
681
+ throw new A('unexpected "iss" claim value', a, "iss", "check_failed");
682
+ if (i && a.sub !== i)
683
+ throw new A('unexpected "sub" claim value', a, "sub", "check_failed");
684
+ if (c && !Tt(a.aud, typeof c == "string" ? [c] : c))
685
+ throw new A('unexpected "aud" claim value', a, "aud", "check_failed");
686
686
  let y;
687
687
  switch (typeof r.clockTolerance) {
688
688
  case "string":
@@ -697,27 +697,27 @@ const At = (e) => Math.floor(e.getTime() / 1e3), Ce = 60, Pe = Ce * 60, oe = Pe
697
697
  default:
698
698
  throw new TypeError("Invalid clockTolerance option type");
699
699
  }
700
- const { currentDate: _ } = r, E = At(_ || /* @__PURE__ */ new Date());
700
+ const { currentDate: _ } = r, S = At(_ || /* @__PURE__ */ new Date());
701
701
  if ((a.iat !== void 0 || u) && typeof a.iat != "number")
702
- throw new g('"iat" claim must be a number', a, "iat", "invalid");
702
+ throw new A('"iat" claim must be a number', a, "iat", "invalid");
703
703
  if (a.nbf !== void 0) {
704
704
  if (typeof a.nbf != "number")
705
- throw new g('"nbf" claim must be a number', a, "nbf", "invalid");
706
- if (a.nbf > E + y)
707
- throw new g('"nbf" claim timestamp check failed', a, "nbf", "check_failed");
705
+ throw new A('"nbf" claim must be a number', a, "nbf", "invalid");
706
+ if (a.nbf > S + y)
707
+ throw new A('"nbf" claim timestamp check failed', a, "nbf", "check_failed");
708
708
  }
709
709
  if (a.exp !== void 0) {
710
710
  if (typeof a.exp != "number")
711
- throw new g('"exp" claim must be a number', a, "exp", "invalid");
712
- if (a.exp <= E - y)
713
- throw new ie('"exp" claim timestamp check failed', a, "exp", "check_failed");
711
+ throw new A('"exp" claim must be a number', a, "exp", "invalid");
712
+ if (a.exp <= S - y)
713
+ throw new ce('"exp" claim timestamp check failed', a, "exp", "check_failed");
714
714
  }
715
715
  if (u) {
716
- const w = E - a.iat, k = typeof u == "number" ? u : de(u);
717
- if (w - y > k)
718
- throw new ie('"iat" claim timestamp check failed (too far in the past)', a, "iat", "check_failed");
719
- if (w < 0 - y)
720
- throw new g('"iat" claim timestamp check failed (it should be in the past)', a, "iat", "check_failed");
716
+ const E = S - a.iat, R = typeof u == "number" ? u : de(u);
717
+ if (E - y > R)
718
+ throw new ce('"iat" claim timestamp check failed (too far in the past)', a, "iat", "check_failed");
719
+ if (E < 0 - y)
720
+ throw new A('"iat" claim timestamp check failed (it should be in the past)', a, "iat", "check_failed");
721
721
  }
722
722
  return a;
723
723
  };
@@ -795,29 +795,29 @@ function W({
795
795
  key: e,
796
796
  initialValue: t
797
797
  }) {
798
- const r = () => me(e), a = D.useSyncExternalStore(
798
+ const r = () => me(e), a = U.useSyncExternalStore(
799
799
  $t,
800
800
  r
801
- ), n = D.useCallback(
802
- (c) => {
801
+ ), n = U.useCallback(
802
+ (i) => {
803
803
  try {
804
- const i = typeof c == "function" ? c(JSON.parse(a)) : c;
805
- i == null ? Nt(e) : fe(e, i);
806
- } catch (i) {
807
- console.warn(i);
804
+ const c = typeof i == "function" ? i(JSON.parse(a)) : i;
805
+ c == null ? Nt(e) : fe(e, c);
806
+ } catch (c) {
807
+ console.warn(c);
808
808
  }
809
809
  },
810
810
  [e, a]
811
- ), s = D.useCallback(() => {
811
+ ), s = U.useCallback(() => {
812
812
  n(t);
813
- }, [t, n]), o = D.useCallback(() => {
813
+ }, [t, n]), o = U.useCallback(() => {
814
814
  n(null);
815
815
  }, [n]);
816
- return D.useEffect(() => {
816
+ return U.useEffect(() => {
817
817
  try {
818
818
  me(e) === null && typeof t < "u" && fe(e, t);
819
- } catch (c) {
820
- console.warn(c);
819
+ } catch (i) {
820
+ console.warn(i);
821
821
  }
822
822
  }, [e, t]), [a ? JSON.parse(a) : null, n, s, o];
823
823
  }
@@ -844,7 +844,7 @@ function jt(e, t, r) {
844
844
  var a = e.random || (e.rng || Jt)();
845
845
  return a[6] = a[6] & 15 | 64, a[8] = a[8] & 63 | 128, Lt(a);
846
846
  }
847
- const re = "Oops! It looks like your session has expired. For your security, please log in again to continue.", Mt = "Your session has been successfully terminated.", Ee = "Login failed. Please try again.", U = "Error getting access token, please re-authenticate.", Vt = "You forgot to wrap your component in <AuthProvider>.", Se = {
847
+ const re = "Oops! It looks like your session has expired. For your security, please log in again to continue.", Mt = "Your session has been successfully terminated.", Ee = "Login failed. Please try again.", v = "Error getting access token, please re-authenticate.", Vt = "You forgot to wrap your component in <AuthProvider>.", Se = {
848
848
  dev: "https://auth.gizmette.local.com:3003",
849
849
  prod: "https://mylogin.gizmette.com"
850
850
  }, x = "@@auth@@", Yt = process.env.NODE_ENV === "production", Bt = !Yt, z = async ({
@@ -907,10 +907,10 @@ const re = "Oops! It looks like your session has expired. For your security, ple
907
907
  type: n,
908
908
  sessionExpiration: s,
909
909
  code: o,
910
- code_verifier: c
910
+ code_verifier: i
911
911
  }) => {
912
912
  try {
913
- const i = await z({
913
+ const c = await z({
914
914
  type: F.AUTHENTICATE,
915
915
  clientId: r,
916
916
  params: {
@@ -920,13 +920,13 @@ const re = "Oops! It looks like your session has expired. For your security, ple
920
920
  sessionExpiration: s,
921
921
  nonce: a,
922
922
  code: o,
923
- code_verifier: c
923
+ code_verifier: i
924
924
  }
925
- }), u = await H(i.data.idToken);
925
+ }), u = await H(c.data.idToken);
926
926
  return u && u.payload[f.USER_ID_KEY] !== "" && u.payload[f.NONCE_KEY] === a ? {
927
- idToken: i.data.idToken,
928
- accessToken: i.data.accessToken,
929
- refreshToken: i.data.refreshToken,
927
+ idToken: c.data.idToken,
928
+ accessToken: c.data.accessToken,
929
+ refreshToken: c.data.refreshToken,
930
930
  userId: u.payload[f.USER_ID_KEY],
931
931
  status: !0
932
932
  } : {
@@ -1012,32 +1012,32 @@ const re = "Oops! It looks like your session has expired. For your security, ple
1012
1012
  }) => {
1013
1013
  const [a, n, , s] = W({
1014
1014
  key: `${x}::${r}::@@user@@`
1015
- }), [o, c, , i] = W({
1015
+ }), [o, i, , c] = W({
1016
1016
  key: `${x}::${r}::@@access@@`
1017
- }), [u, m, , y] = W(
1017
+ }), [u, w, , y] = W(
1018
1018
  {
1019
1019
  key: `${x}::${r}::@@refresh@@`
1020
1020
  }
1021
- ), [_, E, , w] = W({
1021
+ ), [_, S, , E] = W({
1022
1022
  key: `${x}::${r}::@@nonce@@`
1023
- }), [k, K] = xe({
1023
+ }), [R, K] = xe({
1024
1024
  isLoading: !0,
1025
1025
  isAuthenticated: !1,
1026
1026
  user: void 0,
1027
1027
  logoutReason: ""
1028
- }), A = je(
1028
+ }), g = je(
1029
1029
  (p) => {
1030
1030
  K({
1031
1031
  isLoading: !1,
1032
1032
  isAuthenticated: !1,
1033
1033
  user: void 0,
1034
1034
  logoutReason: p || re
1035
- }), s(), i(), y(), w();
1035
+ }), s(), c(), y(), E();
1036
1036
  },
1037
- [s, i, w, y]
1037
+ [s, c, E, y]
1038
1038
  );
1039
1039
  Me(() => {
1040
- k.isLoading && a !== null && (async () => {
1040
+ R.isLoading && a !== null && (async () => {
1041
1041
  try {
1042
1042
  const p = await H(a);
1043
1043
  p && p.payload[f.USER_ID_KEY] !== "" ? K({
@@ -1048,14 +1048,14 @@ const re = "Oops! It looks like your session has expired. For your security, ple
1048
1048
  username: p.payload[f.USERNAME_KEY]
1049
1049
  },
1050
1050
  logoutReason: ""
1051
- }) : (A(re), await ae({
1051
+ }) : (g(re), await ae({
1052
1052
  idToken: a,
1053
1053
  accessToken: o,
1054
1054
  refreshToken: u,
1055
1055
  clientId: r
1056
1056
  }));
1057
1057
  } catch {
1058
- A(re), await ae({
1058
+ g(re), await ae({
1059
1059
  idToken: a,
1060
1060
  accessToken: o,
1061
1061
  refreshToken: u,
@@ -1064,100 +1064,101 @@ const re = "Oops! It looks like your session has expired. For your security, ple
1064
1064
  }
1065
1065
  })();
1066
1066
  }, [
1067
- k.isLoading,
1067
+ R.isLoading,
1068
1068
  o,
1069
1069
  a,
1070
1070
  u,
1071
1071
  r,
1072
- A
1072
+ g
1073
1073
  ]);
1074
- const Ue = async (p, P, R) => {
1075
- const I = jt();
1076
- if (E(I), R === B.CODE) {
1074
+ const Ue = async (p, P, I) => {
1075
+ const m = jt();
1076
+ if (S(m), I === B.CODE) {
1077
1077
  const { code_verifier: $e, code_challenge: Le } = await Kt(), se = await Ft({
1078
- nonce: I,
1078
+ nonce: m,
1079
1079
  clientId: r,
1080
1080
  code_challenge: Le
1081
1081
  });
1082
1082
  if (se.status) {
1083
- const O = await ge({
1083
+ const D = await ge({
1084
1084
  username: p,
1085
1085
  password: P,
1086
1086
  clientId: r,
1087
1087
  sessionExpiration: t,
1088
- nonce: I,
1089
- type: R,
1088
+ nonce: m,
1089
+ type: I,
1090
1090
  code: se.code,
1091
1091
  code_verifier: $e
1092
1092
  });
1093
- return O.status ? (n(O.idToken), c(O.accessToken), m(O.refreshToken), K({
1093
+ return D.status ? (n(D.idToken), i(D.accessToken), w(D.refreshToken), K({
1094
1094
  isLoading: !1,
1095
1095
  isAuthenticated: !0,
1096
1096
  user: {
1097
- userId: O.userId,
1097
+ userId: D.userId,
1098
1098
  username: p
1099
1099
  },
1100
1100
  logoutReason: ""
1101
- }), !0) : (A(Ee), !1);
1101
+ }), !0) : (g(Ee), !1);
1102
1102
  }
1103
1103
  return !1;
1104
1104
  }
1105
- const S = await ge({
1105
+ const O = await ge({
1106
1106
  username: p,
1107
1107
  password: P,
1108
1108
  clientId: r,
1109
1109
  sessionExpiration: t,
1110
- nonce: I,
1111
- type: R
1110
+ nonce: m,
1111
+ type: I
1112
1112
  });
1113
- return S.status ? (n(S.idToken), c(S.accessToken), m(S.refreshToken), K({
1113
+ return O.status ? (n(O.idToken), i(O.accessToken), w(O.refreshToken), K({
1114
1114
  isLoading: !1,
1115
1115
  isAuthenticated: !0,
1116
1116
  user: {
1117
- userId: S.userId,
1117
+ userId: O.userId,
1118
1118
  username: p
1119
1119
  }
1120
- }), !0) : (A(Ee), !1);
1120
+ }), !0) : (g(Ee), !1);
1121
1121
  }, He = async () => {
1122
- A(Mt), await ae({
1122
+ g(Mt), await ae({
1123
1123
  idToken: a,
1124
1124
  accessToken: o,
1125
1125
  refreshToken: u,
1126
1126
  clientId: r
1127
1127
  });
1128
1128
  }, Ke = async () => {
1129
- const { isAuthenticated: p, user: P } = k;
1129
+ const { isAuthenticated: p, user: P } = R;
1130
1130
  try {
1131
- if (p && P && P.userId && o) {
1132
- const R = await H(o);
1133
- if (R && R.payload[f.USER_ID_KEY] !== "")
1134
- return o;
1131
+ if (p && P && P.userId) {
1132
+ if (o) {
1133
+ const m = await H(o);
1134
+ if (m && m.payload[f.USER_ID_KEY] !== "")
1135
+ return o;
1136
+ }
1135
1137
  const I = await H(u);
1136
1138
  if (I && I.payload[f.USER_ID_KEY] !== "") {
1137
- const S = await Gt({
1139
+ const m = await Gt({
1138
1140
  clientId: r,
1139
1141
  userId: P.userId,
1140
1142
  nonce: _,
1141
1143
  refreshToken: u,
1142
1144
  accessToken: o
1143
1145
  });
1144
- if (S.status)
1145
- return c(S.accessToken), m(S.refreshToken), S.accessToken;
1146
- A(U);
1146
+ return m.status ? (i(m.accessToken), w(m.refreshToken), m.accessToken) : (g(v), console.error(v), "");
1147
1147
  }
1148
- return A(U), console.error(U), "";
1148
+ return g(v), console.error(v), "";
1149
1149
  }
1150
+ return g(v), console.error(v), "";
1150
1151
  } catch {
1151
- return A(U), console.error(U), "";
1152
+ return g(v), console.error(v), "";
1152
1153
  }
1153
1154
  }, Ne = () => {
1154
- if (k.isAuthenticated && a)
1155
+ if (R.isAuthenticated && a)
1155
1156
  return a;
1156
1157
  };
1157
1158
  return /* @__PURE__ */ We(
1158
1159
  De.Provider,
1159
1160
  {
1160
- value: { ...k, login: Ue, logout: He, getAccessToken: Ke, getIdToken: Ne },
1161
+ value: { ...R, login: Ue, logout: He, getAccessToken: Ke, getIdToken: Ne },
1161
1162
  children: e
1162
1163
  }
1163
1164
  );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@versini/auth-provider",
3
- "version": "5.0.0",
3
+ "version": "5.0.1",
4
4
  "license": "MIT",
5
5
  "author": "Arno Versini",
6
6
  "publishConfig": {
@@ -46,8 +46,8 @@
46
46
  "dependencies": {
47
47
  "@versini/auth-common": "2.10.1",
48
48
  "@versini/ui-hooks": "4.0.0",
49
- "jose": "5.6.2",
49
+ "jose": "5.6.3",
50
50
  "uuid": "10.0.0"
51
51
  },
52
- "gitHead": "5a4130a33944cf31fe9bd4dd32207119bc27678d"
52
+ "gitHead": "e58285842ff21caaa538c6c0e41b840a2df569cd"
53
53
  }