@versini/auth-provider 7.0.0 → 7.1.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 +200 -194
  2. package/package.json +4 -4
package/dist/index.js CHANGED
@@ -4,13 +4,13 @@ var j = (e, t, r) => mt(e, typeof t != "symbol" ? t + "" : t, r);
4
4
  import { jsx as be } from "react/jsx-runtime";
5
5
  import wt, { useSyncExternalStore as St, useCallback as N, useEffect as He, createContext as At, useReducer as Tt, useRef as Rt, useContext as _t } from "react";
6
6
  /*!
7
- @versini/auth-provider v7.0.0
7
+ @versini/auth-provider v7.1.1
8
8
  © 2024 gizmette.com
9
9
  */
10
10
  try {
11
11
  window.__VERSINI_AUTH_CLIENT__ || (window.__VERSINI_AUTH_CLIENT__ = {
12
- version: "7.0.0",
13
- buildTime: "08/19/2024 06:11 PM EDT",
12
+ version: "7.1.1",
13
+ buildTime: "08/25/2024 03:19 PM EDT",
14
14
  homepage: "https://github.com/aversini/auth-client",
15
15
  license: "MIT"
16
16
  });
@@ -141,12 +141,12 @@ class bt {
141
141
  }
142
142
  }
143
143
  }
144
- const Je = new bt(), Ot = ["cross-platform", "platform"];
144
+ const Je = new bt(), vt = ["cross-platform", "platform"];
145
145
  function Ye(e) {
146
- if (e && !(Ot.indexOf(e) < 0))
146
+ if (e && !(vt.indexOf(e) < 0))
147
147
  return e;
148
148
  }
