@versini/auth-provider 7.2.0 → 7.3.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.
package/dist/index.d.ts CHANGED
@@ -19,6 +19,7 @@ type AuthState = {
19
19
  user?: {
20
20
  userId?: string;
21
21
  username?: string;
22
+ email?: string;
22
23
  };
23
24
  debug?: boolean;
24
25
  authenticationType: typeof AUTH_TYPES.PASSKEY | typeof AUTH_TYPES.CODE;
package/dist/index.js CHANGED
@@ -4,13 +4,13 @@ var F = (e, t, r) => Et(e, typeof t != "symbol" ? t + "" : t, r);
4
4
  import { jsx as be } from "react/jsx-runtime";
5
5
  import mt, { useSyncExternalStore as wt, useCallback as N, useEffect as He, createContext as St, useReducer as At, useRef as Tt, useContext as Rt } from "react";
6
6
  /*!
7
- @versini/auth-provider v7.2.0
7
+ @versini/auth-provider v7.3.1
8
8
  © 2024 gizmette.com
9
9
  */
10
10
  try {
11
11
  window.__VERSINI_AUTH_CLIENT__ || (window.__VERSINI_AUTH_CLIENT__ = {
12
- version: "7.2.0",
13
- buildTime: "09/01/2024 02:27 PM EDT",
12
+ version: "7.3.1",
13
+ buildTime: "09/05/2024 04:25 PM EDT",
14
14
  homepage: "https://github.com/aversini/auth-client",
15
15
  license: "MIT"
16
16
  });
@@ -177,11 +177,11 @@ async function vt(e) {
177
177
  } catch (l) {
178
178
  he("getPublicKeyAlgorithm()", l);
179
179
  }
180
- let f;
180
+ let y;
181
181
  if (typeof s.getPublicKey == "function")
182
182
  try {
183
183
  const l = s.getPublicKey();
184
- l !== null && (f = _(l));
184
+ l !== null && (y = _(l));
185
185
  } catch (l) {
186
186
  he("getPublicKey()", l);
187
187
  }
@@ -200,7 +200,7 @@ async function vt(e) {
200
200
  clientDataJSON: _(s.clientDataJSON),
201
201
  transports: c,
202
202
  publicKeyAlgorithm: h,
203
- publicKey: f,
203
+ publicKey: y,
204
204
  authenticatorData: p
205
205
  },
206
206
  type: i,
@@ -286,15 +286,15 @@ async function Pt(e, t = !1) {
286
286
  if (!o)
287
287
  throw new Error("Authentication was not completed");
288
288
  const { id: s, rawId: i, response: c, type: h } = o;
289
- let f;
290
- return c.userHandle && (f = _(c.userHandle)), {
289
+ let y;
290
+ return c.userHandle && (y = _(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: f
297
+ userHandle: y
298
298
  },
299
299
  type: h,
300
300
  clientExtensionResults: o.getClientExtensionResults(),
@@ -302,19 +302,19 @@ async function Pt(e, t = !1) {
302
302
  };
303
303
  }
304
304
  /*!
305
- @versini/auth-common v4.0.0
305
+ @versini/auth-common v4.1.1
306
306
  © 2024 gizmette.com
307
307
  */
308
308
  try {
309
309
  window.__VERSINI_AUTH_COMMON__ || (window.__VERSINI_AUTH_COMMON__ = {
310
- version: "4.0.0",
311
- buildTime: "09/01/2024 02:27 PM EDT",
310
+ version: "4.1.1",
311
+ buildTime: "09/05/2024 04:25 PM EDT",
312
312
  homepage: "https://github.com/aversini/auth-client",
313
313
  license: "MIT"
314
314
  });
315
315
  } catch {
316
316
  }
317
- const H = {
317
+ const W = {
318
318
  ID_TOKEN: "id_token",
319
319
  ACCESS_TOKEN: "token",
320
320
  ID_AND_ACCESS_TOKEN: "id_token token",
@@ -323,12 +323,13 @@ const H = {
323
323
  PASSKEY: "passkey"
324
324
  }, Ge = {
325
325
  CLIENT_ID: "X-Auth-ClientId"
326
- }, w = {
326
+ }, f = {
327
327
  ALG: "RS256",
328
328
  USER_ID_KEY: "sub",
329
+ USERNAME_KEY: "username",
330
+ EMAIL_KEY: "email",
329
331
  TOKEN_ID_KEY: "__raw",
330
332
  NONCE_KEY: "_nonce",
331
- USERNAME_KEY: "username",
332
333
  AUTH_TYPE_KEY: "auth_type",
333
334
  EXPIRES_AT_KEY: "exp",
334
335
  CREATED_AT_KEY: "iat",
@@ -411,7 +412,7 @@ class k extends D {
411
412
  return "ERR_JOSE_NOT_SUPPORTED";
412
413
  }
413
414
  }
414
- class m extends D {
415
+ class w extends D {
415
416
  constructor() {
416
417
  super(...arguments), this.code = "ERR_JWS_INVALID";
417
418
  }
@@ -444,7 +445,7 @@ function q(e, t) {
444
445
  function pe(e) {
445
446
  return parseInt(e.name.slice(4), 10);
446
447
  }
447
- function $t(e) {
448
+ function Lt(e) {
448
449
  switch (e) {
449
450
  case "ES256":
450
451
  return "P-256";
@@ -456,7 +457,7 @@ function $t(e) {
456
457
  throw new Error("unreachable");
457
458
  }
458
459
  }
459
- function Lt(e, t) {
460
+ function $t(e, t) {
460
461
  if (t.length && !t.some((r) => e.usages.includes(r))) {
461
462
  let r = "CryptoKey does not support this operation, its usages must include ";
462
463
  if (t.length > 2) {
@@ -508,7 +509,7 @@ function Ht(e, t, ...r) {
508
509
  case "ES512": {
509
510
  if (!q(e.algorithm, "ECDSA"))
510
511
  throw b("ECDSA");
511
- const n = $t(t);
512
+ const n = Lt(t);
512
513
  if (e.algorithm.namedCurve !== n)
513
514
  throw b(n, "algorithm.namedCurve");
514
515
  break;
@@ -516,7 +517,7 @@ function Ht(e, t, ...r) {
516
517
  default:
517
518
  throw new TypeError("CryptoKey does not support this operation");
518
519
  }
519
- Lt(e, r);
520
+ $t(e, r);
520
521
  }
521
522
  function Ve(e, t, ...r) {
522
523
  var n;
@@ -651,7 +652,7 @@ const Gt = async (e) => {
651
652
  ], a = { ...e };
652
653
  return delete a.alg, delete a.use, ce.subtle.importKey("jwk", a, ...n);
653
654
  }, Be = (e) => G(e);
654
- let fe, ye;
655
+ let ye, fe;
655
656
  const qe = (e) => e?.[Symbol.toStringTag] === "KeyObject", ze = async (e, t, r, n) => {
656
657
  let a = e.get(t);
657
658
  if (a != null && a[n])
@@ -661,13 +662,13 @@ const qe = (e) => e?.[Symbol.toStringTag] === "KeyObject", ze = async (e, t, r,
661
662
  }, Mt = (e, t) => {
662
663
  if (qe(e)) {
663
664
  let r = e.export({ format: "jwk" });
664
- return delete r.d, delete r.dp, delete r.dq, delete r.p, delete r.q, delete r.qi, r.k ? Be(r.k) : (ye || (ye = /* @__PURE__ */ new WeakMap()), ze(ye, e, r, t));
665
+ return delete r.d, delete r.dp, delete r.dq, delete r.p, delete r.q, delete r.qi, r.k ? Be(r.k) : (fe || (fe = /* @__PURE__ */ new WeakMap()), ze(fe, e, r, t));
665
666
  }
666
667
  return e;
667
668
  }, Vt = (e, t) => {
668
669
  if (qe(e)) {
669
670
  let r = e.export({ format: "jwk" });
670
- return r.k ? Be(r.k) : (fe || (fe = /* @__PURE__ */ new WeakMap()), ze(fe, e, r, t));
671
+ return r.k ? Be(r.k) : (ye || (ye = /* @__PURE__ */ new WeakMap()), ze(ye, e, r, t));
671
672
  }
672
673
  return e;
673
674
  }, jt = { normalizePublicKey: Mt, normalizePrivateKey: Vt }, O = (e, t, r = 0) => {
@@ -840,62 +841,62 @@ const nr = async (e, t, r, n) => {
840
841
  };
841
842
  async function ar(e, t, r) {
842
843
  if (!se(e))
843
- throw new m("Flattened JWS must be an object");
844
+ throw new w("Flattened JWS must be an object");
844
845
  if (e.protected === void 0 && e.header === void 0)
845
- throw new m('Flattened JWS must have either of the "protected" or "header" members');
846
+ throw new w('Flattened JWS must have either of the "protected" or "header" members');
846
847
  if (e.protected !== void 0 && typeof e.protected != "string")
847
- throw new m("JWS Protected Header incorrect type");
848
+ throw new w("JWS Protected Header incorrect type");
848
849
  if (e.payload === void 0)
849
- throw new m("JWS Payload missing");
850
+ throw new w("JWS Payload missing");
850
851
  if (typeof e.signature != "string")
851
- throw new m("JWS Signature missing or incorrect type");
852
+ throw new w("JWS Signature missing or incorrect type");
852
853
  if (e.header !== void 0 && !se(e.header))
853
- throw new m("JWS Unprotected Header incorrect type");
854
+ throw new w("JWS Unprotected Header incorrect type");
854
855
  let n = {};
855
856
  if (e.protected)
856
857
  try {
857
858
  const T = G(e.protected);
858
859
  n = JSON.parse(M.decode(T));
859
860
  } catch {
860
- throw new m("JWS Protected Header is invalid");
861
+ throw new w("JWS Protected Header is invalid");
861
862
  }
862
863
  if (!Wt(n, e.header))
863
- throw new m("JWS Protected and JWS Unprotected Header Parameter names must be disjoint");
864
+ throw new w("JWS Protected and JWS Unprotected Header Parameter names must be disjoint");
864
865
  const a = {
865
866
  ...n,
866
867
  ...e.header
867
- }, o = Zt(m, /* @__PURE__ */ new Map([["b64", !0]]), r?.crit, n, a);
868
+ }, o = Zt(w, /* @__PURE__ */ new Map([["b64", !0]]), r?.crit, n, a);
868
869
  let s = !0;
869
870
  if (o.has("b64") && (s = n.b64, typeof s != "boolean"))
870
- throw new m('The "b64" (base64url-encode payload) Header Parameter must be a boolean');
871
+ throw new w('The "b64" (base64url-encode payload) Header Parameter must be a boolean');
871
872
  const { alg: i } = a;
872
873
  if (typeof i != "string" || !i)
873
- throw new m('JWS "alg" (Algorithm) Header Parameter missing or invalid');
874
+ throw new w('JWS "alg" (Algorithm) Header Parameter missing or invalid');
874
875
  const c = r && er("algorithms", r.algorithms);
875
876
  if (c && !c.has(i))
876
877
  throw new Ut('"alg" (Algorithm) Header Parameter value not allowed');
877
878
  if (s) {
878
879
  if (typeof e.payload != "string")
879
- throw new m("JWS Payload must be a string");
880
+ throw new w("JWS Payload must be a string");
880
881
  } else if (typeof e.payload != "string" && !(e.payload instanceof Uint8Array))
881
- throw new m("JWS Payload must be a string or an Uint8Array instance");
882
+ throw new w("JWS Payload must be a string or an Uint8Array instance");
882
883
  let h = !1;
883
884
  typeof t == "function" && (t = await t(n, e), h = !0), Xt(i, t, "verify");
884
- const f = Nt(B.encode(e.protected ?? ""), B.encode("."), typeof e.payload == "string" ? B.encode(e.payload) : e.payload);
885
+ const y = Nt(B.encode(e.protected ?? ""), B.encode("."), typeof e.payload == "string" ? B.encode(e.payload) : e.payload);
885
886
  let p;
886
887
  try {
887
888
  p = G(e.signature);
888
889
  } catch {
889
- throw new m("Failed to base64url decode the signature");
890
+ throw new w("Failed to base64url decode the signature");
890
891
  }
891
- if (!await nr(i, t, p, f))
892
+ if (!await nr(i, t, p, y))
892
893
  throw new Kt();
893
894
  let l;
894
895
  if (s)
895
896
  try {
896
897
  l = G(e.payload);
897
898
  } catch {
898
- throw new m("Failed to base64url decode the payload");
899
+ throw new w("Failed to base64url decode the payload");
899
900
  }
900
901
  else typeof e.payload == "string" ? l = B.encode(e.payload) : l = e.payload;
901
902
  const A = { payload: l };
@@ -903,10 +904,10 @@ async function ar(e, t, r) {
903
904
  }
904
905
  async function sr(e, t, r) {
905
906
  if (e instanceof Uint8Array && (e = M.decode(e)), typeof e != "string")
906
- throw new m("Compact JWS must be a string or Uint8Array");
907
+ throw new w("Compact JWS must be a string or Uint8Array");
907
908
  const { 0: n, 1: a, 2: o, length: s } = e.split(".");
908
909
  if (s !== 3)
909
- throw new m("Invalid Compact JWS");
910
+ throw new w("Invalid Compact JWS");
910
911
  const i = await ar({ payload: a, protected: n, signature: o }, t, r), c = { payload: i.payload, protectedHeader: i.protectedHeader };
911
912
  return typeof t == "function" ? { ...c, key: i.key } : c;
912
913
  }
@@ -964,9 +965,9 @@ const or = (e) => Math.floor(e.getTime() / 1e3), Qe = 60, Xe = Qe * 60, Ae = Xe
964
965
  const { typ: a } = r;
965
966
  if (a && (typeof e.typ != "string" || Ce(e.typ) !== Ce(a)))
966
967
  throw new R('unexpected "typ" JWT header value', n, "typ", "check_failed");
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()))
968
+ const { requiredClaims: o = [], issuer: s, subject: i, audience: c, maxTokenAge: h } = r, y = [...o];
969
+ h !== void 0 && y.push("iat"), c !== void 0 && y.push("aud"), i !== void 0 && y.push("sub"), s !== void 0 && y.push("iss");
970
+ for (const T of new Set(y.reverse()))
970
971
  if (!(T in n))
971
972
  throw new R(`missing required "${T}" claim`, n, T, "missing");
972
973
  if (s && !(Array.isArray(s) ? s : [s]).includes(n.iss))
@@ -1022,7 +1023,7 @@ async function hr(e, t, r) {
1022
1023
  return typeof t == "function" ? { ...o, key: a.key } : o;
1023
1024
  }
1024
1025
  const pr = G;
1025
- function fr(e) {
1026
+ function yr(e) {
1026
1027
  if (typeof e != "string")
1027
1028
  throw new v("JWTs must use Compact JWS serialization, JWT must be a string");
1028
1029
  const { 1: t, length: r } = e.split(".");
@@ -1048,27 +1049,27 @@ function fr(e) {
1048
1049
  throw new v("Invalid JWT Claims Set");
1049
1050
  return a;
1050
1051
  }
1051
- const W = async (e) => {
1052
+ const Y = async (e) => {
1052
1053
  try {
1053
- const t = w.ALG, r = await qt(Ct, t);
1054
+ const t = f.ALG, r = await qt(Ct, t);
1054
1055
  return await hr(e, r, {
1055
- issuer: w.ISSUER
1056
+ issuer: f.ISSUER
1056
1057
  });
1057
1058
  } catch {
1058
1059
  return;
1059
1060
  }
1060
- }, yr = (e) => {
1061
+ }, fr = (e) => {
1061
1062
  try {
1062
- return fr(e);
1063
+ return yr(e);
1063
1064
  } catch {
1064
1065
  return;
1065
1066
  }
1066
1067
  };
1067
- var g = [];
1068
+ var E = [];
1068
1069
  for (var ge = 0; ge < 256; ++ge)
1069
- g.push((ge + 256).toString(16).slice(1));
1070
+ E.push((ge + 256).toString(16).slice(1));
1070
1071
  function gr(e, t = 0) {
1071
- return (g[e[t + 0]] + g[e[t + 1]] + g[e[t + 2]] + g[e[t + 3]] + "-" + g[e[t + 4]] + g[e[t + 5]] + "-" + g[e[t + 6]] + g[e[t + 7]] + "-" + g[e[t + 8]] + g[e[t + 9]] + "-" + g[e[t + 10]] + g[e[t + 11]] + g[e[t + 12]] + g[e[t + 13]] + g[e[t + 14]] + g[e[t + 15]]).toLowerCase();
1072
+ 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();
1072
1073
  }
1073
1074
  var z, Er = new Uint8Array(16);
1074
1075
  function mr() {
@@ -1107,10 +1108,10 @@ async function Rr(e) {
1107
1108
  }
1108
1109
  const Fr = async (e, t) => {
1109
1110
  var r;
1110
- const n = await W(e);
1111
- if (!n || !Array.isArray((r = n.payload) == null ? void 0 : r[w.SCOPES_KEY]))
1111
+ const n = await Y(e);
1112
+ if (!n || !Array.isArray((r = n.payload) == null ? void 0 : r[f.SCOPES_KEY]))
1112
1113
  return !1;
1113
- const a = n.payload[w.SCOPES_KEY];
1114
+ const a = n.payload[f.SCOPES_KEY];
1114
1115
  return Array.isArray(t) ? t.every((o) => a.includes(o)) : Object.keys(t).some(
1115
1116
  (o) => t[o].every((s) => a.includes(s))
1116
1117
  );
@@ -1125,12 +1126,12 @@ const Ke = (e, t) => {
1125
1126
  window.localStorage.setItem(e, r), Ze(e, r);
1126
1127
  }, _r = (e) => {
1127
1128
  window.localStorage.removeItem(e), Ze(e, null);
1128
- }, $e = (e) => window.localStorage.getItem(e), Ir = (e) => (window.addEventListener("storage", e), () => window.removeEventListener("storage", e));
1129
+ }, Le = (e) => window.localStorage.getItem(e), Ir = (e) => (window.addEventListener("storage", e), () => window.removeEventListener("storage", e));
1129
1130
  function Q({
1130
1131
  key: e,
1131
1132
  initialValue: t
1132
1133
  }) {
1133
- const r = wt(Ir, () => $e(e)), n = N(
1134
+ const r = wt(Ir, () => Le(e)), n = N(
1134
1135
  (s) => {
1135
1136
  try {
1136
1137
  const i = typeof s == "function" ? s(JSON.parse(r)) : s;
@@ -1147,17 +1148,17 @@ function Q({
1147
1148
  }, [n]);
1148
1149
  return He(() => {
1149
1150
  try {
1150
- $e(e) === null && typeof t < "u" && Ke(e, t);
1151
+ Le(e) === null && typeof t < "u" && Ke(e, t);
1151
1152
  } catch (s) {
1152
1153
  console.warn(s);
1153
1154
  }
1154
1155
  }, [e, t]), [r ? JSON.parse(r) : null, n, a, o];
1155
1156
  }
1156
- var E = [];
1157
+ var m = [];
1157
1158
  for (var Ee = 0; Ee < 256; ++Ee)
1158
- E.push((Ee + 256).toString(16).slice(1));
1159
+ m.push((Ee + 256).toString(16).slice(1));
1159
1160
  function br(e, t = 0) {
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
+ return (m[e[t + 0]] + m[e[t + 1]] + m[e[t + 2]] + m[e[t + 3]] + "-" + m[e[t + 4]] + m[e[t + 5]] + "-" + m[e[t + 6]] + m[e[t + 7]] + "-" + m[e[t + 8]] + m[e[t + 9]] + "-" + m[e[t + 10]] + m[e[t + 11]] + m[e[t + 12]] + m[e[t + 13]] + m[e[t + 14]] + m[e[t + 15]]).toLowerCase();
1161
1162
  }
1162
1163
  var X, vr = new Uint8Array(16);
1163
1164
  function Or() {
@@ -1166,17 +1167,17 @@ function Or() {
1166
1167
  return X(vr);
1167
1168
  }
1168
1169
  var kr = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto);
1169
- const Le = {
1170
+ const $e = {
1170
1171
  randomUUID: kr
1171
1172
  };
1172
1173
  function me(e, t, r) {
1173
- if (Le.randomUUID && !t && !e)
1174
- return Le.randomUUID();
1174
+ if ($e.randomUUID && !t && !e)
1175
+ return $e.randomUUID();
1175
1176
  e = e || {};
1176
1177
  var n = e.random || (e.rng || Or)();
1177
1178
  return n[6] = n[6] & 15 | 64, n[8] = n[8] & 63 | 128, br(n);
1178
1179
  }
1179
- const U = "Your session has expired. For your security, please log in again to continue.", Pr = "Your session has been successfully terminated.", we = "Login failed. Please try again.", Cr = "Error getting access token, please re-authenticate.", Nr = "You forgot to wrap your component in <AuthProvider>.", oe = {
1180
+ const K = "Your session has expired. For your security, please log in again to continue.", Pr = "Your session has been successfully terminated.", we = "Login failed. Please try again.", Cr = "Error getting access token, please re-authenticate.", Nr = "You forgot to wrap your component in <AuthProvider>.", oe = {
1180
1181
  dev: "https://auth.gizmette.local.com:3003",
1181
1182
  prod: "https://mylogin.gizmette.com/auth"
1182
1183
  }, Z = "@@auth@@", J = "LOADING", re = "LOGIN", et = "LOGOUT", V = "success", I = "failure", tt = "include", rt = "POST", nt = "application/json", ee = {
@@ -1257,9 +1258,10 @@ const U = "Your session has expired. For your security, please log in again to c
1257
1258
  refreshToken,
1258
1259
  userId,
1259
1260
  username,
1261
+ email
1260
1262
  }
1261
1263
  }`
1262
- }, K = {
1264
+ }, L = {
1263
1265
  GET_REGISTRATION_OPTIONS: {
1264
1266
  schema: ee.GET_REGISTRATION_OPTIONS,
1265
1267
  method: "getPasskeyRegistrationOptions"
@@ -1346,8 +1348,8 @@ const U = "Your session has expired. For your security, please log in again to c
1346
1348
  authenticationType: ""
1347
1349
  }, Ur = (e) => {
1348
1350
  try {
1349
- const t = yr(e);
1350
- return t ? t[w.USER_ID_KEY] : "";
1351
+ const t = fr(e);
1352
+ return t ? t[f.USER_ID_KEY] : "";
1351
1353
  } catch {
1352
1354
  return "";
1353
1355
  }
@@ -1374,7 +1376,7 @@ const U = "Your session has expired. For your security, please log in again to c
1374
1376
  status: I
1375
1377
  };
1376
1378
  }
1377
- }, $r = async ({
1379
+ }, Lr = async ({
1378
1380
  username: e,
1379
1381
  password: t,
1380
1382
  clientId: r,
@@ -1387,11 +1389,11 @@ const U = "Your session has expired. For your security, please log in again to c
1387
1389
  ua: h
1388
1390
  }) => {
1389
1391
  try {
1390
- const f = await ue({
1392
+ const y = await ue({
1391
1393
  type: ie.LOGIN,
1392
1394
  clientId: r,
1393
1395
  params: {
1394
- type: a || H.ID_AND_ACCESS_TOKEN,
1396
+ type: a || W.ID_AND_ACCESS_TOKEN,
1395
1397
  username: e,
1396
1398
  password: t,
1397
1399
  sessionExpiration: o,
@@ -1401,12 +1403,13 @@ const U = "Your session has expired. For your security, please log in again to c
1401
1403
  domain: c,
1402
1404
  ua: h
1403
1405
  }
1404
- }), p = await W(f?.data?.idToken);
1405
- return p && p.payload[w.USER_ID_KEY] !== "" && p.payload[w.NONCE_KEY] === n ? {
1406
- idToken: f.data.idToken,
1407
- accessToken: f.data.accessToken,
1408
- refreshToken: f.data.refreshToken,
1409
- userId: p.payload[w.USER_ID_KEY],
1406
+ }), p = await Y(y?.data?.idToken);
1407
+ return p && p.payload[f.USER_ID_KEY] !== "" && p.payload[f.NONCE_KEY] === n ? {
1408
+ idToken: y.data.idToken,
1409
+ accessToken: y.data.accessToken,
1410
+ refreshToken: y.data.refreshToken,
1411
+ userId: p.payload[f.USER_ID_KEY],
1412
+ email: p.payload[f.EMAIL_KEY],
1410
1413
  status: !0
1411
1414
  } : {
1412
1415
  status: !1
@@ -1416,7 +1419,7 @@ const U = "Your session has expired. For your security, please log in again to c
1416
1419
  status: !1
1417
1420
  };
1418
1421
  }
1419
- }, Lr = async ({
1422
+ }, $r = async ({
1420
1423
  nonce: e,
1421
1424
  clientId: t,
1422
1425
  code_challenge: r
@@ -1426,7 +1429,7 @@ const U = "Your session has expired. For your security, please log in again to c
1426
1429
  type: ie.CODE,
1427
1430
  clientId: t,
1428
1431
  params: {
1429
- type: H.CODE,
1432
+ type: W.CODE,
1430
1433
  nonce: e,
1431
1434
  code_challenge: r
1432
1435
  }
@@ -1457,18 +1460,18 @@ const U = "Your session has expired. For your security, please log in again to c
1457
1460
  type: ie.REFRESH,
1458
1461
  clientId: e,
1459
1462
  params: {
1460
- type: H.REFRESH_TOKEN,
1463
+ type: W.REFRESH_TOKEN,
1461
1464
  userId: t,
1462
1465
  nonce: r,
1463
1466
  refreshToken: n,
1464
1467
  accessToken: a,
1465
1468
  domain: o
1466
1469
  }
1467
- }), i = await W(s?.data?.accessToken);
1468
- return i && i.payload[w.USER_ID_KEY] !== "" && i.payload[w.NONCE_KEY] === r ? {
1470
+ }), i = await Y(s?.data?.accessToken);
1471
+ return i && i.payload[f.USER_ID_KEY] !== "" && i.payload[f.NONCE_KEY] === r ? {
1469
1472
  accessToken: s.data.accessToken,
1470
1473
  refreshToken: s.data.refreshToken,
1471
- userId: i.payload[w.USER_ID_KEY],
1474
+ userId: i.payload[f.USER_ID_KEY],
1472
1475
  status: !0
1473
1476
  } : {
1474
1477
  status: !1
@@ -1510,8 +1513,8 @@ class Wr {
1510
1513
  nonce: n,
1511
1514
  domain: a
1512
1515
  }) {
1513
- const o = await W(this.refreshToken);
1514
- if (o && o.payload[w.USER_ID_KEY] !== "") {
1516
+ const o = await Y(this.refreshToken);
1517
+ if (o && o.payload[f.USER_ID_KEY] !== "") {
1515
1518
  const s = await Hr({
1516
1519
  clientId: t,
1517
1520
  userId: r,
@@ -1538,17 +1541,17 @@ const Yr = (e) => N(
1538
1541
  e && console.info(`==> [Auth ${Date.now()}]: `, ...t);
1539
1542
  },
1540
1543
  [e]
1541
- ), L = () => {
1544
+ ), H = () => {
1542
1545
  throw new Error(Nr);
1543
1546
  }, ot = St({
1544
1547
  isAuthenticated: !1,
1545
1548
  isLoading: !1,
1546
- login: L,
1547
- logout: L,
1548
- getAccessToken: L,
1549
- getIdToken: L,
1550
- registeringForPasskey: L,
1551
- loginWithPasskey: L,
1549
+ login: H,
1550
+ logout: H,
1551
+ getAccessToken: H,
1552
+ getIdToken: H,
1553
+ registeringForPasskey: H,
1554
+ loginWithPasskey: H,
1552
1555
  logoutReason: "",
1553
1556
  authenticationType: ""
1554
1557
  }), xr = mt.createContext({
@@ -1582,7 +1585,7 @@ const Yr = (e) => N(
1582
1585
  const [o, s] = At(Jr, {
1583
1586
  ...st,
1584
1587
  debug: a
1585
- }), i = Yr(a), c = Tt(!1), [h, f, , p] = Q({
1588
+ }), i = Yr(a), c = Tt(!1), [h, y, , p] = Q({
1586
1589
  key: `${Z}::${r}::@@user@@`
1587
1590
  }), [l, A, , T] = Q({
1588
1591
  key: `${Z}::${r}::@@access@@`
@@ -1600,7 +1603,7 @@ const Yr = (e) => N(
1600
1603
  _e,
1601
1604
  Te,
1602
1605
  i
1603
- ]), Y = N(
1606
+ ]), x = N(
1604
1607
  (u) => {
1605
1608
  i(
1606
1609
  "removeStateAndLocalStorage: removing state and local storage with reason: ",
@@ -1608,7 +1611,7 @@ const Yr = (e) => N(
1608
1611
  ), s({
1609
1612
  type: et,
1610
1613
  payload: {
1611
- logoutReason: u || U
1614
+ logoutReason: u || K
1612
1615
  }
1613
1616
  }), j(), s({ type: J, payload: { isLoading: !1 } });
1614
1617
  },
@@ -1616,7 +1619,7 @@ const Yr = (e) => N(
1616
1619
  ), P = N(
1617
1620
  async (u) => {
1618
1621
  i("invalidateAndLogout: invalidating and logging out");
1619
- const { user: y } = o, d = y?.userId || Ur(h);
1622
+ const { user: g } = o, d = g?.userId || Ur(h);
1620
1623
  d || i(
1621
1624
  "invalidateAndLogout: user cannot be identified, logging out without userId"
1622
1625
  ), await Kr({
@@ -1624,94 +1627,96 @@ const Yr = (e) => N(
1624
1627
  clientId: r,
1625
1628
  domain: n,
1626
1629
  idToken: h
1627
- }), Y(u || U);
1630
+ }), x(u || K);
1628
1631
  },
1629
- [h, o, r, n, Y, i]
1632
+ [h, o, r, n, x, i]
1630
1633
  );
1631
1634
  He(() => {
1632
1635
  if (!c.current)
1633
1636
  return o.isLoading && h !== null ? (async () => {
1634
1637
  try {
1635
- const u = await W(h);
1636
- u && u.payload[w.USER_ID_KEY] !== "" ? (i("useEffect: setting the authentication state"), s({
1638
+ const u = await Y(h);
1639
+ u && u.payload[f.USER_ID_KEY] !== "" ? (i("useEffect: setting the authentication state"), s({
1637
1640
  type: re,
1638
1641
  payload: {
1639
- authenticationType: u.payload[w.AUTH_TYPE_KEY],
1642
+ authenticationType: u.payload[f.AUTH_TYPE_KEY],
1640
1643
  user: {
1641
- userId: u.payload[w.USER_ID_KEY],
1642
- username: u.payload[w.USERNAME_KEY]
1644
+ userId: u.payload[f.USER_ID_KEY],
1645
+ username: u.payload[f.USERNAME_KEY],
1646
+ email: u.payload[f.EMAIL_KEY]
1643
1647
  }
1644
1648
  }
1645
- })) : (i("useEffect: invalid JWT, invalidating and logging out"), await P(U));
1649
+ })) : (i("useEffect: invalid JWT, invalidating and logging out"), await P(K));
1646
1650
  } catch {
1647
1651
  i(
1648
1652
  "useEffect: exception validating JWT, invalidating and logging out"
1649
- ), await P(U);
1653
+ ), await P(K);
1650
1654
  }
1651
1655
  })() : (i("useEffect: setting the loading state to false"), s({ type: J, payload: { isLoading: !1 } })), () => {
1652
1656
  c.current = !0;
1653
1657
  };
1654
1658
  }, [o.isLoading, h, P, i]);
1655
- const ut = async (u, y) => {
1659
+ const ut = async (u, g) => {
1656
1660
  s({ type: J, payload: { isLoading: !0 } }), j();
1657
1661
  const d = me();
1658
1662
  Re(d), i("login: Logging in with password");
1659
- const { code_verifier: C, code_challenge: yt } = await Rr(), Ie = await Lr({
1663
+ const { code_verifier: C, code_challenge: ft } = await Rr(), Ie = await $r({
1660
1664
  nonce: d,
1661
1665
  clientId: r,
1662
- code_challenge: yt
1666
+ code_challenge: ft
1663
1667
  });
1664
1668
  if (Ie.status) {
1665
- const x = await $r({
1669
+ const U = await Lr({
1666
1670
  username: u,
1667
- password: y,
1671
+ password: g,
1668
1672
  clientId: r,
1669
1673
  sessionExpiration: t,
1670
1674
  nonce: d,
1671
- type: H.CODE,
1675
+ type: W.CODE,
1672
1676
  code: Ie.data,
1673
1677
  code_verifier: C,
1674
1678
  domain: n,
1675
1679
  ua: navigator.userAgent
1676
1680
  });
1677
- return x.status ? (f(x.idToken), A(x.accessToken), de(x.refreshToken), s({
1681
+ return U.status ? (y(U.idToken), A(U.accessToken), de(U.refreshToken), s({
1678
1682
  type: re,
1679
1683
  payload: {
1680
- authenticationType: H.CODE,
1684
+ authenticationType: W.CODE,
1681
1685
  user: {
1682
- userId: x.userId,
1683
- username: u
1686
+ userId: U.userId,
1687
+ username: u,
1688
+ email: U.email
1684
1689
  }
1685
1690
  }
1686
- }), !0) : (Y(we), !1);
1691
+ }), !0) : (x(we), !1);
1687
1692
  }
1688
1693
  return !1;
1689
1694
  }, lt = async (u) => {
1690
1695
  u?.preventDefault(), await P(Pr);
1691
1696
  }, dt = async () => {
1692
- const { isAuthenticated: u, user: y } = o;
1697
+ const { isAuthenticated: u, user: g } = o;
1693
1698
  try {
1694
- if (u && y && y.userId) {
1699
+ if (u && g && g.userId) {
1695
1700
  if (l) {
1696
1701
  i("getAccessToken");
1697
- const C = await W(l);
1698
- if (C && C.payload[w.USER_ID_KEY] !== "")
1702
+ const C = await Y(l);
1703
+ if (C && C.payload[f.USER_ID_KEY] !== "")
1699
1704
  return l;
1700
1705
  }
1701
1706
  i("getAccessToken: invalid access token, trying to refresh it");
1702
1707
  const d = await ct.refreshtoken({
1703
1708
  clientId: r,
1704
- userId: y.userId,
1709
+ userId: g.userId,
1705
1710
  nonce: it,
1706
1711
  domain: n
1707
1712
  });
1708
1713
  return d.status && d.status === "success" && d.newAccessToken ? (A(d.newAccessToken), de(d.newRefreshToken), d.newAccessToken) : (i(
1709
1714
  "getAccessToken: invalid refresh token, need to re-authenticate"
1710
- ), await P(U), "");
1715
+ ), await P(K), "");
1711
1716
  }
1712
1717
  return i(
1713
1718
  "getAccessToken: user is not authenticated, cannot get access token"
1714
- ), await P(U), "";
1719
+ ), await P(K), "";
1715
1720
  } catch {
1716
1721
  return i(
1717
1722
  "getAccessToken: exception occurred, invalidating and logging out"
@@ -1719,35 +1724,35 @@ const Yr = (e) => N(
1719
1724
  }
1720
1725
  }, ht = () => o.isAuthenticated && h ? h : "", pt = async () => {
1721
1726
  const { user: u } = o;
1722
- let y = await $({
1727
+ let g = await $({
1723
1728
  accessToken: l,
1724
1729
  clientId: r,
1725
- type: K.GET_REGISTRATION_OPTIONS,
1730
+ type: L.GET_REGISTRATION_OPTIONS,
1726
1731
  params: {
1727
1732
  clientId: r,
1728
1733
  id: u?.userId,
1729
1734
  username: u?.username
1730
1735
  }
1731
1736
  });
1732
- if (y.status)
1737
+ if (g.status)
1733
1738
  try {
1734
- const d = await vt(y.data);
1735
- return y = await $({
1739
+ const d = await vt(g.data);
1740
+ return g = await $({
1736
1741
  accessToken: l,
1737
1742
  clientId: r,
1738
- type: K.VERIFY_REGISTRATION,
1743
+ type: L.VERIFY_REGISTRATION,
1739
1744
  params: {
1740
1745
  clientId: r,
1741
1746
  id: u?.userId,
1742
1747
  username: u?.username,
1743
1748
  registration: d
1744
1749
  }
1745
- }), !!(y.status && y.data.length > 0);
1750
+ }), !!(g.status && g.data.length > 0);
1746
1751
  } catch {
1747
1752
  return await $({
1748
1753
  accessToken: l,
1749
1754
  clientId: r,
1750
- type: K.VERIFY_REGISTRATION,
1755
+ type: L.VERIFY_REGISTRATION,
1751
1756
  params: {
1752
1757
  clientId: r,
1753
1758
  id: u?.userId,
@@ -1757,17 +1762,17 @@ const Yr = (e) => N(
1757
1762
  }), !1;
1758
1763
  }
1759
1764
  return !1;
1760
- }, ft = async () => {
1765
+ }, yt = async () => {
1761
1766
  s({ type: J, payload: { isLoading: !0 } }), j();
1762
1767
  const u = me();
1763
1768
  Re(u), i("loginWithPasskey");
1764
- const y = me();
1769
+ const g = me();
1765
1770
  let d = await $({
1766
1771
  accessToken: l,
1767
1772
  clientId: r,
1768
- type: K.GET_AUTHENTICATION_OPTIONS,
1773
+ type: L.GET_AUTHENTICATION_OPTIONS,
1769
1774
  params: {
1770
- id: y,
1775
+ id: g,
1771
1776
  clientId: r
1772
1777
  }
1773
1778
  });
@@ -1777,40 +1782,41 @@ const Yr = (e) => N(
1777
1782
  return d = await $({
1778
1783
  accessToken: l,
1779
1784
  clientId: r,
1780
- type: K.VERIFY_AUTHENTICATION,
1785
+ type: L.VERIFY_AUTHENTICATION,
1781
1786
  params: {
1782
1787
  clientId: r,
1783
- id: y,
1788
+ id: g,
1784
1789
  authentication: C,
1785
1790
  nonce: u,
1786
1791
  domain: n,
1787
1792
  sessionExpiration: t,
1788
1793
  ua: navigator.userAgent
1789
1794
  }
1790
- }), d.data.status === V ? (f(d.data.idToken), A(d.data.accessToken), de(d.data.refreshToken), s({
1795
+ }), d.data.status === V ? (y(d.data.idToken), A(d.data.accessToken), de(d.data.refreshToken), s({
1791
1796
  type: re,
1792
1797
  payload: {
1793
- authenticationType: H.PASSKEY,
1798
+ authenticationType: W.PASSKEY,
1794
1799
  user: {
1795
1800
  userId: d.data.userId,
1796
- username: d.data.username
1801
+ username: d.data.username,
1802
+ email: d.data.email
1797
1803
  }
1798
1804
  }
1799
- }), !0) : (Y(we), !1);
1805
+ }), !0) : (x(we), !1);
1800
1806
  } catch {
1801
1807
  return await $({
1802
1808
  accessToken: l,
1803
1809
  clientId: r,
1804
- type: K.VERIFY_AUTHENTICATION,
1810
+ type: L.VERIFY_AUTHENTICATION,
1805
1811
  params: {
1806
1812
  clientId: r,
1807
- id: y,
1813
+ id: g,
1808
1814
  authentication: {},
1809
1815
  nonce: u,
1810
1816
  domain: n,
1811
1817
  sessionExpiration: t
1812
1818
  }
1813
- }), Y(we), !1;
1819
+ }), x(we), !1;
1814
1820
  }
1815
1821
  return !1;
1816
1822
  };
@@ -1824,14 +1830,14 @@ const Yr = (e) => N(
1824
1830
  getAccessToken: dt,
1825
1831
  getIdToken: ht,
1826
1832
  registeringForPasskey: pt,
1827
- loginWithPasskey: ft
1833
+ loginWithPasskey: yt
1828
1834
  },
1829
1835
  children: e
1830
1836
  }
1831
1837
  ) });
1832
1838
  }, qr = (e = ot) => Rt(e);
1833
1839
  export {
1834
- H as AUTH_TYPES,
1840
+ W as AUTH_TYPES,
1835
1841
  Br as AuthProvider,
1836
1842
  Fr as isGranted,
1837
1843
  qr as useAuth
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@versini/auth-provider",
3
- "version": "7.2.0",
3
+ "version": "7.3.1",
4
4
  "license": "MIT",
5
5
  "author": "Arno Versini",
6
6
  "publishConfig": {
@@ -45,10 +45,10 @@
45
45
  },
46
46
  "dependencies": {
47
47
  "@simplewebauthn/browser": "10.0.0",
48
- "@versini/auth-common": "4.0.0",
49
- "@versini/ui-hooks": "4.1.0",
50
- "jose": "5.7.0",
48
+ "@versini/auth-common": "4.1.1",
49
+ "@versini/ui-hooks": "4.1.1",
50
+ "jose": "5.8.0",
51
51
  "uuid": "10.0.0"
52
52
  },
53
- "gitHead": "bd5589c7b60642943c3c299824e9260b7013059f"
53
+ "gitHead": "16ca50ac8e015645757fa8afee0cf1ef80e53cb7"
54
54
  }