@versini/auth-provider 6.3.5 → 6.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -32,14 +32,14 @@ type AuthState = {
32
32
  debug?: boolean;
33
33
  };
34
34
 
35
- type LoginType = (
35
+ type LoginResponse = (
36
36
  username: string,
37
37
  password: string,
38
38
  type?: typeof AUTH_TYPES.CODE | typeof AUTH_TYPES.PASSKEY,
39
39
  ) => Promise<boolean>;
40
40
 
41
41
  type AuthContextProps = {
42
- login: LoginType;
42
+ login: LoginResponse;
43
43
  logout: (e?: any) => void;
44
44
  getAccessToken: () => Promise<string>;
45
45
  getIdToken: () => string;
package/dist/index.js CHANGED
@@ -4,13 +4,13 @@ var Q = (e, t, n) => Ct(e, typeof t != "symbol" ? t + "" : t, n);
4
4
  import { jsx as ve } from "react/jsx-runtime";
5
5
  import Pt, { useSyncExternalStore as kt, useCallback as x, useEffect as Ae, createContext as Ot, useReducer as Nt, useRef as Ce, useContext as Dt } from "react";
6
6
  /*!
7
- @versini/auth-provider v6.3.5
7
+ @versini/auth-provider v6.4.0
8
8
  © 2024 gizmette.com
9
9
  */
10
10
  try {
11
11
  window.__VERSINI_AUTH_CLIENT__ || (window.__VERSINI_AUTH_CLIENT__ = {
12
- version: "6.3.5",
13
- buildTime: "07/24/2024 07:48 PM EDT",
12
+ version: "6.4.0",
13
+ buildTime: "07/26/2024 07:51 PM EDT",
14
14
  homepage: "https://github.com/aversini/auth-client",
15
15
  license: "MIT"
16
16
  });
@@ -308,13 +308,13 @@ async function xt(e, t = !1) {
308
308
  try {
309
309
  window.__VERSINI_AUTH_COMMON__ || (window.__VERSINI_AUTH_COMMON__ = {
310
310
  version: "3.3.0",
311
- buildTime: "07/24/2024 07:48 PM EDT",
311
+ buildTime: "07/26/2024 07:51 PM EDT",
312
312
  homepage: "https://github.com/aversini/auth-client",
313
313
  license: "MIT"
314
314
  });
315
315
  } catch {
316
316
  }
317
- const F = {
317
+ const M = {
318
318
  ID_TOKEN: "id_token",
319
319
  ACCESS_TOKEN: "token",
320
320
  ID_AND_ACCESS_TOKEN: "id_token token",
@@ -359,7 +359,7 @@ const Jt = (e) => {
359
359
  for (let r = 0; r < t.length; r++)
360
360
  n[r] = t.charCodeAt(r);
361
361
  return n;
362
- }, j = (e) => {
362
+ }, F = (e) => {
363
363
  let t = e;
364
364
  t instanceof Uint8Array && (t = B.decode(t)), t = t.replace(/-/g, "+").replace(/_/g, "/").replace(/\s/g, "");
365
365
  try {
@@ -646,7 +646,7 @@ const Zt = async (e) => {
646
646
  e.key_ops ?? n
647
647
  ], a = { ...e };
648
648
  return delete a.alg, delete a.use, he.subtle.importKey("jwk", a, ...r);
649
- }, Ze = (e) => j(e);
649
+ }, Ze = (e) => F(e);
650
650
  let ge, me;
651
651
  const et = (e) => e?.[Symbol.toStringTag] === "KeyObject", tt = async (e, t, n, r) => {
652
652
  let a = e.get(t);
@@ -850,7 +850,7 @@ async function yn(e, t, n) {
850
850
  let r = {};
851
851
  if (e.protected)
852
852
  try {
853
- const u = j(e.protected);
853
+ const u = F(e.protected);
854
854
  r = JSON.parse(B.decode(u));
855
855
  } catch {
856
856
  throw new S("JWS Protected Header is invalid");
@@ -880,7 +880,7 @@ async function yn(e, t, n) {
880
880
  const l = Gt(X.encode(e.protected ?? ""), X.encode("."), typeof e.payload == "string" ? X.encode(e.payload) : e.payload);
881
881
  let h;
882
882
  try {
883
- h = j(e.signature);
883
+ h = F(e.signature);
884
884
  } catch {
885
885
  throw new S("Failed to base64url decode the signature");
886
886
  }
@@ -889,7 +889,7 @@ async function yn(e, t, n) {
889
889
  let y;
890
890
  if (o)
891
891
  try {
892
- y = j(e.payload);
892
+ y = F(e.payload);
893
893
  } catch {
894
894
  throw new S("Failed to base64url decode the payload");
895
895
  }
@@ -1017,7 +1017,7 @@ async function Rn(e, t, n) {
1017
1017
  const s = { payload: Tn(a.protectedHeader, a.payload, n), protectedHeader: a.protectedHeader };
1018
1018
  return typeof t == "function" ? { ...s, key: a.key } : s;
1019
1019
  }
1020
- const bn = j;
1020
+ const bn = F;
1021
1021
  function In(e) {
1022
1022
  if (typeof e != "string")
1023
1023
  throw new P("JWTs must use Compact JWS serialization, JWT must be a string");
@@ -1044,7 +1044,7 @@ function In(e) {
1044
1044
  throw new P("Invalid JWT Claims Set");
1045
1045
  return a;
1046
1046
  }
1047
- const M = async (e) => {
1047
+ const G = async (e) => {
1048
1048
  try {
1049
1049
  const t = A.ALG, n = await on(Mt, t);
1050
1050
  return await Rn(e, n, {
@@ -1103,7 +1103,7 @@ async function Un(e) {
1103
1103
  }
1104
1104
  const Dr = async (e, t) => {
1105
1105
  var n;
1106
- const r = await M(e);
1106
+ const r = await G(e);
1107
1107
  if (!r || !Array.isArray((n = r.payload) == null ? void 0 : n[A.SCOPES_KEY]))
1108
1108
  return !1;
1109
1109
  const a = r.payload[A.SCOPES_KEY];
@@ -1175,7 +1175,7 @@ function Se(e, t, n) {
1175
1175
  const $ = "Oops! It looks like your session has expired. For your security, please log in again to continue.", Mn = "Your session has been successfully terminated.", re = "Login failed. Please try again.", Gn = "Error getting access token, please re-authenticate.", Jn = "You forgot to wrap your component in <AuthProvider>.", le = {
1176
1176
  dev: "https://auth.gizmette.local.com:3003",
1177
1177
  prod: "https://mylogin.gizmette.com/auth"
1178
- }, ae = "@@auth@@", Y = "LOADING", V = "LOGIN", ot = "LOGOUT", Yn = "success", xe = "failure";
1178
+ }, ae = "@@auth@@", V = "LOADING", j = "LOGIN", ot = "LOGOUT", Yn = "success", xe = "failure";
1179
1179
  /*!
1180
1180
  @versini/ui-fingerprint v1.0.1
1181
1181
  © 2024 gizmette.com
@@ -1749,7 +1749,7 @@ const pr = async (e) => {
1749
1749
  type: de.AUTHENTICATE,
1750
1750
  clientId: n,
1751
1751
  params: {
1752
- type: a || F.ID_AND_ACCESS_TOKEN,
1752
+ type: a || M.ID_AND_ACCESS_TOKEN,
1753
1753
  username: e,
1754
1754
  password: t,
1755
1755
  sessionExpiration: s,
@@ -1759,7 +1759,7 @@ const pr = async (e) => {
1759
1759
  domain: c,
1760
1760
  fingerprint: g
1761
1761
  }
1762
- }), h = await M(l?.data?.idToken);
1762
+ }), h = await G(l?.data?.idToken);
1763
1763
  return h && h.payload[A.USER_ID_KEY] !== "" && h.payload[A.NONCE_KEY] === r ? {
1764
1764
  idToken: l.data.idToken,
1765
1765
  accessToken: l.data.accessToken,
@@ -1784,7 +1784,7 @@ const pr = async (e) => {
1784
1784
  type: de.CODE,
1785
1785
  clientId: t,
1786
1786
  params: {
1787
- type: F.CODE,
1787
+ type: M.CODE,
1788
1788
  nonce: e,
1789
1789
  code_challenge: n
1790
1790
  }
@@ -1813,7 +1813,7 @@ const pr = async (e) => {
1813
1813
  type: de.AUTHENTICATE,
1814
1814
  clientId: e,
1815
1815
  params: {
1816
- type: F.REFRESH_TOKEN,
1816
+ type: M.REFRESH_TOKEN,
1817
1817
  userId: t,
1818
1818
  nonce: n,
1819
1819
  refreshToken: r,
@@ -1821,7 +1821,7 @@ const pr = async (e) => {
1821
1821
  domain: s,
1822
1822
  fingerprint: await yt()
1823
1823
  }
1824
- }), i = await M(o?.data?.accessToken);
1824
+ }), i = await G(o?.data?.accessToken);
1825
1825
  return i && i.payload[A.USER_ID_KEY] !== "" && i.payload[A.NONCE_KEY] === n ? {
1826
1826
  accessToken: o.data.accessToken,
1827
1827
  refreshToken: o.data.refreshToken,
@@ -1873,7 +1873,7 @@ class Ar {
1873
1873
  nonce: r,
1874
1874
  domain: a
1875
1875
  }) {
1876
- const s = await M(this.refreshToken);
1876
+ const s = await G(this.refreshToken);
1877
1877
  if (s && s.payload[A.USER_ID_KEY] !== "") {
1878
1878
  const o = await Sr({
1879
1879
  clientId: t,
@@ -1918,10 +1918,10 @@ const Tr = (e) => x(
1918
1918
  state: ft,
1919
1919
  dispatch: () => {
1920
1920
  }
1921
- }), br = (e, t) => t?.type === Y ? {
1921
+ }), br = (e, t) => t?.type === V ? {
1922
1922
  ...e,
1923
1923
  isLoading: t.payload.isLoading
1924
- } : t?.type === V ? {
1924
+ } : t?.type === j ? {
1925
1925
  ...e,
1926
1926
  isLoading: !1,
1927
1927
  isAuthenticated: !0,
@@ -1965,7 +1965,7 @@ const Tr = (e) => x(
1965
1965
  payload: {
1966
1966
  logoutReason: d || $
1967
1967
  }
1968
- }), y(), m(), z(), Ie(), o({ type: Y, payload: { isLoading: !1 } });
1968
+ }), y(), m(), z(), Ie(), o({ type: V, payload: { isLoading: !1 } });
1969
1969
  },
1970
1970
  [m, y, Ie, z, i]
1971
1971
  ), N = x(
@@ -1994,15 +1994,15 @@ const Tr = (e) => x(
1994
1994
  i
1995
1995
  ]
1996
1996
  );
1997
- Ae(() => ((async () => (i("useEffect: setting the fingerprint"), g.current = await yt()))(), () => {
1998
- i("useEffect: cleaning up the fingerprint"), g.current = "";
1997
+ Ae(() => ((async () => g.current = await yt())(), () => {
1998
+ g.current = "";
1999
1999
  }), []), Ae(() => {
2000
2000
  if (!c.current)
2001
2001
  return s.isLoading && l !== null ? (async () => {
2002
2002
  try {
2003
- const d = await M(l);
2003
+ const d = await G(l);
2004
2004
  d && d.payload[A.USER_ID_KEY] !== "" ? (i("useEffect: setting the authentication state"), o({
2005
- type: V,
2005
+ type: j,
2006
2006
  payload: {
2007
2007
  authenticationType: d.payload[A.AUTH_TYPE_KEY],
2008
2008
  user: {
@@ -2016,20 +2016,20 @@ const Tr = (e) => x(
2016
2016
  "useEffect: exception validating JWT, invalidating and logging out"
2017
2017
  ), await N($);
2018
2018
  }
2019
- })() : (i("useEffect: setting the loading state to false"), o({ type: Y, payload: { isLoading: !1 } })), () => {
2019
+ })() : (i("useEffect: setting the loading state to false"), o({ type: V, payload: { isLoading: !1 } })), () => {
2020
2020
  c.current = !0;
2021
2021
  };
2022
2022
  }, [s.isLoading, l, N, i]);
2023
- const Et = async (d, R, f) => {
2023
+ const Et = async (d, R, f = M.CODE) => {
2024
2024
  const I = Se();
2025
- if (be(I), o({ type: Y, payload: { isLoading: !0 } }), y(), m(), z(), i("login: Logging in with type: ", f), f === F.CODE) {
2025
+ if (be(I), o({ type: V, payload: { isLoading: !0 } }), y(), m(), z(), i("login: Logging in with type: ", f), f === M.CODE) {
2026
2026
  const { code_verifier: It, code_challenge: _t } = await Un(), _e = await Er({
2027
2027
  nonce: I,
2028
2028
  clientId: n,
2029
2029
  code_challenge: _t
2030
2030
  });
2031
2031
  if (_e.status) {
2032
- const J = await Je({
2032
+ const Y = await Je({
2033
2033
  username: d,
2034
2034
  password: R,
2035
2035
  clientId: n,
@@ -2041,12 +2041,12 @@ const Tr = (e) => x(
2041
2041
  domain: r,
2042
2042
  fingerprint: g.current
2043
2043
  });
2044
- return J.status ? (h(J.idToken), u(J.accessToken), q(J.refreshToken), o({
2045
- type: V,
2044
+ return Y.status ? (h(Y.idToken), u(Y.accessToken), q(Y.refreshToken), o({
2045
+ type: j,
2046
2046
  payload: {
2047
2047
  authenticationType: f,
2048
2048
  user: {
2049
- userId: J.userId,
2049
+ userId: Y.userId,
2050
2050
  username: d
2051
2051
  }
2052
2052
  }
@@ -2054,7 +2054,7 @@ const Tr = (e) => x(
2054
2054
  }
2055
2055
  return !1;
2056
2056
  }
2057
- const G = await Je({
2057
+ const J = await Je({
2058
2058
  username: d,
2059
2059
  password: R,
2060
2060
  clientId: n,
@@ -2064,12 +2064,12 @@ const Tr = (e) => x(
2064
2064
  domain: r,
2065
2065
  fingerprint: g.current
2066
2066
  });
2067
- return G.status ? (h(G.idToken), u(G.accessToken), q(G.refreshToken), o({
2068
- type: V,
2067
+ return J.status ? (h(J.idToken), u(J.accessToken), q(J.refreshToken), o({
2068
+ type: j,
2069
2069
  payload: {
2070
2070
  authenticationType: f,
2071
2071
  user: {
2072
- userId: G.userId,
2072
+ userId: J.userId,
2073
2073
  username: d
2074
2074
  }
2075
2075
  }
@@ -2082,7 +2082,7 @@ const Tr = (e) => x(
2082
2082
  if (d && R && R.userId) {
2083
2083
  if (p) {
2084
2084
  i("getAccessToken");
2085
- const I = await M(p);
2085
+ const I = await G(p);
2086
2086
  if (I && I.payload[A.USER_ID_KEY] !== "")
2087
2087
  return p;
2088
2088
  }
@@ -2149,7 +2149,7 @@ const Tr = (e) => x(
2149
2149
  }
2150
2150
  }, bt = async () => {
2151
2151
  const d = Se();
2152
- be(d), o({ type: Y, payload: { isLoading: !0 } }), y(), m(), z(), i("loginWithPasskey");
2152
+ be(d), o({ type: V, payload: { isLoading: !0 } }), y(), m(), z(), i("loginWithPasskey");
2153
2153
  const R = Se();
2154
2154
  let f = await L({
2155
2155
  accessToken: p,
@@ -2176,9 +2176,9 @@ const Tr = (e) => x(
2176
2176
  fingerprint: g.current
2177
2177
  }
2178
2178
  }), f.data.status === "success" ? (h(f.data.idToken), u(f.data.accessToken), q(f.data.refreshToken), o({
2179
- type: V,
2179
+ type: j,
2180
2180
  payload: {
2181
- authenticationType: F.PASSKEY,
2181
+ authenticationType: M.PASSKEY,
2182
2182
  user: {
2183
2183
  userId: f.data.userId,
2184
2184
  username: f.data.username
@@ -2217,7 +2217,7 @@ const Tr = (e) => x(
2217
2217
  ) });
2218
2218
  }, $r = (e = gt) => Dt(e);
2219
2219
  export {
2220
- F as AUTH_TYPES,
2220
+ M as AUTH_TYPES,
2221
2221
  Ur as AuthProvider,
2222
2222
  Dr as isGranted,
2223
2223
  $r as useAuth
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@versini/auth-provider",
3
- "version": "6.3.5",
3
+ "version": "6.4.0",
4
4
  "license": "MIT",
5
5
  "author": "Arno Versini",
6
6
  "publishConfig": {
@@ -51,5 +51,5 @@
51
51
  "jose": "5.6.3",
52
52
  "uuid": "10.0.0"
53
53
  },
54
- "gitHead": "c80771b79faa52666932c939fe4f4c1fc371e9fc"
54
+ "gitHead": "37e3ab55aa655ce3427a8da5edef13da366478da"
55
55
  }