149
- async function vt(e) {
149
+ async function Ot(e) {
150
150
  if (!Se())
151
151
  throw new Error("WebAuthn is not supported in this browser");
152
152
  const r = { publicKey: {
@@ -162,35 +162,35 @@ async function vt(e) {
162
162
  let n;
163
163
  try {
164
164
  n = await navigator.credentials.create(r);
165
- } catch (l) {
166
- throw It({ error: l, options: r });
165
+ } catch (u) {
166
+ throw It({ error: u, options: r });
167
167
  }
168
168
  if (!n)
169
169
  throw new Error("Registration was not completed");
170
170
  const { id: a, rawId: o, response: s, type: i } = n;
171
171
  let c;
172
172
  typeof s.getTransports == "function" && (c = s.getTransports());
173
- let u;
173
+ let h;
174
174
  if (typeof s.getPublicKeyAlgorithm == "function")
175
175
  try {
176
- u = s.getPublicKeyAlgorithm();
177
- } catch (l) {
178
- he("getPublicKeyAlgorithm()", l);
176
+ h = s.getPublicKeyAlgorithm();
177
+ } catch (u) {
178
+ he("getPublicKeyAlgorithm()", u);
179
179
  }
180
- let p;
180
+ let f;
181
181
  if (typeof s.getPublicKey == "function")
182
182
  try {
183
- const l = s.getPublicKey();
184
- l !== null && (p = _(l));
185
- } catch (l) {
186
- he("getPublicKey()", l);
183
+ const u = s.getPublicKey();
184
+ u !== null && (f = _(u));
185
+ } catch (u) {
186
+ he("getPublicKey()", u);
187
187
  }
188
- let f;
188
+ let p;
189
189
  if (typeof s.getAuthenticatorData == "function")
190
190
  try {
191
- f = _(s.getAuthenticatorData());
192
- } catch (l) {
193
- he("getAuthenticatorData()", l);
191
+ p = _(s.getAuthenticatorData());
192
+ } catch (u) {
193
+ he("getAuthenticatorData()", u);
194
194
  }
195
195
  return {
196
196
  id: a,
@@ -199,9 +199,9 @@ async function vt(e) {
199
199
  attestationObject: _(s.attestationObject),
200
200
  clientDataJSON: _(s.clientDataJSON),
201
201
  transports: c,
202
- publicKeyAlgorithm: u,
203
- publicKey: p,
204
- authenticatorData: f
202
+ publicKeyAlgorithm: h,
203
+ publicKey: f,
204
+ authenticatorData: p
205
205
  },
206
206
  type: i,
207
207
  clientExtensionResults: n.getClientExtensionResults(),
@@ -280,23 +280,23 @@ async function Ct(e, t = !1) {
280
280
  let o;
281
281
  try {
282
282
  o = await navigator.credentials.get(a);
283
- } catch (f) {
284
- throw Pt({ error: f, options: a });
283
+ } catch (p) {
284
+ throw Pt({ error: p, options: a });
285
285
  }
286
286
  if (!o)
287
287
  throw new Error("Authentication was not completed");
288
- const { id: s, rawId: i, response: c, type: u } = o;
289
- let p;
290
- return c.userHandle && (p = _(c.userHandle)), {
288
+ const { id: s, rawId: i, response: c, type: h } = o;
289
+ let f;
290
+ return c.userHandle && (f = _(c.userHandle)), {
291
291
  id: s,
292
292
  rawId: _(i),
293
293
  response: {
294
294
  authenticatorData: _(c.authenticatorData),
295
295
  clientDataJSON: _(c.clientDataJSON),
296
296
  signature: _(c.signature),
297
- userHandle: p
297
+ userHandle: f
298
298
  },
299
- type: u,
299
+ type: h,
300
300
  clientExtensionResults: o.getClientExtensionResults(),
301
301
  authenticatorAttachment: Ye(o.authenticatorAttachment)
302
302
  };
@@ -308,7 +308,7 @@ async function Ct(e, t = !1) {
308
308
  try {
309
309
  window.__VERSINI_AUTH_COMMON__ || (window.__VERSINI_AUTH_COMMON__ = {
310
310
  version: "4.0.0",
311
- buildTime: "08/19/2024 06:11 PM EDT",
311
+ buildTime: "08/25/2024 03:19 PM EDT",
312
312
  homepage: "https://github.com/aversini/auth-client",
313
313
  license: "MIT"
314
314
  });
@@ -387,7 +387,7 @@ class R extends D {
387
387
  super(t), this.code = "ERR_JWT_CLAIM_VALIDATION_FAILED", this.claim = n, this.reason = a, this.payload = r;
388
388
  }
389
389
  }
390
- class Oe extends D {
390
+ class ve extends D {
391
391
  static get code() {
392
392
  return "ERR_JWT_EXPIRED";
393
393
  }
@@ -419,7 +419,7 @@ class m extends D {
419
419
  return "ERR_JWS_INVALID";
420
420
  }
421
421
  }
422
- let O = class extends D {
422
+ let v = class extends D {
423
423
  constructor() {
424
424
  super(...arguments), this.code = "ERR_JWT_INVALID";
425
425
  }
@@ -427,7 +427,7 @@ let O = class extends D {
427
427
  return "ERR_JWT_INVALID";
428
428
  }
429
429
  };
430
- class Lt extends D {
430
+ class $t extends D {
431
431
  constructor() {
432
432
  super(...arguments), this.code = "ERR_JWS_SIGNATURE_VERIFICATION_FAILED", this.message = "signature verification failed";
433
433
  }
@@ -444,7 +444,7 @@ function B(e, t) {
444
444
  function pe(e) {
445
445
  return parseInt(e.name.slice(4), 10);
446
446
  }
447
- function $t(e) {
447
+ function Lt(e) {
448
448
  switch (e) {
449
449
  case "ES256":
450
450
  return "P-256";
@@ -508,7 +508,7 @@ function Wt(e, t, ...r) {
508
508
  case "ES512": {
509
509
  if (!B(e.algorithm, "ECDSA"))
510
510
  throw b("ECDSA");
511
- const n = $t(t);
511
+ const n = Lt(t);
512
512
  if (e.algorithm.namedCurve !== n)
513
513
  throw b(n, "algorithm.namedCurve");
514
514
  break;
@@ -526,7 +526,7 @@ function Ve(e, t, ...r) {
526
526
  } else r.length === 2 ? e += `one of type ${r[0]} or ${r[1]}.` : e += `of type ${r[0]}.`;
527
527
  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;
528
528
  }
529
- const ve = (e, ...t) => Ve("Key must be ", e, ...t);
529
+ const Oe = (e, ...t) => Ve("Key must be ", e, ...t);
530
530
  function je(e, t, ...r) {
531
531
  return Ve(`Key for the ${e} algorithm must be `, t, ...r);
532
532
  }
@@ -670,28 +670,28 @@ const qe = (e) => e?.[Symbol.toStringTag] === "KeyObject", ze = async (e, t, r,
670
670
  return r.k ? Be(r.k) : (fe || (fe = /* @__PURE__ */ new WeakMap()), ze(fe, e, r, t));
671
671
  }
672
672
  return e;
673
- }, Ft = { normalizePublicKey: Vt, normalizePrivateKey: jt }, v = (e, t, r = 0) => {
673
+ }, Ft = { normalizePublicKey: Vt, normalizePrivateKey: jt }, O = (e, t, r = 0) => {
674
674
  r === 0 && (t.unshift(t.length), t.unshift(6));
675
675
  const n = e.indexOf(t[0], r);
676
676
  if (n === -1)
677
677
  return !1;
678
678
  const a = e.subarray(n, n + t.length);
679
- return a.length !== t.length ? !1 : a.every((o, s) => o === t[s]) || v(e, t, n + 1);
679
+ return a.length !== t.length ? !1 : a.every((o, s) => o === t[s]) || O(e, t, n + 1);
680
680
  }, ke = (e) => {
681
681
  switch (!0) {
682
- case v(e, [42, 134, 72, 206, 61, 3, 1, 7]):
682
+ case O(e, [42, 134, 72, 206, 61, 3, 1, 7]):
683
683
  return "P-256";
684
- case v(e, [43, 129, 4, 0, 34]):
684
+ case O(e, [43, 129, 4, 0, 34]):
685
685
  return "P-384";
686
- case v(e, [43, 129, 4, 0, 35]):
686
+ case O(e, [43, 129, 4, 0, 35]):
687
687
  return "P-521";
688
- case v(e, [43, 101, 110]):
688
+ case O(e, [43, 101, 110]):
689
689
  return "X25519";
690
- case v(e, [43, 101, 111]):
690
+ case O(e, [43, 101, 111]):
691
691
  return "X448";
692
- case v(e, [43, 101, 112]):
692
+ case O(e, [43, 101, 112]):
693
693
  return "Ed25519";
694
- case v(e, [43, 101, 113]):
694
+ case O(e, [43, 101, 113]):
695
695
  return "Ed448";
696
696
  default:
697
697
  throw new k("Invalid or unsupported EC Key Curve or OKP Key Sub Type");
@@ -823,10 +823,10 @@ async function nr(e, t, r) {
823
823
  return Wt(t, e, r), t;
824
824
  if (t instanceof Uint8Array) {
825
825
  if (!e.startsWith("HS"))
826
- throw new TypeError(ve(t, ...ne));
826
+ throw new TypeError(Oe(t, ...ne));
827
827
  return ce.subtle.importKey("raw", t, { hash: `SHA-${e.slice(-3)}`, name: "HMAC" }, !1, [r]);
828
828
  }
829
- throw new TypeError(ve(t, ...ne, "Uint8Array"));
829
+ throw new TypeError(Oe(t, ...ne, "Uint8Array"));
830
830
  }
831
831
  const ar = async (e, t, r, n) => {
832
832
  const a = await nr(e, t, "verify");
@@ -879,27 +879,27 @@ async function sr(e, t, r) {
879
879
  throw new m("JWS Payload must be a string");
880
880
  } else if (typeof e.payload != "string" && !(e.payload instanceof Uint8Array))
881
881
  throw new m("JWS Payload must be a string or an Uint8Array instance");
882
- let u = !1;
883
- typeof t == "function" && (t = await t(n, e), u = !0), Zt(i, t, "verify");
884
- const p = Dt(F.encode(e.protected ?? ""), F.encode("."), typeof e.payload == "string" ? F.encode(e.payload) : e.payload);
885
- let f;
882
+ let h = !1;
883
+ typeof t == "function" && (t = await t(n, e), h = !0), Zt(i, t, "verify");
884
+ const f = Dt(F.encode(e.protected ?? ""), F.encode("."), typeof e.payload == "string" ? F.encode(e.payload) : e.payload);
885
+ let p;
886
886
  try {
887
- f = Y(e.signature);
887
+ p = Y(e.signature);
888
888
  } catch {
889
889
  throw new m("Failed to base64url decode the signature");
890
890
  }
891
- if (!await ar(i, t, f, p))
892
- throw new Lt();
893
- let l;
891
+ if (!await ar(i, t, p, f))
892
+ throw new $t();
893
+ let u;
894
894
  if (s)
895
895
  try {
896
- l = Y(e.payload);
896
+ u = Y(e.payload);
897
897
  } catch {
898
898
  throw new m("Failed to base64url decode the payload");
899
899
  }
900
- else typeof e.payload == "string" ? l = F.encode(e.payload) : l = e.payload;
901
- const A = { payload: l };
902
- return e.protected !== void 0 && (A.protectedHeader = n), e.header !== void 0 && (A.unprotectedHeader = e.header), u ? { ...A, key: t } : A;
900
+ else typeof e.payload == "string" ? u = F.encode(e.payload) : u = e.payload;
901
+ const A = { payload: u };
902
+ return e.protected !== void 0 && (A.protectedHeader = n), e.header !== void 0 && (A.unprotectedHeader = e.header), h ? { ...A, key: t } : A;
903
903
  }
904
904
  async function or(e, t, r) {
905
905
  if (e instanceof Uint8Array && (e = G.decode(e)), typeof e != "string")
@@ -960,13 +960,13 @@ const ir = (e) => Math.floor(e.getTime() / 1e3), Qe = 60, Xe = Qe * 60, Ae = Xe
960
960
  } catch {
961
961
  }
962
962
  if (!ae(n))
963
- throw new O("JWT Claims Set must be a top-level JSON object");
963
+ throw new v("JWT Claims Set must be a top-level JSON object");
964
964
  const { typ: a } = r;
965
965
  if (a && (typeof e.typ != "string" || Ce(e.typ) !== Ce(a)))
966
966
  throw new R('unexpected "typ" JWT header value', n, "typ", "check_failed");
967
- const { requiredClaims: o = [], issuer: s, subject: i, audience: c, maxTokenAge: u } = r, p = [...o];
968
- u !== void 0 && p.push("iat"), c !== void 0 && p.push("aud"), i !== void 0 && p.push("sub"), s !== void 0 && p.push("iss");
969
- for (const T of new Set(p.reverse()))
967
+ const { requiredClaims: o = [], issuer: s, subject: i, audience: c, maxTokenAge: h } = r, f = [...o];
968
+ h !== void 0 && f.push("iat"), c !== void 0 && f.push("aud"), i !== void 0 && f.push("sub"), s !== void 0 && f.push("iss");
969
+ for (const T of new Set(f.reverse()))
970
970
  if (!(T in n))
971
971
  throw new R(`missing required "${T}" claim`, n, T, "missing");
972
972
  if (s && !(Array.isArray(s) ? s : [s]).includes(n.iss))
@@ -975,40 +975,40 @@ const ir = (e) => Math.floor(e.getTime() / 1e3), Qe = 60, Xe = Qe * 60, Ae = Xe
975
975
  throw new R('unexpected "sub" claim value', n, "sub", "check_failed");
976
976
  if (c && !dr(n.aud, typeof c == "string" ? [c] : c))
977
977
  throw new R('unexpected "aud" claim value', n, "aud", "check_failed");
978
- let f;
978
+ let p;
979
979
  switch (typeof r.clockTolerance) {
980
980
  case "string":
981
- f = Pe(r.clockTolerance);
981
+ p = Pe(r.clockTolerance);
982
982
  break;
983
983
  case "number":
984
- f = r.clockTolerance;
984
+ p = r.clockTolerance;
985
985
  break;
986
986
  case "undefined":
987
- f = 0;
987
+ p = 0;
988
988
  break;
989
989
  default:
990
990
  throw new TypeError("Invalid clockTolerance option type");
991
991
  }
992
- const { currentDate: l } = r, A = ir(l || /* @__PURE__ */ new Date());
993
- if ((n.iat !== void 0 || u) && typeof n.iat != "number")
992
+ const { currentDate: u } = r, A = ir(u || /* @__PURE__ */ new Date());
993
+ if ((n.iat !== void 0 || h) && typeof n.iat != "number")
994
994
  throw new R('"iat" claim must be a number', n, "iat", "invalid");
995
995
  if (n.nbf !== void 0) {
996
996
  if (typeof n.nbf != "number")
997
997
  throw new R('"nbf" claim must be a number', n, "nbf", "invalid");
998
- if (n.nbf > A + f)
998
+ if (n.nbf > A + p)
999
999
  throw new R('"nbf" claim timestamp check failed', n, "nbf", "check_failed");
1000
1000
  }
1001
1001
  if (n.exp !== void 0) {
1002
1002
  if (typeof n.exp != "number")
1003
1003
  throw new R('"exp" claim must be a number', n, "exp", "invalid");
1004
- if (n.exp <= A - f)
1005
- throw new Oe('"exp" claim timestamp check failed', n, "exp", "check_failed");
1004
+ if (n.exp <= A - p)
1005
+ throw new ve('"exp" claim timestamp check failed', n, "exp", "check_failed");
1006
1006
  }
1007
- if (u) {
1008
- const T = A - n.iat, le = typeof u == "number" ? u : Pe(u);
1009
- if (T - f > le)
1010
- throw new Oe('"iat" claim timestamp check failed (too far in the past)', n, "iat", "check_failed");
1011
- if (T < 0 - f)
1007
+ if (h) {
1008
+ const T = A - n.iat, le = typeof h == "number" ? h : Pe(h);
1009
+ if (T - p > le)
1010
+ throw new ve('"iat" claim timestamp check failed (too far in the past)', n, "iat", "check_failed");
1011
+ if (T < 0 - p)
1012
1012
  throw new R('"iat" claim timestamp check failed (it should be in the past)', n, "iat", "check_failed");
1013
1013
  }
1014
1014
  return n;
@@ -1017,35 +1017,35 @@ async function pr(e, t, r) {
1017
1017
  var n;
1018
1018
  const a = await or(e, t, r);
1019
1019
  if ((n = a.protectedHeader.crit) != null && n.includes("b64") && a.protectedHeader.b64 === !1)
1020
- throw new O("JWTs MUST NOT use unencoded payload");
1020
+ throw new v("JWTs MUST NOT use unencoded payload");
1021
1021
  const o = { payload: hr(a.protectedHeader, a.payload, r), protectedHeader: a.protectedHeader };
1022
1022
  return typeof t == "function" ? { ...o, key: a.key } : o;
1023
1023
  }
1024
1024
  const fr = Y;
1025
1025
  function yr(e) {
1026
1026
  if (typeof e != "string")
1027
- throw new O("JWTs must use Compact JWS serialization, JWT must be a string");
1027
+ throw new v("JWTs must use Compact JWS serialization, JWT must be a string");
1028
1028
  const { 1: t, length: r } = e.split(".");
1029
1029
  if (r === 5)
1030
- throw new O("Only JWTs using Compact JWS serialization can be decoded");
1030
+ throw new v("Only JWTs using Compact JWS serialization can be decoded");
1031
1031
  if (r !== 3)
1032
- throw new O("Invalid JWT");
1032
+ throw new v("Invalid JWT");
1033
1033
  if (!t)
1034
- throw new O("JWTs must contain a payload");
1034
+ throw new v("JWTs must contain a payload");
1035
1035
  let n;
1036
1036
  try {
1037
1037
  n = fr(t);
1038
1038
  } catch {
1039
- throw new O("Failed to base64url decode the payload");
1039
+ throw new v("Failed to base64url decode the payload");
1040
1040
  }
1041
1041
  let a;
1042
1042
  try {
1043
1043
  a = JSON.parse(G.decode(n));
1044
1044
  } catch {
1045
- throw new O("Failed to parse the decoded payload as JSON");
1045
+ throw new v("Failed to parse the decoded payload as JSON");
1046
1046
  }
1047
1047
  if (!ae(a))
1048
- throw new O("Invalid JWT Claims Set");
1048
+ throw new v("Invalid JWT Claims Set");
1049
1049
  return a;
1050
1050
  }
1051
1051
  const H = async (e) => {
@@ -1125,12 +1125,12 @@ const Ke = (e, t) => {
1125
1125
  window.localStorage.setItem(e, r), Ze(e, r);
1126
1126
  }, Ir = (e) => {
1127
1127
  window.localStorage.removeItem(e), Ze(e, null);
1128
- }, Le = (e) => window.localStorage.getItem(e), br = (e) => (window.addEventListener("storage", e), () => window.removeEventListener("storage", e));
1128
+ }, $e = (e) => window.localStorage.getItem(e), br = (e) => (window.addEventListener("storage", e), () => window.removeEventListener("storage", e));
1129
1129
  function z({
1130
1130
  key: e,
1131
1131
  initialValue: t
1132
1132
  }) {
1133
- const r = St(br, () => Le(e)), n = N(
1133
+ const r = St(br, () => $e(e)), n = N(
1134
1134
  (s) => {
1135
1135
  try {
1136
1136
  const i = typeof s == "function" ? s(JSON.parse(r)) : s;
@@ -1147,7 +1147,7 @@ function z({
1147
1147
  }, [n]);
1148
1148
  return He(() => {
1149
1149
  try {
1150
- Le(e) === null && typeof t < "u" && Ke(e, t);
1150
+ $e(e) === null && typeof t < "u" && Ke(e, t);
1151
1151
  } catch (s) {
1152
1152
  console.warn(s);
1153
1153
  }
@@ -1156,25 +1156,25 @@ function z({
1156
1156
  var E = [];
1157
1157
  for (var Ee = 0; Ee < 256; ++Ee)
1158
1158
  E.push((Ee + 256).toString(16).slice(1));
1159
- function Or(e, t = 0) {
1159
+ function vr(e, t = 0) {
1160
1160
  return (E[e[t + 0]] + E[e[t + 1]] + E[e[t + 2]] + E[e[t + 3]] + "-" + E[e[t + 4]] + E[e[t + 5]] + "-" + E[e[t + 6]] + E[e[t + 7]] + "-" + E[e[t + 8]] + E[e[t + 9]] + "-" + E[e[t + 10]] + E[e[t + 11]] + E[e[t + 12]] + E[e[t + 13]] + E[e[t + 14]] + E[e[t + 15]]).toLowerCase();
1161
1161
  }
1162
- var Q, vr = new Uint8Array(16);
1162
+ var Q, Or = new Uint8Array(16);
1163
1163
  function kr() {
1164
1164
  if (!Q && (Q = typeof crypto < "u" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto), !Q))
1165
1165
  throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
1166
- return Q(vr);
1166
+ return Q(Or);
1167
1167
  }
1168
1168
  var Pr = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto);
1169
- const $e = {
1169
+ const Le = {
1170
1170
  randomUUID: Pr
1171
1171
  };
1172
1172
  function me(e, t, r) {
1173
- if ($e.randomUUID && !t && !e)
1174
- return $e.randomUUID();
1173
+ if (Le.randomUUID && !t && !e)
1174
+ return Le.randomUUID();
1175
1175
  e = e || {};
1176
1176
  var n = e.random || (e.rng || kr)();
1177
- return n[6] = n[6] & 15 | 64, n[8] = n[8] & 63 | 128, Or(n);
1177
+ return n[6] = n[6] & 15 | 64, n[8] = n[8] & 63 | 128, vr(n);
1178
1178
  }
1179
1179
  const U = "Your session has expired. For your security, please log in again to continue.", Cr = "Your session has been successfully terminated.", we = "Login failed. Please try again.", Nr = "Error getting access token, please re-authenticate.", Dr = "You forgot to wrap your component in <AuthProvider>.", se = {
1180
1180
  dev: "https://auth.gizmette.local.com:3003",
@@ -1241,14 +1241,16 @@ const U = "Your session has expired. For your security, please log in again to c
1241
1241
  $authentication: AuthenticationOptionsInput!,
1242
1242
  $nonce: String!,
1243
1243
  $domain: String,
1244
- $sessionExpiration: String) {
1244
+ $sessionExpiration: String,
1245
+ $ua: String) {
1245
1246
  verifyPasskeyAuthentication(
1246
1247
  clientId: $clientId,
1247
1248
  id: $id,
1248
1249
  authentication: $authentication,
1249
1250
  nonce: $nonce,
1250
1251
  domain: $domain,
1251
- sessionExpiration: $sessionExpiration) {
1252
+ sessionExpiration: $sessionExpiration,
1253
+ ua: $ua) {
1252
1254
  status,
1253
1255
  idToken,
1254
1256
  accessToken,
@@ -1274,35 +1276,35 @@ const U = "Your session has expired. For your security, please log in again to c
1274
1276
  schema: Z.VERIFY_AUTHENTICATION,
1275
1277
  method: "verifyPasskeyAuthentication"
1276
1278
  }
1277
- }, L = async ({
1279
+ }, $ = async ({
1278
1280
  accessToken: e,
1279
1281
  type: t,
1280
1282
  clientId: r,
1281
1283
  params: n = {}
1282
1284
  }) => {
1283
1285
  try {
1284
- const a = n, o = `Bearer ${e}`, s = await fetch(
1286
+ const a = `Bearer ${e}`, o = await fetch(
1285
1287
  at ? `${se.dev}/graphql` : `${se.prod}/graphql`,
1286
1288
  {
1287
1289
  credentials: tt,
1288
1290
  method: rt,
1289
1291
  headers: {
1290
- authorization: o,
1292
+ authorization: a,
1291
1293
  "Content-Type": nt,
1292
1294
  [Ge.CLIENT_ID]: `${r}`
1293
1295
  },
1294
1296
  body: JSON.stringify({
1295
1297
  query: t.schema,
1296
- variables: a
1298
+ variables: n
1297
1299
  })
1298
1300
  }
1299
1301
  );
1300
- if (s.status !== 200)
1302
+ if (o.status !== 200)
1301
1303
  return { status: I, data: [] };
1302
- const { data: i } = await s.json();
1304
+ const { data: s } = await o.json();
1303
1305
  return {
1304
1306
  status: M,
1305
- data: i[t.method]
1307
+ data: s[t.method]
1306
1308
  };
1307
1309
  } catch (a) {
1308
1310
  return console.error(a), { status: I, data: [] };
@@ -1348,7 +1350,7 @@ const U = "Your session has expired. For your security, please log in again to c
1348
1350
  } catch {
1349
1351
  return "";
1350
1352
  }
1351
- }, Lr = async ({
1353
+ }, $r = async ({
1352
1354
  userId: e,
1353
1355
  clientId: t,
1354
1356
  domain: r
@@ -1369,7 +1371,7 @@ const U = "Your session has expired. For your security, please log in again to c
1369
1371
  status: I
1370
1372
  };
1371
1373
  }
1372
- }, $r = async ({
1374
+ }, Lr = async ({
1373
1375
  username: e,
1374
1376
  password: t,
1375
1377
  clientId: r,
@@ -1378,10 +1380,11 @@ const U = "Your session has expired. For your security, please log in again to c
1378
1380
  sessionExpiration: o,
1379
1381
  code: s,
1380
1382
  code_verifier: i,
1381
- domain: c
1383
+ domain: c,
1384
+ ua: h
1382
1385
  }) => {
1383
1386
  try {
1384
- const u = await ue({
1387
+ const f = await ue({
1385
1388
  type: ie.LOGIN,
1386
1389
  clientId: r,
1387
1390
  params: {
@@ -1392,13 +1395,14 @@ const U = "Your session has expired. For your security, please log in again to c
1392
1395
  nonce: n,
1393
1396
  code: s,
1394
1397
  code_verifier: i,
1395
- domain: c
1398
+ domain: c,
1399
+ ua: h
1396
1400
  }
1397
- }), p = await H(u?.data?.idToken);
1401
+ }), p = await H(f?.data?.idToken);
1398
1402
  return p && p.payload[S.USER_ID_KEY] !== "" && p.payload[S.NONCE_KEY] === n ? {
1399
- idToken: u.data.idToken,
1400
- accessToken: u.data.accessToken,
1401
- refreshToken: u.data.refreshToken,
1403
+ idToken: f.data.idToken,
1404
+ accessToken: f.data.accessToken,
1405
+ refreshToken: f.data.refreshToken,
1402
1406
  userId: p.payload[S.USER_ID_KEY],
1403
1407
  status: !0
1404
1408
  } : {
@@ -1531,17 +1535,17 @@ const Jr = (e) => N(
1531
1535
  e && console.info(`==> [Auth ${Date.now()}]: `, ...t);
1532
1536
  },
1533
1537
  [e]
1534
- ), $ = () => {
1538
+ ), L = () => {
1535
1539
  throw new Error(Dr);
1536
1540
  }, ot = At({
1537
1541
  isAuthenticated: !1,
1538
1542
  isLoading: !1,
1539
- login: $,
1540
- logout: $,
1541
- getAccessToken: $,
1542
- getIdToken: $,
1543
- registeringForPasskey: $,
1544
- loginWithPasskey: $,
1543
+ login: L,
1544
+ logout: L,
1545
+ getAccessToken: L,
1546
+ getIdToken: L,
1547
+ registeringForPasskey: L,
1548
+ loginWithPasskey: L,
1545
1549
  logoutReason: ""
1546
1550
  }), Yr = wt.createContext({
1547
1551
  state: st,
@@ -1572,9 +1576,9 @@ const Jr = (e) => N(
1572
1576
  const [o, s] = Tt(Gr, {
1573
1577
  ...st,
1574
1578
  debug: a
1575
- }), i = Jr(a), c = Rt(!1), [u, p, , f] = z({
1579
+ }), i = Jr(a), c = Rt(!1), [h, f, , p] = z({
1576
1580
  key: `${X}::${r}::@@user@@`
1577
- }), [l, A, , T] = z({
1581
+ }), [u, A, , T] = z({
1578
1582
  key: `${X}::${r}::@@access@@`
1579
1583
  }), [le, de, , Te] = z(
1580
1584
  {
@@ -1582,52 +1586,52 @@ const Jr = (e) => N(
1582
1586
  }
1583
1587
  ), [it, Re, , _e] = z({
1584
1588
  key: `${X}::${r}::@@nonce@@`
1585
- }), ct = new xr(l, le), V = N(() => {
1586
- i("removeLocalStorage: removing local storage"), f(), T(), Te(), _e();
1589
+ }), ct = new xr(u, le), V = N(() => {
1590
+ i("removeLocalStorage: removing local storage"), p(), T(), Te(), _e();
1587
1591
  }, [
1588
1592
  T,
1589
- f,
1593
+ p,
1590
1594
  _e,
1591
1595
  Te,
1592
1596
  i
1593
1597
  ]), W = N(
1594
- (d) => {
1598
+ (l) => {
1595
1599
  i(
1596
1600
  "removeStateAndLocalStorage: removing state and local storage with reason: ",
1597
- d
1601
+ l
1598
1602
  ), s({
1599
1603
  type: et,
1600
1604
  payload: {
1601
- logoutReason: d || U
1605
+ logoutReason: l || U
1602
1606
  }
1603
1607
  }), V(), s({ type: J, payload: { isLoading: !1 } });
1604
1608
  },
1605
1609
  [V, i]
1606
1610
  ), P = N(
1607
- async (d) => {
1611
+ async (l) => {
1608
1612
  i("invalidateAndLogout: invalidating and logging out");
1609
- const { user: y } = o, h = y?.userId || Kr(u);
1610
- h || i(
1613
+ const { user: y } = o, d = y?.userId || Kr(h);
1614
+ d || i(
1611
1615
  "invalidateAndLogout: user cannot be identified, logging out without userId"
1612
- ), await Lr({
1613
- userId: h,
1616
+ ), await $r({
1617
+ userId: d,
1614
1618
  clientId: r,
1615
1619
  domain: n
1616
- }), W(d || U);
1620
+ }), W(l || U);
1617
1621
  },
1618
- [u, o, r, n, W, i]
1622
+ [h, o, r, n, W, i]
1619
1623
  );
1620
1624
  He(() => {
1621
1625
  if (!c.current)
1622
- return o.isLoading && u !== null ? (async () => {
1626
+ return o.isLoading && h !== null ? (async () => {
1623
1627
  try {
1624
- const d = await H(u);
1625
- d && d.payload[S.USER_ID_KEY] !== "" ? (i("useEffect: setting the authentication state"), s({
1628
+ const l = await H(h);
1629
+ l && l.payload[S.USER_ID_KEY] !== "" ? (i("useEffect: setting the authentication state"), s({
1626
1630
  type: te,
1627
1631
  payload: {
1628
1632
  user: {
1629
- userId: d.payload[S.USER_ID_KEY],
1630
- username: d.payload[S.USERNAME_KEY]
1633
+ userId: l.payload[S.USER_ID_KEY],
1634
+ username: l.payload[S.USERNAME_KEY]
1631
1635
  }
1632
1636
  }
1633
1637
  })) : (i("useEffect: invalid JWT, invalidating and logging out"), await P(U));
@@ -1639,59 +1643,60 @@ const Jr = (e) => N(
1639
1643
  })() : (i("useEffect: setting the loading state to false"), s({ type: J, payload: { isLoading: !1 } })), () => {
1640
1644
  c.current = !0;
1641
1645
  };
1642
- }, [o.isLoading, u, P, i]);
1643
- const ut = async (d, y) => {
1646
+ }, [o.isLoading, h, P, i]);
1647
+ const ut = async (l, y) => {
1644
1648
  s({ type: J, payload: { isLoading: !0 } }), V();
1645
- const h = me();
1646
- Re(h), i("login: Logging in with password");
1649
+ const d = me();
1650
+ Re(d), i("login: Logging in with password");
1647
1651
  const C = oe.CODE, { code_verifier: yt, code_challenge: gt } = await _r(), Ie = await Hr({
1648
- nonce: h,
1652
+ nonce: d,
1649
1653
  clientId: r,
1650
1654
  code_challenge: gt
1651
1655
  });
1652
1656
  if (Ie.status) {
1653
- const x = await $r({
1654
- username: d,
1657
+ const x = await Lr({
1658
+ username: l,
1655
1659
  password: y,
1656
1660
  clientId: r,
1657
1661
  sessionExpiration: t,
1658
- nonce: h,
1662
+ nonce: d,
1659
1663
  type: C,
1660
1664
  code: Ie.data,
1661
1665
  code_verifier: yt,
1662
- domain: n
1666
+ domain: n,
1667
+ ua: navigator.userAgent
1663
1668
  });
1664
- return x.status ? (p(x.idToken), A(x.accessToken), de(x.refreshToken), s({
1669
+ return x.status ? (f(x.idToken), A(x.accessToken), de(x.refreshToken), s({
1665
1670
  type: te,
1666
1671
  payload: {
1667
1672
  user: {
1668
1673
  userId: x.userId,
1669
- username: d
1674
+ username: l
1670
1675
  }
1671
1676
  }
1672
1677
  }), !0) : (W(we), !1);
1673
1678
  }
1674
1679
  return !1;
1675
- }, lt = async (d) => {
1676
- d?.preventDefault(), await P(Cr);
1680
+ }, lt = async (l) => {
1681
+ l?.preventDefault(), await P(Cr);
1677
1682
  }, dt = async () => {
1678
- const { isAuthenticated: d, user: y } = o;
1683
+ const { isAuthenticated: l, user: y } = o;
1679
1684
  try {
1680
- if (d && y && y.userId) {
1681
- if (l) {
1685
+ if (l && y && y.userId) {
1686
+ if (u) {
1682
1687
  i("getAccessToken");
1683
- const C = await H(l);
1688
+ const C = await H(u);
1684
1689
  if (C && C.payload[S.USER_ID_KEY] !== "")
1685
- return l;
1690
+ return u;
1686
1691
  }
1687
1692
  i("getAccessToken: invalid access token, trying to refresh it");
1688
- const h = await ct.refreshtoken({
1693
+ const d = await ct.refreshtoken({
1689
1694
  clientId: r,
1690
1695
  userId: y.userId,
1691
1696
  nonce: it,
1692
1697
  domain: n
1693
1698
  });
1694
- return h.status && h.status === "success" && h.newAccessToken ? (A(h.newAccessToken), de(h.newRefreshToken), h.newAccessToken) : (i(
1699
+ return d.status && d.status === "success" && d.newAccessToken ? (A(d.newAccessToken), de(d.newRefreshToken), d.newAccessToken) : (i(
1695
1700
  "getAccessToken: invalid refresh token, need to re-authenticate"
1696
1701
  ), await P(U), "");
1697
1702
  }
@@ -1703,41 +1708,41 @@ const Jr = (e) => N(
1703
1708
  "getAccessToken: exception occurred, invalidating and logging out"
1704
1709
  ), await P(Nr), "";
1705
1710
  }
1706
- }, ht = () => o.isAuthenticated && u ? u : "", pt = async () => {
1707
- const { user: d } = o;
1708
- let y = await L({
1709
- accessToken: l,
1711
+ }, ht = () => o.isAuthenticated && h ? h : "", pt = async () => {
1712
+ const { user: l } = o;
1713
+ let y = await $({
1714
+ accessToken: u,
1710
1715
  clientId: r,
1711
1716
  type: K.GET_REGISTRATION_OPTIONS,
1712
1717
  params: {
1713
1718
  clientId: r,
1714
- id: d?.userId,
1715
- username: d?.username
1719
+ id: l?.userId,
1720
+ username: l?.username
1716
1721
  }
1717
1722
  });
1718
1723
  if (y.status)
1719
1724
  try {
1720
- const h = await vt(y.data);
1721
- return y = await L({
1722
- accessToken: l,
1725
+ const d = await Ot(y.data);
1726
+ return y = await $({
1727
+ accessToken: u,
1723
1728
  clientId: r,
1724
1729
  type: K.VERIFY_REGISTRATION,
1725
1730
  params: {
1726
1731
  clientId: r,
1727
- id: d?.userId,
1728
- username: d?.username,
1729
- registration: h
1732
+ id: l?.userId,
1733
+ username: l?.username,
1734
+ registration: d
1730
1735
  }
1731
1736
  }), !!(y.status && y.data.length > 0);
1732
1737
  } catch {
1733
- return await L({
1734
- accessToken: l,
1738
+ return await $({
1739
+ accessToken: u,
1735
1740
  clientId: r,
1736
1741
  type: K.VERIFY_REGISTRATION,
1737
1742
  params: {
1738
1743
  clientId: r,
1739
- id: d?.userId,
1740
- username: d?.username,
1744
+ id: l?.userId,
1745
+ username: l?.username,
1741
1746
  registration: {}
1742
1747
  }
1743
1748
  }), !1;
@@ -1745,11 +1750,11 @@ const Jr = (e) => N(
1745
1750
  return !1;
1746
1751
  }, ft = async () => {
1747
1752
  s({ type: J, payload: { isLoading: !0 } }), V();
1748
- const d = me();
1749
- Re(d), i("loginWithPasskey");
1753
+ const l = me();
1754
+ Re(l), i("loginWithPasskey");
1750
1755
  const y = me();
1751
- let h = await L({
1752
- accessToken: l,
1756
+ let d = await $({
1757
+ accessToken: u,
1753
1758
  clientId: r,
1754
1759
  type: K.GET_AUTHENTICATION_OPTIONS,
1755
1760
  params: {
@@ -1757,40 +1762,41 @@ const Jr = (e) => N(
1757
1762
  clientId: r
1758
1763
  }
1759
1764
  });
1760
- if (h.status)
1765
+ if (d.status)
1761
1766
  try {
1762
- const C = await Ct(h.data);
1763
- return h = await L({
1764
- accessToken: l,
1767
+ const C = await Ct(d.data);
1768
+ return d = await $({
1769
+ accessToken: u,
1765
1770
  clientId: r,
1766
1771
  type: K.VERIFY_AUTHENTICATION,
1767
1772
  params: {
1768
1773
  clientId: r,
1769
1774
  id: y,
1770
1775
  authentication: C,
1771
- nonce: d,
1776
+ nonce: l,
1772
1777
  domain: n,
1773
- sessionExpiration: t
1778
+ sessionExpiration: t,
1779
+ ua: navigator.userAgent
1774
1780
  }
1775
- }), h.data.status === M ? (p(h.data.idToken), A(h.data.accessToken), de(h.data.refreshToken), s({
1781
+ }), d.data.status === M ? (f(d.data.idToken), A(d.data.accessToken), de(d.data.refreshToken), s({
1776
1782
  type: te,
1777
1783
  payload: {
1778
1784
  user: {
1779
- userId: h.data.userId,
1780
- username: h.data.username
1785
+ userId: d.data.userId,
1786
+ username: d.data.username
1781
1787
  }
1782
1788
  }
1783
1789
  }), !0) : (W(we), !1);
1784
1790
  } catch {
1785
- return await L({
1786
- accessToken: l,
1791
+ return await $({
1792
+ accessToken: u,
1787
1793
  clientId: r,
1788
1794
  type: K.VERIFY_AUTHENTICATION,
1789
1795
  params: {
1790
1796
  clientId: r,
1791
1797
  id: y,
1792
1798
  authentication: {},
1793
- nonce: d,
1799
+ nonce: l,
1794
1800
  domain: n,
1795
1801
  sessionExpiration: t
1796
1802
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@versini/auth-provider",
3
- "version": "7.0.0",
3
+ "version": "7.1.1",
4
4
  "license": "MIT",
5
5
  "author": "Arno Versini",
6
6
  "publishConfig": {
@@ -46,9 +46,9 @@
46
46
  "dependencies": {
47
47
  "@simplewebauthn/browser": "10.0.0",
48
48
  "@versini/auth-common": "4.0.0",
49
- "@versini/ui-hooks": "4.0.1",
50
- "jose": "5.6.3",
49
+ "@versini/ui-hooks": "4.1.0",
50
+ "jose": "5.7.0",
51
51
  "uuid": "10.0.0"
52
52
  },
53
- "gitHead": "810b2920c2281e78b52ffbe1db7e52f4fefa8cbe"
53
+ "gitHead": "f91f2bce0bb2cc3887be4b53132b0a96549877d7"
54
54
  }