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