@versini/auth-provider 5.0.3 → 5.0.4

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 +48 -48
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -5,13 +5,13 @@ import { jsx as Ve } from "react/jsx-runtime";
5
5
  import * as U from "react";
6
6
  import { createContext as Ye, useRef as Be, useState as Fe, useCallback as Ge, useEffect as qe, useContext as ze } from "react";
7
7
  /*!
8
- @versini/auth-provider v5.0.3
8
+ @versini/auth-provider v5.0.4
9
9
  © 2024 gizmette.com
10
10
  */
11
11
  try {
12
12
  window.__VERSINI_AUTH_CLIENT__ || (window.__VERSINI_AUTH_CLIENT__ = {
13
- version: "5.0.3",
14
- buildTime: "07/05/2024 10:27 AM EDT",
13
+ version: "5.0.4",
14
+ buildTime: "07/05/2024 12:57 PM EDT",
15
15
  homepage: "https://github.com/aversini/auth-client",
16
16
  license: "MIT"
17
17
  });
@@ -24,7 +24,7 @@ try {
24
24
  try {
25
25
  window.__VERSINI_AUTH_COMMON__ || (window.__VERSINI_AUTH_COMMON__ = {
26
26
  version: "2.10.1",
27
- buildTime: "07/05/2024 10:27 AM EDT",
27
+ buildTime: "07/05/2024 12:57 PM EDT",
28
28
  homepage: "https://github.com/aversini/auth-client",
29
29
  license: "MIT"
30
30
  });
@@ -88,7 +88,7 @@ class C extends Error {
88
88
  super(t), this.code = "ERR_JOSE_GENERIC", this.name = this.constructor.name, (r = Error.captureStackTrace) == null || r.call(Error, this, this.constructor);
89
89
  }
90
90
  }
91
- class g extends C {
91
+ class A extends C {
92
92
  static get code() {
93
93
  return "ERR_JWT_CLAIM_VALIDATION_FAILED";
94
94
  }
@@ -600,16 +600,16 @@ async function _t(e, t, r) {
600
600
  }
601
601
  if (!await bt(i, t, p, y))
602
602
  throw new rt();
603
- let A;
603
+ let T;
604
604
  if (o)
605
605
  try {
606
- A = V(e.payload);
606
+ T = V(e.payload);
607
607
  } catch {
608
608
  throw new f("Failed to base64url decode the payload");
609
609
  }
610
610
  else
611
- typeof e.payload == "string" ? A = L.encode(e.payload) : A = e.payload;
612
- const E = { payload: A };
611
+ typeof e.payload == "string" ? T = L.encode(e.payload) : T = e.payload;
612
+ const E = { payload: T };
613
613
  return e.protected !== void 0 && (E.protectedHeader = a), e.header !== void 0 && (E.unprotectedHeader = e.header), d ? { ...E, key: t } : E;
614
614
  }
615
615
  async function vt(e, t, r) {
@@ -674,18 +674,18 @@ const Rt = (e) => Math.floor(e.getTime() / 1e3), De = 60, Ue = De * 60, ce = Ue
674
674
  throw new _e("JWT Claims Set must be a top-level JSON object");
675
675
  const { typ: n } = r;
676
676
  if (n && (typeof e.typ != "string" || pe(e.typ) !== pe(n)))
677
- throw new g('unexpected "typ" JWT header value', a, "typ", "check_failed");
677
+ throw new A('unexpected "typ" JWT header value', a, "typ", "check_failed");
678
678
  const { requiredClaims: s = [], issuer: o, subject: i, audience: c, maxTokenAge: d } = r, y = [...s];
679
679
  d !== void 0 && y.push("iat"), c !== void 0 && y.push("aud"), i !== void 0 && y.push("sub"), o !== void 0 && y.push("iss");
680
680
  for (const S of new Set(y.reverse()))
681
681
  if (!(S in a))
682
- throw new g(`missing required "${S}" claim`, a, S, "missing");
682
+ throw new A(`missing required "${S}" claim`, a, S, "missing");
683
683
  if (o && !(Array.isArray(o) ? o : [o]).includes(a.iss))
684
- throw new g('unexpected "iss" claim value', a, "iss", "check_failed");
684
+ throw new A('unexpected "iss" claim value', a, "iss", "check_failed");
685
685
  if (i && a.sub !== i)
686
- throw new g('unexpected "sub" claim value', a, "sub", "check_failed");
686
+ throw new A('unexpected "sub" claim value', a, "sub", "check_failed");
687
687
  if (c && !Ot(a.aud, typeof c == "string" ? [c] : c))
688
- throw new g('unexpected "aud" claim value', a, "aud", "check_failed");
688
+ throw new A('unexpected "aud" claim value', a, "aud", "check_failed");
689
689
  let p;
690
690
  switch (typeof r.clockTolerance) {
691
691
  case "string":
@@ -700,18 +700,18 @@ const Rt = (e) => Math.floor(e.getTime() / 1e3), De = 60, Ue = De * 60, ce = Ue
700
700
  default:
701
701
  throw new TypeError("Invalid clockTolerance option type");
702
702
  }
703
- const { currentDate: A } = r, E = Rt(A || /* @__PURE__ */ new Date());
703
+ const { currentDate: T } = r, E = Rt(T || /* @__PURE__ */ new Date());
704
704
  if ((a.iat !== void 0 || d) && typeof a.iat != "number")
705
- throw new g('"iat" claim must be a number', a, "iat", "invalid");
705
+ throw new A('"iat" claim must be a number', a, "iat", "invalid");
706
706
  if (a.nbf !== void 0) {
707
707
  if (typeof a.nbf != "number")
708
- throw new g('"nbf" claim must be a number', a, "nbf", "invalid");
708
+ throw new A('"nbf" claim must be a number', a, "nbf", "invalid");
709
709
  if (a.nbf > E + p)
710
- throw new g('"nbf" claim timestamp check failed', a, "nbf", "check_failed");
710
+ throw new A('"nbf" claim timestamp check failed', a, "nbf", "check_failed");
711
711
  }
712
712
  if (a.exp !== void 0) {
713
713
  if (typeof a.exp != "number")
714
- throw new g('"exp" claim must be a number', a, "exp", "invalid");
714
+ throw new A('"exp" claim must be a number', a, "exp", "invalid");
715
715
  if (a.exp <= E - p)
716
716
  throw new de('"exp" claim timestamp check failed', a, "exp", "check_failed");
717
717
  }
@@ -720,7 +720,7 @@ const Rt = (e) => Math.floor(e.getTime() / 1e3), De = 60, Ue = De * 60, ce = Ue
720
720
  if (S - p > K)
721
721
  throw new de('"iat" claim timestamp check failed (too far in the past)', a, "iat", "check_failed");
722
722
  if (S < 0 - p)
723
- throw new g('"iat" claim timestamp check failed (it should be in the past)', a, "iat", "check_failed");
723
+ throw new A('"iat" claim timestamp check failed (it should be in the past)', a, "iat", "check_failed");
724
724
  }
725
725
  return a;
726
726
  };
@@ -1068,34 +1068,34 @@ const M = () => {
1068
1068
  key: `${j}::${r}::@@user@@`
1069
1069
  }), [i, c, , d] = J({
1070
1070
  key: `${j}::${r}::@@access@@`
1071
- }), [y, p, , A] = J(
1071
+ }), [y, p, , T] = J(
1072
1072
  {
1073
1073
  key: `${j}::${r}::@@refresh@@`
1074
1074
  }
1075
1075
  ), [E, S, , K] = J({
1076
1076
  key: `${j}::${r}::@@nonce@@`
1077
- }), Ne = new tr(i, y), [P, T] = Fe({
1077
+ }), Ne = new tr(i, y), [P, k] = Fe({
1078
1078
  isLoading: !0,
1079
1079
  isAuthenticated: !1,
1080
1080
  user: void 0,
1081
1081
  logoutReason: ""
1082
- }), k = Ge(
1082
+ }), b = Ge(
1083
1083
  (u) => {
1084
- console.warn(u), T({
1084
+ console.warn(u), k({
1085
1085
  isLoading: !0,
1086
1086
  isAuthenticated: !1,
1087
1087
  user: void 0,
1088
1088
  logoutReason: u || ne
1089
- }), o(), d(), A(), K();
1089
+ }), o(), d(), T(), K();
1090
1090
  },
1091
- [o, d, K, A]
1091
+ [o, d, K, T]
1092
1092
  );
