@versini/auth-provider 2.2.0 → 2.3.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
@@ -10,9 +10,6 @@ type AuthProviderProps = {
10
10
 
11
11
  type AuthState = {
12
12
  isAuthenticated: boolean;
13
- idToken?: string;
14
- accessToken?: string;
15
- refreshToken?: string;
16
13
  logoutReason?: string;
17
14
  userId?: string;
18
15
  };
@@ -20,6 +17,7 @@ type AuthState = {
20
17
  type AuthContextProps = {
21
18
  login: (username: string, password: string) => Promise<boolean>;
22
19
  logout: () => void;
20
+ getIdTokenClaims: () => Promise<any>;
23
21
  } & AuthState;
24
22
 
25
23
  declare const AuthProvider: ({ children, sessionExpiration, clientId, }: AuthProviderProps) => react_jsx_runtime.JSX.Element;
package/dist/index.js CHANGED
@@ -1,33 +1,33 @@
1
1
  import { jsx as ne } from "react/jsx-runtime";
2
2
  import * as I from "react";
3
- import { useRef as ae, useEffect as F, createContext as se, useState as ie, useContext as ce } from "react";
3
+ import { useRef as ae, useEffect as Y, createContext as se, useState as ie, useContext as ce } from "react";
4
4
  /*!
5
- @versini/auth-provider v2.2.0
5
+ @versini/auth-provider v2.3.0
6
6
  © 2024 gizmette.com
7
7
  */
8
8
  try {
9
9
  window.__VERSINI_AUTH_CLIENT__ || (window.__VERSINI_AUTH_CLIENT__ = {
10
- version: "2.2.0",
11
- buildTime: "06/24/2024 05:23 PM EDT",
10
+ version: "2.3.0",
11
+ buildTime: "06/24/2024 06:34 PM EDT",
12
12
  homepage: "https://github.com/aversini/auth-client",
13
13
  license: "MIT"
14
14
  });
15
15
  } catch {
16
16
  }
17
17
  /*!
18
- @versini/auth-common v2.2.0
18
+ @versini/auth-common v2.3.0
19
19
  © 2024 gizmette.com
20
20
  */
21
21
  try {
22
22
  window.__VERSINI_AUTH_COMMON__ || (window.__VERSINI_AUTH_COMMON__ = {
23
- version: "2.2.0",
24
- buildTime: "06/24/2024 05:23 PM EDT",
23
+ version: "2.3.0",
24
+ buildTime: "06/24/2024 06:34 PM EDT",
25
25
  homepage: "https://github.com/aversini/auth-client",
26
26
  license: "MIT"
27
27
  });
28
28
  } catch {
29
29
  }
30
- const H = crypto, G = (e) => e instanceof CryptoKey, v = new TextEncoder(), T = new TextDecoder();
30
+ const U = crypto, G = (e) => e instanceof CryptoKey, _ = new TextEncoder(), T = new TextDecoder();
31
31
  function ue(...e) {
32
32
  const t = e.reduce((n, { length: a }) => n + a, 0), o = new Uint8Array(t);
33
33
  let r = 0;
@@ -40,7 +40,7 @@ const de = (e) => {
40
40
  for (let r = 0; r < t.length; r++)
41
41
  o[r] = t.charCodeAt(r);
42
42
  return o;
43
- }, P = (e) => {
43
+ }, C = (e) => {
44
44
  let t = e;
45
45
  t instanceof Uint8Array && (t = T.decode(t)), t = t.replace(/-/g, "+").replace(/_/g, "/").replace(/\s/g, "");
46
46
  try {
@@ -49,7 +49,7 @@ const de = (e) => {
49
49
  throw new TypeError("The input to be decoded is not correctly encoded.");
50
50
  }
51
51
  };
52
- class A extends Error {
52
+ class b extends Error {
53
53
  static get code() {
54
54
  return "ERR_JOSE_GENERIC";
55
55
  }
@@ -58,7 +58,7 @@ class A extends Error {
58
58
  super(t), this.code = "ERR_JOSE_GENERIC", this.name = this.constructor.name, (o = Error.captureStackTrace) == null || o.call(Error, this, this.constructor);
59
59
  }
60
60
  }
61
- class f extends A {
61
+ class m extends b {
62
62
  static get code() {
63
63
  return "ERR_JWT_CLAIM_VALIDATION_FAILED";
64
64
  }
@@ -66,7 +66,7 @@ class f extends A {
66
66
  super(t), this.code = "ERR_JWT_CLAIM_VALIDATION_FAILED", this.claim = r, this.reason = n, this.payload = o;
67
67
  }
68
68
  }
69
- class N extends A {
69
+ class $ extends b {
70
70
  static get code() {
71
71
  return "ERR_JWT_EXPIRED";
72
72
  }
@@ -74,7 +74,7 @@ class N extends A {
74
74
  super(t), this.code = "ERR_JWT_EXPIRED", this.claim = r, this.reason = n, this.payload = o;
75
75
  }
76
76
  }
77
- class le extends A {
77
+ class le extends b {
78
78
  constructor() {
79
79
  super(...arguments), this.code = "ERR_JOSE_ALG_NOT_ALLOWED";
80
80
  }
@@ -82,7 +82,7 @@ class le extends A {
82
82
  return "ERR_JOSE_ALG_NOT_ALLOWED";
83
83
  }
84
84
  }
85
- class k extends A {
85
+ class k extends b {
86
86
  constructor() {
87
87
  super(...arguments), this.code = "ERR_JOSE_NOT_SUPPORTED";
88
88
  }
@@ -90,7 +90,7 @@ class k extends A {
90
90
  return "ERR_JOSE_NOT_SUPPORTED";
91
91
  }
92
92
  }
93
- let l = class extends A {
93
+ let l = class extends b {
94
94
  constructor() {
95
95
  super(...arguments), this.code = "ERR_JWS_INVALID";
96
96
  }
@@ -98,7 +98,7 @@ let l = class extends A {
98
98
  return "ERR_JWS_INVALID";
99
99
  }
100
100
  };
101
- class Y extends A {
101
+ class q extends b {
102
102
  constructor() {
103
103
  super(...arguments), this.code = "ERR_JWT_INVALID";
104
104
  }
@@ -106,7 +106,7 @@ class Y extends A {
106
106
  return "ERR_JWT_INVALID";
107
107
  }
108
108
  }
109
- class he extends A {
109
+ class he extends b {
110
110
  constructor() {
111
111
  super(...arguments), this.code = "ERR_JWS_SIGNATURE_VERIFICATION_FAILED", this.message = "signature verification failed";
112
112
  }
@@ -114,13 +114,13 @@ class he extends A {
114
114
  return "ERR_JWS_SIGNATURE_VERIFICATION_FAILED";
115
115
  }
116
116
  }
117
- function m(e, t = "algorithm.name") {
117
+ function S(e, t = "algorithm.name") {
118
118
  return new TypeError(`CryptoKey does not support this operation, its ${t} must be ${e}`);
119
119
  }
120
- function _(e, t) {
120
+ function v(e, t) {
121
121
  return e.name === t;
122
122
  }
123
- function C(e) {
123
+ function P(e) {
124
124
  return parseInt(e.name.slice(4), 10);
125
125
  }
126
126
  function pe(e) {
@@ -151,46 +151,46 @@ function ye(e, t, ...o) {
151
151
  case "HS256":
152
152
  case "HS384":
153
153
  case "HS512": {
154
- if (!_(e.algorithm, "HMAC"))
155
- throw m("HMAC");
154
+ if (!v(e.algorithm, "HMAC"))
155
+ throw S("HMAC");
156
156
  const r = parseInt(t.slice(2), 10);
157
- if (C(e.algorithm.hash) !== r)
158
- throw m(`SHA-${r}`, "algorithm.hash");
157
+ if (P(e.algorithm.hash) !== r)
158
+ throw S(`SHA-${r}`, "algorithm.hash");
159
159
  break;
160
160
  }
161
161
  case "RS256":
162
162
  case "RS384":
163
163
  case "RS512": {
164
- if (!_(e.algorithm, "RSASSA-PKCS1-v1_5"))
165
- throw m("RSASSA-PKCS1-v1_5");
164
+ if (!v(e.algorithm, "RSASSA-PKCS1-v1_5"))
165
+ throw S("RSASSA-PKCS1-v1_5");
166
166
  const r = parseInt(t.slice(2), 10);
167
- if (C(e.algorithm.hash) !== r)
168
- throw m(`SHA-${r}`, "algorithm.hash");
167
+ if (P(e.algorithm.hash) !== r)
168
+ throw S(`SHA-${r}`, "algorithm.hash");
169
169
  break;
170
170
  }
171
171
  case "PS256":
172
172
  case "PS384":
173
173
  case "PS512": {
174
- if (!_(e.algorithm, "RSA-PSS"))
175
- throw m("RSA-PSS");
174
+ if (!v(e.algorithm, "RSA-PSS"))
175
+ throw S("RSA-PSS");
176
176
  const r = parseInt(t.slice(2), 10);
177
- if (C(e.algorithm.hash) !== r)
178
- throw m(`SHA-${r}`, "algorithm.hash");
177
+ if (P(e.algorithm.hash) !== r)
178
+ throw S(`SHA-${r}`, "algorithm.hash");
179
179
  break;
180
180
  }
181
181
  case "EdDSA": {
182
182
  if (e.algorithm.name !== "Ed25519" && e.algorithm.name !== "Ed448")
183
- throw m("Ed25519 or Ed448");
183
+ throw S("Ed25519 or Ed448");
184
184
  break;
185
185
  }
186
186
  case "ES256":
187
187
  case "ES384":
188
188
  case "ES512": {
189
- if (!_(e.algorithm, "ECDSA"))
190
- throw m("ECDSA");
189
+ if (!v(e.algorithm, "ECDSA"))
190
+ throw S("ECDSA");
191
191
  const r = pe(t);
192
192
  if (e.algorithm.namedCurve !== r)
193
- throw m(r, "algorithm.namedCurve");
193
+ throw S(r, "algorithm.namedCurve");
194
194
  break;
195
195
  }
196
196
  default:
@@ -198,7 +198,7 @@ function ye(e, t, ...o) {
198
198
  }
199
199
  fe(e, o);
200
200
  }
201
- function q(e, t, ...o) {
201
+ function z(e, t, ...o) {
202
202
  var r;
203
203
  if (o.length > 2) {
204
204
  const n = o.pop();
@@ -207,11 +207,11 @@ function q(e, t, ...o) {
207
207
  o.length === 2 ? e += `one of type ${o[0]} or ${o[1]}.` : e += `of type ${o[0]}.`;
208
208
  return t == null ? e += ` Received ${t}` : typeof t == "function" && t.name ? e += ` Received function ${t.name}` : typeof t == "object" && t != null && (r = t.constructor) != null && r.name && (e += ` Received an instance of ${t.constructor.name}`), e;
209
209
  }
210
- const J = (e, ...t) => q("Key must be ", e, ...t);
211
- function z(e, t, ...o) {
212
- return q(`Key for the ${e} algorithm must be `, t, ...o);
210
+ const L = (e, ...t) => z("Key must be ", e, ...t);
211
+ function X(e, t, ...o) {
212
+ return z(`Key for the ${e} algorithm must be `, t, ...o);
213
213
  }
214
- const X = (e) => G(e), E = ["CryptoKey"], me = (...e) => {
214
+ const Q = (e) => G(e), g = ["CryptoKey"], me = (...e) => {
215
215
  const t = e.filter(Boolean);
216
216
  if (t.length === 0 || t.length === 1)
217
217
  return !0;
@@ -233,7 +233,7 @@ const X = (e) => G(e), E = ["CryptoKey"], me = (...e) => {
233
233
  function we(e) {
234
234
  return typeof e == "object" && e !== null;
235
235
  }
236
- function D(e) {
236
+ function H(e) {
237
237
  if (!we(e) || Object.prototype.toString.call(e) !== "[object Object]")
238
238
  return !1;
239
239
  if (Object.getPrototypeOf(e) === null)
@@ -249,33 +249,33 @@ const Se = (e, t) => {
249
249
  if (typeof o != "number" || o < 2048)
250
250
  throw new TypeError(`${e} requires key modulusLength to be 2048 bits or larger`);
251
251
  }
252
- }, g = (e, t, o = 0) => {
252
+ }, E = (e, t, o = 0) => {
253
253
  o === 0 && (t.unshift(t.length), t.unshift(6));
254
254
  const r = e.indexOf(t[0], o);
255
255
  if (r === -1)
256
256
  return !1;
257
257
  const n = e.subarray(r, r + t.length);
258
- return n.length !== t.length ? !1 : n.every((a, s) => a === t[s]) || g(e, t, r + 1);
259
- }, $ = (e) => {
258
+ return n.length !== t.length ? !1 : n.every((a, s) => a === t[s]) || E(e, t, r + 1);
259
+ }, K = (e) => {
260
260
  switch (!0) {
261
- case g(e, [42, 134, 72, 206, 61, 3, 1, 7]):
261
+ case E(e, [42, 134, 72, 206, 61, 3, 1, 7]):
262
262
  return "P-256";
263
- case g(e, [43, 129, 4, 0, 34]):
263
+ case E(e, [43, 129, 4, 0, 34]):
264
264
  return "P-384";
265
- case g(e, [43, 129, 4, 0, 35]):
265
+ case E(e, [43, 129, 4, 0, 35]):
266
266
  return "P-521";
267
- case g(e, [43, 101, 110]):
267
+ case E(e, [43, 101, 110]):
268
268
  return "X25519";
269
- case g(e, [43, 101, 111]):
269
+ case E(e, [43, 101, 111]):
270
270
  return "X448";
271
- case g(e, [43, 101, 112]):
271
+ case E(e, [43, 101, 112]):
272
272
  return "Ed25519";
273
- case g(e, [43, 101, 113]):
273
+ case E(e, [43, 101, 113]):
274
274
  return "Ed448";
275
275
  default:
276
276
  throw new k("Invalid or unsupported EC Key Curve or OKP Key Sub Type");
277
277
  }
278
- }, ge = async (e, t, o, r, n) => {
278
+ }, Ee = async (e, t, o, r, n) => {
279
279
  let a, s;
280
280
  const i = new Uint8Array(atob(o.replace(e, "")).split("").map((c) => c.charCodeAt(0)));
281
281
  switch (r) {
@@ -311,43 +311,43 @@ const Se = (e, t) => {
311
311
  case "ECDH-ES+A128KW":
312
312
  case "ECDH-ES+A192KW":
313
313
  case "ECDH-ES+A256KW": {
314
- const c = $(i);
314
+ const c = K(i);
315
315
  a = c.startsWith("P-") ? { name: "ECDH", namedCurve: c } : { name: c }, s = [];
316
316
  break;
317
317
  }
318
318
  case "EdDSA":
319
- a = { name: $(i) }, s = ["verify"];
319
+ a = { name: K(i) }, s = ["verify"];
320
320
  break;
321
321
  default:
322
322
  throw new k('Invalid or unsupported "alg" (Algorithm) value');
323
323
  }
324
- return H.subtle.importKey(t, i, a, !1, s);
325
- }, Ee = (e, t, o) => ge(/(?:-----(?:BEGIN|END) PUBLIC KEY-----|\s)/g, "spki", e, t);
324
+ return U.subtle.importKey(t, i, a, !1, s);
325
+ }, ge = (e, t, o) => Ee(/(?:-----(?:BEGIN|END) PUBLIC KEY-----|\s)/g, "spki", e, t);
326
326
  async function Ae(e, t, o) {
327
327
  if (e.indexOf("-----BEGIN PUBLIC KEY-----") !== 0)
328
328
  throw new TypeError('"spki" must be SPKI formatted string');
329
- return Ee(e, t);
329
+ return ge(e, t);
330
330
  }
331
331
  const be = (e, t) => {
332
332
  if (!(t instanceof Uint8Array)) {
333
- if (!X(t))
334
- throw new TypeError(z(e, t, ...E, "Uint8Array"));
333
+ if (!Q(t))
334
+ throw new TypeError(X(e, t, ...g, "Uint8Array"));
335
335
  if (t.type !== "secret")
336
- throw new TypeError(`${E.join(" or ")} instances for symmetric algorithms must be of type "secret"`);
336
+ throw new TypeError(`${g.join(" or ")} instances for symmetric algorithms must be of type "secret"`);
337
337
  }
338
338
  }, Ie = (e, t, o) => {
339
- if (!X(t))
340
- throw new TypeError(z(e, t, ...E));
339
+ if (!Q(t))
340
+ throw new TypeError(X(e, t, ...g));
341
341
  if (t.type === "secret")
342
- throw new TypeError(`${E.join(" or ")} instances for asymmetric algorithms must not be of type "secret"`);
342
+ throw new TypeError(`${g.join(" or ")} instances for asymmetric algorithms must not be of type "secret"`);
343
343
  if (t.algorithm && o === "verify" && t.type === "private")
344
- throw new TypeError(`${E.join(" or ")} instances for asymmetric algorithm verifying must be of type "public"`);
344
+ throw new TypeError(`${g.join(" or ")} instances for asymmetric algorithm verifying must be of type "public"`);
345
345
  if (t.algorithm && o === "encrypt" && t.type === "private")
346
- throw new TypeError(`${E.join(" or ")} instances for asymmetric algorithm encryption must be of type "public"`);
347
- }, ve = (e, t, o) => {
346
+ throw new TypeError(`${g.join(" or ")} instances for asymmetric algorithm encryption must be of type "public"`);
347
+ }, _e = (e, t, o) => {
348
348
  e.startsWith("HS") || e === "dir" || e.startsWith("PBES2") || /^A\d{3}(?:GCM)?KW$/.test(e) ? be(e, t) : Ie(e, t, o);
349
349
  };
350
- function _e(e, t, o, r, n) {
350
+ function ve(e, t, o, r, n) {
351
351
  if (n.crit !== void 0 && (r == null ? void 0 : r.crit) === void 0)
352
352
  throw new e('"crit" (Critical) Header Parameter MUST be integrity protected');
353
353
  if (!r || r.crit === void 0)
@@ -402,23 +402,23 @@ function ke(e, t, o) {
402
402
  return ye(t, e, o), t;
403
403
  if (t instanceof Uint8Array) {
404
404
  if (!e.startsWith("HS"))
405
- throw new TypeError(J(t, ...E));
406
- return H.subtle.importKey("raw", t, { hash: `SHA-${e.slice(-3)}`, name: "HMAC" }, !1, [o]);
405
+ throw new TypeError(L(t, ...g));
406
+ return U.subtle.importKey("raw", t, { hash: `SHA-${e.slice(-3)}`, name: "HMAC" }, !1, [o]);
407
407
  }
408
- throw new TypeError(J(t, ...E, "Uint8Array"));
408
+ throw new TypeError(L(t, ...g, "Uint8Array"));
409
409
  }
410
- const Pe = async (e, t, o, r) => {
410
+ const Ce = async (e, t, o, r) => {
411
411
  const n = await ke(e, t, "verify");
412
412
  Se(e, n);
413
413
  const a = Te(e, n.algorithm);
414
414
  try {
415
- return await H.subtle.verify(a, n, o, r);
415
+ return await U.subtle.verify(a, n, o, r);
416
416
  } catch {
417
417
  return !1;
418
418
  }
419
419
  };
420
- async function Ce(e, t, o) {
421
- if (!D(e))
420
+ async function Pe(e, t, o) {
421
+ if (!H(e))
422
422
  throw new l("Flattened JWS must be an object");
423
423
  if (e.protected === void 0 && e.header === void 0)
424
424
  throw new l('Flattened JWS must have either of the "protected" or "header" members');
@@ -428,13 +428,13 @@ async function Ce(e, t, o) {
428
428
  throw new l("JWS Payload missing");
429
429
  if (typeof e.signature != "string")
430
430
  throw new l("JWS Signature missing or incorrect type");
431
- if (e.header !== void 0 && !D(e.header))
431
+ if (e.header !== void 0 && !H(e.header))
432
432
  throw new l("JWS Unprotected Header incorrect type");
433
433
  let r = {};
434
434
  if (e.protected)
435
435
  try {
436
- const S = P(e.protected);
437
- r = JSON.parse(T.decode(S));
436
+ const p = C(e.protected);
437
+ r = JSON.parse(T.decode(p));
438
438
  } catch {
439
439
  throw new l("JWS Protected Header is invalid");
440
440
  }
@@ -443,7 +443,7 @@ async function Ce(e, t, o) {
443
443
  const n = {
444
444
  ...r,
445
445
  ...e.header
446
- }, a = _e(l, /* @__PURE__ */ new Map([["b64", !0]]), o == null ? void 0 : o.crit, r, n);
446
+ }, a = ve(l, /* @__PURE__ */ new Map([["b64", !0]]), o == null ? void 0 : o.crit, r, n);
447
447
  let s = !0;
448
448
  if (a.has("b64") && (s = r.b64, typeof s != "boolean"))
449
449
  throw new l('The "b64" (base64url-encode payload) Header Parameter must be a boolean');
@@ -458,28 +458,28 @@ async function Ce(e, t, o) {
458
458
  throw new l("JWS Payload must be a string");
459
459
  } else if (typeof e.payload != "string" && !(e.payload instanceof Uint8Array))
460
460
  throw new l("JWS Payload must be a string or an Uint8Array instance");
461
- let p = !1;
462
- typeof t == "function" && (t = await t(r, e), p = !0), ve(i, t, "verify");
463
- const y = ue(v.encode(e.protected ?? ""), v.encode("."), typeof e.payload == "string" ? v.encode(e.payload) : e.payload);
464
- let u;
461
+ let f = !1;
462
+ typeof t == "function" && (t = await t(r, e), f = !0), _e(i, t, "verify");
463
+ const w = ue(_.encode(e.protected ?? ""), _.encode("."), typeof e.payload == "string" ? _.encode(e.payload) : e.payload);
464
+ let h;
465
465
  try {
466
- u = P(e.signature);
466
+ h = C(e.signature);
467
467
  } catch {
468
468
  throw new l("Failed to base64url decode the signature");
469
469
  }
470
- if (!await Pe(i, t, u, y))
470
+ if (!await Ce(i, t, h, w))
471
471
  throw new he();
472
- let w;
472
+ let u;
473
473
  if (s)
474
474
  try {
475
- w = P(e.payload);
475
+ u = C(e.payload);
476
476
  } catch {
477
477
  throw new l("Failed to base64url decode the payload");
478
478
  }
479
479
  else
480
- typeof e.payload == "string" ? w = v.encode(e.payload) : w = e.payload;
481
- const h = { payload: w };
482
- return e.protected !== void 0 && (h.protectedHeader = r), e.header !== void 0 && (h.unprotectedHeader = e.header), p ? { ...h, key: t } : h;
480
+ typeof e.payload == "string" ? u = _.encode(e.payload) : u = e.payload;
481
+ const y = { payload: u };
482
+ return e.protected !== void 0 && (y.protectedHeader = r), e.header !== void 0 && (y.unprotectedHeader = e.header), f ? { ...y, key: t } : y;
483
483
  }
484
484
  async function Oe(e, t, o) {
485
485
  if (e instanceof Uint8Array && (e = T.decode(e)), typeof e != "string")
@@ -487,11 +487,11 @@ async function Oe(e, t, o) {
487
487
  const { 0: r, 1: n, 2: a, length: s } = e.split(".");
488
488
  if (s !== 3)
489
489
  throw new l("Invalid Compact JWS");
490
- const i = await Ce({ payload: n, protected: r, signature: a }, t, o), c = { payload: i.payload, protectedHeader: i.protectedHeader };
490
+ const i = await Pe({ payload: n, protected: r, signature: a }, t, o), c = { payload: i.payload, protectedHeader: i.protectedHeader };
491
491
  return typeof t == "function" ? { ...c, key: i.key } : c;
492
492
  }
493
- const De = (e) => Math.floor(e.getTime() / 1e3), Q = 60, Z = Q * 60, U = Z * 24, He = U * 7, Ue = U * 365.25, Ne = /^(\+|\-)? ?(\d+|\d+\.\d+) ?(seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)(?: (ago|from now))?$/i, L = (e) => {
494
- const t = Ne.exec(e);
493
+ const De = (e) => Math.floor(e.getTime() / 1e3), Z = 60, ee = Z * 60, J = ee * 24, He = J * 7, Ne = J * 365.25, Ue = /^(\+|\-)? ?(\d+|\d+\.\d+) ?(seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)(?: (ago|from now))?$/i, W = (e) => {
494
+ const t = Ue.exec(e);
495
495
  if (!t || t[4] && t[1])
496
496
  throw new TypeError("Invalid time period format");
497
497
  const o = parseFloat(t[2]), r = t[3].toLowerCase();
@@ -509,19 +509,19 @@ const De = (e) => Math.floor(e.getTime() / 1e3), Q = 60, Z = Q * 60, U = Z * 24,
509
509
  case "min":
510
510
  case "mins":
511
511
  case "m":
512
- n = Math.round(o * Q);
512
+ n = Math.round(o * Z);
513
513
  break;
514
514
  case "hour":
515
515
  case "hours":
516
516
  case "hr":
517
517
  case "hrs":
518
518
  case "h":
519
- n = Math.round(o * Z);
519
+ n = Math.round(o * ee);
520
520
  break;
521
521
  case "day":
522
522
  case "days":
523
523
  case "d":
524
- n = Math.round(o * U);
524
+ n = Math.round(o * J);
525
525
  break;
526
526
  case "week":
527
527
  case "weeks":
@@ -529,67 +529,67 @@ const De = (e) => Math.floor(e.getTime() / 1e3), Q = 60, Z = Q * 60, U = Z * 24,
529
529
  n = Math.round(o * He);
530
530
  break;
531
531
  default:
532
- n = Math.round(o * Ue);
532
+ n = Math.round(o * Ne);
533
533
  break;
534
534
  }
535
535
  return t[1] === "-" || t[4] === "ago" ? -n : n;
536
- }, W = (e) => e.toLowerCase().replace(/^application\//, ""), Je = (e, t) => typeof e == "string" ? t.includes(e) : Array.isArray(e) ? t.some(Set.prototype.has.bind(new Set(e))) : !1, $e = (e, t, o = {}) => {
536
+ }, x = (e) => e.toLowerCase().replace(/^application\//, ""), Je = (e, t) => typeof e == "string" ? t.includes(e) : Array.isArray(e) ? t.some(Set.prototype.has.bind(new Set(e))) : !1, $e = (e, t, o = {}) => {
537
537
  let r;
538
538
  try {
539
539
  r = JSON.parse(T.decode(t));
540
540
  } catch {
541
541
  }
542
- if (!D(r))
543
- throw new Y("JWT Claims Set must be a top-level JSON object");
542
+ if (!H(r))
543
+ throw new q("JWT Claims Set must be a top-level JSON object");
544
544
  const { typ: n } = o;
545
- if (n && (typeof e.typ != "string" || W(e.typ) !== W(n)))
546
- throw new f('unexpected "typ" JWT header value', r, "typ", "check_failed");
547
- const { requiredClaims: a = [], issuer: s, subject: i, audience: c, maxTokenAge: p } = o, y = [...a];
548
- p !== void 0 && y.push("iat"), c !== void 0 && y.push("aud"), i !== void 0 && y.push("sub"), s !== void 0 && y.push("iss");
549
- for (const S of new Set(y.reverse()))
550
- if (!(S in r))
551
- throw new f(`missing required "${S}" claim`, r, S, "missing");
545
+ if (n && (typeof e.typ != "string" || x(e.typ) !== x(n)))
546
+ throw new m('unexpected "typ" JWT header value', r, "typ", "check_failed");
547
+ const { requiredClaims: a = [], issuer: s, subject: i, audience: c, maxTokenAge: f } = o, w = [...a];
548
+ f !== void 0 && w.push("iat"), c !== void 0 && w.push("aud"), i !== void 0 && w.push("sub"), s !== void 0 && w.push("iss");
549
+ for (const p of new Set(w.reverse()))
550
+ if (!(p in r))
551
+ throw new m(`missing required "${p}" claim`, r, p, "missing");
552
552
  if (s && !(Array.isArray(s) ? s : [s]).includes(r.iss))
553
- throw new f('unexpected "iss" claim value', r, "iss", "check_failed");
553
+ throw new m('unexpected "iss" claim value', r, "iss", "check_failed");
554
554
  if (i && r.sub !== i)
555
- throw new f('unexpected "sub" claim value', r, "sub", "check_failed");
555
+ throw new m('unexpected "sub" claim value', r, "sub", "check_failed");
556
556
  if (c && !Je(r.aud, typeof c == "string" ? [c] : c))
557
- throw new f('unexpected "aud" claim value', r, "aud", "check_failed");
558
- let u;
557
+ throw new m('unexpected "aud" claim value', r, "aud", "check_failed");
558
+ let h;
559
559
  switch (typeof o.clockTolerance) {
560
560
  case "string":
561
- u = L(o.clockTolerance);
561
+ h = W(o.clockTolerance);
562
562
  break;
563
563
  case "number":
564
- u = o.clockTolerance;
564
+ h = o.clockTolerance;
565
565
  break;
566
566
  case "undefined":
567
- u = 0;
567
+ h = 0;
568
568
  break;
569
569
  default:
570
570
  throw new TypeError("Invalid clockTolerance option type");
571
571
  }
572
- const { currentDate: w } = o, h = De(w || /* @__PURE__ */ new Date());
573
- if ((r.iat !== void 0 || p) && typeof r.iat != "number")
574
- throw new f('"iat" claim must be a number', r, "iat", "invalid");
572
+ const { currentDate: u } = o, y = De(u || /* @__PURE__ */ new Date());
573
+ if ((r.iat !== void 0 || f) && typeof r.iat != "number")
574
+ throw new m('"iat" claim must be a number', r, "iat", "invalid");
575
575
  if (r.nbf !== void 0) {
576
576
  if (typeof r.nbf != "number")
577
- throw new f('"nbf" claim must be a number', r, "nbf", "invalid");
578
- if (r.nbf > h + u)
579
- throw new f('"nbf" claim timestamp check failed', r, "nbf", "check_failed");
577
+ throw new m('"nbf" claim must be a number', r, "nbf", "invalid");
578
+ if (r.nbf > y + h)
579
+ throw new m('"nbf" claim timestamp check failed', r, "nbf", "check_failed");
580
580
  }
581
581
  if (r.exp !== void 0) {
582
582
  if (typeof r.exp != "number")
583
- throw new f('"exp" claim must be a number', r, "exp", "invalid");
584
- if (r.exp <= h - u)
585
- throw new N('"exp" claim timestamp check failed', r, "exp", "check_failed");
583
+ throw new m('"exp" claim must be a number', r, "exp", "invalid");
584
+ if (r.exp <= y - h)
585
+ throw new $('"exp" claim timestamp check failed', r, "exp", "check_failed");
586
586
  }
587
- if (p) {
588
- const S = h - r.iat, oe = typeof p == "number" ? p : L(p);
589
- if (S - u > oe)
590
- throw new N('"iat" claim timestamp check failed (too far in the past)', r, "iat", "check_failed");
591
- if (S < 0 - u)
592
- throw new f('"iat" claim timestamp check failed (it should be in the past)', r, "iat", "check_failed");
587
+ if (f) {
588
+ const p = y - r.iat, oe = typeof f == "number" ? f : W(f);
589
+ if (p - h > oe)
590
+ throw new $('"iat" claim timestamp check failed (too far in the past)', r, "iat", "check_failed");
591
+ if (p < 0 - h)
592
+ throw new m('"iat" claim timestamp check failed (it should be in the past)', r, "iat", "check_failed");
593
593
  }
594
594
  return r;
595
595
  };
@@ -597,19 +597,20 @@ async function Le(e, t, o) {
597
597
  var r;
598
598
  const n = await Oe(e, t, o);
599
599
  if ((r = n.protectedHeader.crit) != null && r.includes("b64") && n.protectedHeader.b64 === !1)
600
- throw new Y("JWTs MUST NOT use unencoded payload");
600
+ throw new q("JWTs MUST NOT use unencoded payload");
601
601
  const a = { payload: $e(n.protectedHeader, n.payload, o), protectedHeader: n.protectedHeader };
602
602
  return typeof t == "function" ? { ...a, key: n.key } : a;
603
603
  }
604
- const We = {
604
+ const Ke = {
605
605
  ID_TOKEN: "id_token"
606
- }, xe = {
606
+ }, We = {
607
607
  CLIENT_ID: "X-Auth-ClientId"
608
- }, b = {
608
+ }, A = {
609
609
  ALG: "RS256",
610
610
  USER_ID_KEY: "_id",
611
+ TOKEN_ID_KEY: "__raw",
611
612
  ISSUER: "gizmette.com"
612
- }, Ke = `-----BEGIN PUBLIC KEY-----
613
+ }, xe = `-----BEGIN PUBLIC KEY-----
613
614
  MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAsF6i3Jd9fY/3COqCw/m7
614
615
  w5PKyTYLGAI2I6SIIdpe6i6DOCbEkmDz7LdVsBqwNtVi8gvWYIj+8ol6rU3qu1v5
615
616
  i1Jd45GSK4kzkVdgCmQZbM5ak0KI99q5wsrAIzUd+LRJ2HRvWtr5IYdsIiXaQjle
@@ -617,11 +618,11 @@ aMwPFOIcJH+rKfFgNcHLcaS5syp7zU1ANwZ+trgR+DifBr8TLVkBynmNeTyhDm2+
617
618
  l0haqjMk0UoNPPE8iYBWUHQJJE1Dqstj65d6Eh5g64Pao25y4cmYJbKjiblIGEkE
618
619
  sjqybA9mARAqh9k/eiIopecWSiffNQTwVQVd2I9ZH3BalhEXHlqFgrjz51kFqg81
619
620
  awIDAQAB
620
- -----END PUBLIC KEY-----`, ee = async (e, t) => {
621
+ -----END PUBLIC KEY-----`, N = async (e, t) => {
621
622
  try {
622
- const o = b.ALG, r = await Ae(Ke, o);
623
+ const o = A.ALG, r = await Ae(xe, o);
623
624
  return await Le(e, r, {
624
- issuer: b.ISSUER,
625
+ issuer: A.ISSUER,
625
626
  audience: t
626
627
  });
627
628
  } catch {
@@ -631,26 +632,26 @@ awIDAQAB
631
632
  function te(e, t) {
632
633
  window.dispatchEvent(new StorageEvent("storage", { key: e, newValue: t }));
633
634
  }
634
- const x = (e, t) => {
635
+ const j = (e, t) => {
635
636
  const o = JSON.stringify(
636
637
  typeof t == "function" ? t() : t
637
638
  );
638
639
  window.localStorage.setItem(e, o), te(e, o);
639
640
  }, je = (e) => {
640
641
  window.localStorage.removeItem(e), te(e, null);
641
- }, K = (e) => window.localStorage.getItem(e), Me = (e) => (window.addEventListener("storage", e), () => window.removeEventListener("storage", e));
642
+ }, M = (e) => window.localStorage.getItem(e), Me = (e) => (window.addEventListener("storage", e), () => window.removeEventListener("storage", e));
642
643
  function Ve({
643
644
  key: e,
644
645
  initialValue: t
645
646
  }) {
646
- const o = () => K(e), r = I.useSyncExternalStore(
647
+ const o = () => M(e), r = I.useSyncExternalStore(
647
648
  Me,
648
649
  o
649
650
  ), n = I.useCallback(
650
651
  (i) => {
651
652
  try {
652
653
  const c = typeof i == "function" ? i(JSON.parse(r)) : i;
653
- c == null ? je(e) : x(e, c);
654
+ c == null ? je(e) : j(e, c);
654
655
  } catch (c) {
655
656
  console.warn(c);
656
657
  }
@@ -663,20 +664,20 @@ function Ve({
663
664
  }, [n]);
664
665
  return I.useEffect(() => {
665
666
  try {
666
- K(e) === null && typeof t < "u" && x(e, t);
667
+ M(e) === null && typeof t < "u" && j(e, t);
667
668
  } catch (i) {
668
669
  console.warn(i);
669
670
  }
670
671
  }, [e, t]), [r ? JSON.parse(r) : null, n, a, s];
671
672
  }
672
- const j = "Oops! It looks like your session has expired. For your security, please log in again to continue.", Be = "Your session has been successfully terminated.", Fe = "You forgot to wrap your component in <AuthProvider>.", M = {
673
+ const V = "Oops! It looks like your session has expired. For your security, please log in again to continue.", Be = "Your session has been successfully terminated.", Fe = "You forgot to wrap your component in <AuthProvider>.", B = {
673
674
  dev: "https://auth.gizmette.local.com:3003",
674
675
  prod: "https://mylogin.gizmette.com"
675
- }, Ge = "@@auth@@";
676
+ }, Ye = "@@auth@@";
676
677
  var d = [];
677
678
  for (var O = 0; O < 256; ++O)
678
679
  d.push((O + 256).toString(16).slice(1));
679
- function Ye(e, t = 0) {
680
+ function Ge(e, t = 0) {
680
681
  return (d[e[t + 0]] + d[e[t + 1]] + d[e[t + 2]] + d[e[t + 3]] + "-" + d[e[t + 4]] + d[e[t + 5]] + "-" + d[e[t + 6]] + d[e[t + 7]] + "-" + d[e[t + 8]] + d[e[t + 9]] + "-" + d[e[t + 10]] + d[e[t + 11]] + d[e[t + 12]] + d[e[t + 13]] + d[e[t + 14]] + d[e[t + 15]]).toLowerCase();
681
682
  }
682
683
  var R, qe = new Uint8Array(16);
@@ -686,26 +687,26 @@ function ze() {
686
687
  return R(qe);
687
688
  }
688
689
  var Xe = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto);
689
- const V = {
690
+ const F = {
690
691
  randomUUID: Xe
691
692
  };
692
693
  function Qe(e, t, o) {
693
- if (V.randomUUID && !t && !e)
694
- return V.randomUUID();
694
+ if (F.randomUUID && !t && !e)
695
+ return F.randomUUID();
695
696
  e = e || {};
696
697
  var r = e.random || (e.rng || ze)();
697
- return r[6] = r[6] & 15 | 64, r[8] = r[8] & 63 | 128, Ye(r);
698
+ return r[6] = r[6] & 15 | 64, r[8] = r[8] & 63 | 128, Ge(r);
698
699
  }
699
700
  const Ze = process.env.NODE_ENV === "production", et = !Ze, tt = async ({ params: e = {} }) => {
700
701
  try {
701
702
  const t = Qe(), o = await fetch(
702
- et ? `${M.dev}/authenticate` : `${M.prod}/authenticate`,
703
+ et ? `${B.dev}/authenticate` : `${B.prod}/authenticate`,
703
704
  {
704
705
  credentials: "include",
705
706
  method: "POST",
706
707
  headers: {
707
708
  "Content-Type": "application/json",
708
- [xe.CLIENT_ID]: `${e.clientId}`
709
+ [We.CLIENT_ID]: `${e.clientId}`
709
710
  },
710
711
  body: JSON.stringify({ ...e, nonce: t })
711
712
  }
@@ -730,16 +731,16 @@ const Ze = process.env.NODE_ENV === "production", et = !Ze, tt = async ({ params
730
731
  try {
731
732
  const n = await tt({
732
733
  params: {
733
- type: We.ID_TOKEN,
734
+ type: Ke.ID_TOKEN,
734
735
  username: e,
735
736
  password: t,
736
737
  sessionExpiration: r,
737
738
  clientId: o
738
739
  }
739
- }), a = await ee(n.data.idToken, o);
740
- return a && a.payload[b.USER_ID_KEY] !== "" ? {
740
+ }), a = await N(n.data.idToken, o);
741
+ return a && a.payload[A.USER_ID_KEY] !== "" ? {
741
742
  idToken: n.data.idToken,
742
- userId: a.payload[b.USER_ID_KEY],
743
+ userId: a.payload[A.USER_ID_KEY],
743
744
  status: !0
744
745
  } : {
745
746
  status: !1
@@ -752,19 +753,17 @@ const Ze = process.env.NODE_ENV === "production", et = !Ze, tt = async ({ params
752
753
  };
753
754
  function ot(e) {
754
755
  const t = ae();
755
- return F(() => {
756
+ return Y(() => {
756
757
  t.current = e;
757
758
  }), t.current;
758
759
  }
759
- const B = () => {
760
+ const D = () => {
760
761
  throw new Error(Fe);
761
762
  }, re = se({
762
763
  isAuthenticated: !1,
763
- login: B,
764
- logout: B,
765
- accessToken: void 0,
766
- refreshToken: void 0,
767
- idToken: void 0,
764
+ login: D,
765
+ logout: D,
766
+ getIdTokenClaims: D,
768
767
  logoutReason: ""
769
768
  }), it = ({
770
769
  children: e,
@@ -772,53 +771,68 @@ const B = () => {
772
771
  clientId: o
773
772
  }) => {
774
773
  const [r, n, , a] = Ve({
775
- key: `${Ge}::${o}::@@user@@`
774
+ key: `${Ye}::${o}::@@user@@`
776
775
  }), [s, i] = ie({
777
776
  isAuthenticated: !!r,
778
777
  logoutReason: "",
779
778
  userId: ""
780
779
  }), c = ot(r) || "";
781
- F(() => {
780
+ Y(() => {
782
781
  c !== r && r !== null && (async () => {
783
782
  try {
784
- const u = await ee(r, o);
785
- u && u.payload[b.USER_ID_KEY] !== "" ? i({
783
+ const u = await N(r, o);
784
+ u && u.payload[A.USER_ID_KEY] !== "" ? i({
786
785
  isAuthenticated: !0,
787
786
  logoutReason: "",
788
- userId: u.payload[b.USER_ID_KEY]
787
+ userId: u.payload[A.USER_ID_KEY]
789
788
  }) : i({
790
789
  isAuthenticated: !1,
791
- logoutReason: j,
790
+ logoutReason: V,
792
791
  userId: ""
793
792
  });
794
793
  } catch {
795
794
  i({
796
795
  isAuthenticated: !1,
797
- logoutReason: j,
796
+ logoutReason: V,
798
797
  userId: ""
799
798
  });
800
799
  }
801
800
  })();
802
801
  }, [r, c, o]);
803
- const p = async (u, w) => {
804
- const h = await rt({
802
+ const f = async (u, y) => {
803
+ const p = await rt({
805
804
  username: u,
806
- password: w,
805
+ password: y,
807
806
  clientId: o,
808
807
  sessionExpiration: t
809
808
  });
810
- return h.status ? (n(h.idToken), i({
809
+ return p.status ? (n(p.idToken), i({
811
810
  isAuthenticated: !0,
812
- userId: h.userId
811
+ userId: p.userId
813
812
  }), !0) : !1;
814
- }, y = () => {
813
+ }, w = () => {
815
814
  i({
816
815
  isAuthenticated: !1,
817
816
  logoutReason: Be,
818
817
  userId: ""
819
818
  }), a();
819
+ }, h = async () => {
820
+ if (s.isAuthenticated)
821
+ try {
822
+ const u = await N(r, o);
823
+ return { ...u == null ? void 0 : u.payload, [A.TOKEN_ID_KEY]: r };
824
+ } catch {
825
+ return {};
826
+ }
827
+ return {};
820
828
  };
821
- return /* @__PURE__ */ ne(re.Provider, { value: { ...s, login: p, logout: y }, children: e });
829
+ return /* @__PURE__ */ ne(
830
+ re.Provider,
831
+ {
832
+ value: { ...s, login: f, logout: w, getIdTokenClaims: h },
833
+ children: e
834
+ }
835
+ );
822
836
  }, ct = (e = re) => ce(e);
823
837
  export {
824
838
  it as AuthProvider,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@versini/auth-provider",
3
- "version": "2.2.0",
3
+ "version": "2.3.0",
4
4
  "license": "MIT",
5
5
  "author": "Arno Versini",
6
6
  "publishConfig": {
@@ -44,10 +44,10 @@
44
44
  "react-dom": "18.3.1"
45
45
  },
46
46
  "dependencies": {
47
- "@versini/auth-common": "2.2.0",
47
+ "@versini/auth-common": "2.3.0",
48
48
  "@versini/ui-hooks": "4.0.0",
49
49
  "jose": "5.4.1",
50
50
  "uuid": "10.0.0"
51
51
  },
52
- "gitHead": "8ba8747f5ea5473bf63a348fef316ccff144f272"
52
+ "gitHead": "db5816d0e48518c40b0aa20ff564a88abf5bc426"
53
53
  }