1093
1093
  qe(() => {
1094
1094
  if (!a.current)
1095
1095
  return P.isLoading && n !== null ? (async () => {
1096
1096
  try {
1097
1097
  const u = await H(n);
1098
- u && u.payload[m.USER_ID_KEY] !== "" ? T({
1098
+ u && u.payload[m.USER_ID_KEY] !== "" ? k({
1099
1099
  isLoading: !1,
1100
1100
  isAuthenticated: !0,
1101
1101
  user: {
@@ -1103,27 +1103,27 @@ const M = () => {
1103
1103
  username: u.payload[m.USERNAME_KEY]
1104
1104
  },
1105
1105
  logoutReason: ""
1106
- }) : (k(ne), await oe({
1106
+ }) : (b(ne), await oe({
1107
1107
  idToken: n,
1108
1108
  accessToken: i,
1109
1109
  refreshToken: y,
1110
1110
  clientId: r
1111
- }), T((w) => ({
1111
+ }), k((w) => ({
1112
1112
  ...w,
1113
1113
  isLoading: !1
1114
1114
  })));
1115
1115
  } catch {
1116
- k(ne), await oe({
1116
+ b(ne), await oe({
1117
1117
  idToken: n,
1118
1118
  accessToken: i,
1119
1119
  refreshToken: y,
1120
1120
  clientId: r
1121
- }), T((w) => ({
1121
+ }), k((w) => ({
1122
1122
  ...w,
1123
1123
  isLoading: !1
1124
1124
  }));
1125
1125
  }
1126
- })() : T((u) => ({
1126
+ })() : k((u) => ({
1127
1127
  ...u,
1128
1128
  isLoading: !1
1129
1129
  })), () => {
@@ -1135,14 +1135,14 @@ const M = () => {
1135
1135
  n,
1136
1136
  y,
1137
1137
  r,
1138
- k
1138
+ b
1139
1139
  ]);
1140
- const Le = async (u, w, b) => {
1140
+ const Le = async (u, w, g) => {
1141
1141
  const I = Gt();
1142
- if (S(I), T((Q) => ({
1142
+ if (S(I), k((Q) => ({
1143
1143
  ...Q,
1144
1144
  isLoading: !0
1145
- })), b === F.CODE) {
1145
+ })), g === F.CODE) {
1146
1146
  const { code_verifier: Q, code_challenge: xe } = await xt(), ue = await Zt({
1147
1147
  nonce: I,
1148
1148
  clientId: r,
@@ -1155,11 +1155,11 @@ const M = () => {
1155
1155
  clientId: r,
1156
1156
  sessionExpiration: t,
1157
1157
  nonce: I,
1158
- type: b,
1158
+ type: g,
1159
1159
  code: ue.code,
1160
1160
  code_verifier: Q
1161
1161
  });
1162
- return D.status ? (s(D.idToken), c(D.accessToken), p(D.refreshToken), T({
1162
+ return D.status ? (s(D.idToken), c(D.accessToken), p(D.refreshToken), k({
1163
1163
  isLoading: !1,
1164
1164
  isAuthenticated: !0,
1165
1165
  user: {
@@ -1167,7 +1167,7 @@ const M = () => {
1167
1167
  username: u
1168
1168
  },
1169
1169
  logoutReason: ""
1170
- }), !0) : (k(Ae), !1);
1170
+ }), !0) : (b(Ae), !1);
1171
1171
  }
1172
1172
  return !1;
1173
1173
  }
@@ -1177,23 +1177,23 @@ const M = () => {
1177
1177
  clientId: r,
1178
1178
  sessionExpiration: t,
1179
1179
  nonce: I,
1180
- type: b
1180
+ type: g
1181
1181
  });
1182
- return O.status ? (s(O.idToken), c(O.accessToken), p(O.refreshToken), T({
1182
+ return O.status ? (s(O.idToken), c(O.accessToken), p(O.refreshToken), k({
1183
1183
  isLoading: !1,
1184
1184
  isAuthenticated: !0,
1185
1185
  user: {
1186
1186
  userId: O.userId,
1187
1187
  username: u
1188
1188
  }
1189
- }), !0) : (k(Ae), !1);
1189
+ }), !0) : (b(Ae), !1);
1190
1190
  }, $e = async (u) => {
1191
- u == null || u.preventDefault(), k(qt), await oe({
1191
+ u == null || u.preventDefault(), b(qt), await oe({
1192
1192
  idToken: n,
1193
1193
  accessToken: i,
1194
1194
  refreshToken: y,
1195
1195
  clientId: r
1196
- }), T((w) => ({
1196
+ }), k((w) => ({
1197
1197
  ...w,
1198
1198
  isLoading: !1
1199
1199
  }));
@@ -1206,16 +1206,16 @@ const M = () => {
1206
1206
  if (I && I.payload[m.USER_ID_KEY] !== "")
1207
1207
  return i;
1208
1208
  }
1209
- const b = await Ne.refreshtoken({
1209
+ const g = await Ne.refreshtoken({
1210
1210
  clientId: r,
1211
1211
  userId: w.userId,
1212
1212
  nonce: E
1213
1213
  });
1214
- return b.status ? (c(b.newAccessToken), p(b.newRefreshToken), b.newAccessToken) : (k(se), "");
1214
+ return g.status && g.status === "success" ? (c(g.newAccessToken), p(g.newRefreshToken), g.newAccessToken) : (b(se), "");
1215
1215
  }
1216
- return k(se), "";
1216
+ return b(se), "";
1217
1217
  } catch {
1218
- return k(se), "";
1218
+ return b(se), "";
1219
1219
  }
1220
1220
  }, Je = () => {
1221
1221
  if (P.isAuthenticated && n)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@versini/auth-provider",
3
- "version": "5.0.3",
3
+ "version": "5.0.4",
4
4
  "license": "MIT",
5
5
  "author": "Arno Versini",
6
6
  "publishConfig": {
@@ -49,5 +49,5 @@
49
49
  "jose": "5.6.3",
50
50
  "uuid": "10.0.0"
51
51
  },
52
- "gitHead": "9701c63e8ac76af08e748b921c0d69c37cded915"
52
+ "gitHead": "f674a54d8b496db21e5f762f59c299eb4e5429e7"
53
53
  }