@versini/auth-provider 4.1.0 → 4.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.js CHANGED
@@ -1,55 +1,81 @@
1
- import { jsx as pe } from "react/jsx-runtime";
2
- import * as I from "react";
3
- import { createContext as fe, useState as ye, useCallback as me, useEffect as we, useContext as Se } from "react";
1
+ import { jsx as Ue } from "react/jsx-runtime";
2
+ import * as D from "react";
3
+ import { createContext as Ne, useState as He, useCallback as Le, useEffect as $e, useContext as Ke } from "react";
4
4
  /*!
5
- @versini/auth-provider v4.1.0
5
+ @versini/auth-provider v4.3.0
6
6
  © 2024 gizmette.com
7
7
  */
8
8
  try {
9
9
  window.__VERSINI_AUTH_CLIENT__ || (window.__VERSINI_AUTH_CLIENT__ = {
10
- version: "4.1.0",
11
- buildTime: "06/26/2024 12:59 PM EDT",
10
+ version: "4.3.0",
11
+ buildTime: "06/28/2024 11:03 AM 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.6.0
18
+ @versini/auth-common v2.9.0
19
19
  © 2024 gizmette.com
20
20
  */
21
21
  try {
22
22
  window.__VERSINI_AUTH_COMMON__ || (window.__VERSINI_AUTH_COMMON__ = {
23
- version: "2.6.0",
24
- buildTime: "06/26/2024 12:59 PM EDT",
23
+ version: "2.9.0",
24
+ buildTime: "06/28/2024 11:03 AM EDT",
25
25
  homepage: "https://github.com/aversini/auth-client",
26
26
  license: "MIT"
27
27
  });
28
28
  } catch {
29
29
  }
30
- const x = crypto, Z = (e) => e instanceof CryptoKey, v = new TextEncoder(), C = new TextDecoder();
31
- function Ee(...e) {
30
+ const M = {
31
+ ID_TOKEN: "id_token",
32
+ ACCESS_TOKEN: "token",
33
+ ID_AND_ACCESS_TOKEN: "id_token token",
34
+ CODE: "code",
35
+ REFRESH_TOKEN: "refresh_token"
36
+ }, Je = {
37
+ CLIENT_ID: "X-Auth-ClientId"
38
+ }, f = {
39
+ ALG: "RS256",
40
+ USER_ID_KEY: "sub",
41
+ TOKEN_ID_KEY: "__raw",
42
+ NONCE_KEY: "_nonce",
43
+ ISSUER: "gizmette.com"
44
+ }, We = `-----BEGIN PUBLIC KEY-----
45
+ MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAsF6i3Jd9fY/3COqCw/m7
46
+ w5PKyTYLGAI2I6SIIdpe6i6DOCbEkmDz7LdVsBqwNtVi8gvWYIj+8ol6rU3qu1v5
47
+ i1Jd45GSK4kzkVdgCmQZbM5ak0KI99q5wsrAIzUd+LRJ2HRvWtr5IYdsIiXaQjle
48
+ aMwPFOIcJH+rKfFgNcHLcaS5syp7zU1ANwZ+trgR+DifBr8TLVkBynmNeTyhDm2+
49
+ l0haqjMk0UoNPPE8iYBWUHQJJE1Dqstj65d6Eh5g64Pao25y4cmYJbKjiblIGEkE
50
+ sjqybA9mARAqh9k/eiIopecWSiffNQTwVQVd2I9ZH3BalhEXHlqFgrjz51kFqg81
51
+ awIDAQAB
52
+ -----END PUBLIC KEY-----`, V = {
53
+ AUTHENTICATE: "authenticate",
54
+ CODE: "code",
55
+ LOGOUT: "logout"
56
+ }, te = crypto, Ee = (e) => e instanceof CryptoKey, L = new TextEncoder(), Y = new TextDecoder();
57
+ function xe(...e) {
32
58
  const t = e.reduce((a, { length: s }) => a + s, 0), o = new Uint8Array(t);
33
59
  let r = 0;
34
60
  for (const a of e)
35
61
  o.set(a, r), r += a.length;
36
62
  return o;
37
63
  }
38
- const ge = (e) => {
64
+ const je = (e) => {
39
65
  const t = atob(e), o = new Uint8Array(t.length);
40
66
  for (let r = 0; r < t.length; r++)
41
67
  o[r] = t.charCodeAt(r);
42
68
  return o;
43
- }, N = (e) => {
69
+ }, B = (e) => {
44
70
  let t = e;
45
- t instanceof Uint8Array && (t = C.decode(t)), t = t.replace(/-/g, "+").replace(/_/g, "/").replace(/\s/g, "");
71
+ t instanceof Uint8Array && (t = Y.decode(t)), t = t.replace(/-/g, "+").replace(/_/g, "/").replace(/\s/g, "");
46
72
  try {
47
- return ge(t);
73
+ return je(t);
48
74
  } catch {
49
75
  throw new TypeError("The input to be decoded is not correctly encoded.");
50
76
  }
51
77
  };
52
- let b = class extends Error {
78
+ class C extends Error {
53
79
  static get code() {
54
80
  return "ERR_JOSE_GENERIC";
55
81
  }
@@ -57,8 +83,8 @@ let b = class extends Error {
57
83
  var o;
58
84
  super(t), this.code = "ERR_JOSE_GENERIC", this.name = this.constructor.name, (o = Error.captureStackTrace) == null || o.call(Error, this, this.constructor);
59
85
  }
60
- };
61
- class S extends b {
86
+ }
87
+ class g extends C {
62
88
  static get code() {
63
89
  return "ERR_JWT_CLAIM_VALIDATION_FAILED";
64
90
  }
@@ -66,7 +92,7 @@ class S extends b {
66
92
  super(t), this.code = "ERR_JWT_CLAIM_VALIDATION_FAILED", this.claim = r, this.reason = a, this.payload = o;
67
93
  }
68
94
  }
69
- class V extends b {
95
+ class ae extends C {
70
96
  static get code() {
71
97
  return "ERR_JWT_EXPIRED";
72
98
  }
@@ -74,7 +100,7 @@ class V extends b {
74
100
  super(t), this.code = "ERR_JWT_EXPIRED", this.claim = r, this.reason = a, this.payload = o;
75
101
  }
76
102
  }
77
- class Ae extends b {
103
+ class Me extends C {
78
104
  constructor() {
79
105
  super(...arguments), this.code = "ERR_JOSE_ALG_NOT_ALLOWED";
80
106
  }
@@ -82,7 +108,7 @@ class Ae extends b {
82
108
  return "ERR_JOSE_ALG_NOT_ALLOWED";
83
109
  }
84
110
  }
85
- class P extends b {
111
+ class F extends C {
86
112
  constructor() {
87
113
  super(...arguments), this.code = "ERR_JOSE_NOT_SUPPORTED";
88
114
  }
@@ -90,7 +116,7 @@ class P extends b {
90
116
  return "ERR_JOSE_NOT_SUPPORTED";
91
117
  }
92
118
  }
93
- let d = class extends b {
119
+ let h = class extends C {
94
120
  constructor() {
95
121
  super(...arguments), this.code = "ERR_JWS_INVALID";
96
122
  }
@@ -98,7 +124,7 @@ let d = class extends b {
98
124
  return "ERR_JWS_INVALID";
99
125
  }
100
126
  };
101
- class ee extends b {
127
+ class Se extends C {
102
128
  constructor() {
103
129
  super(...arguments), this.code = "ERR_JWT_INVALID";
104
130
  }
@@ -106,7 +132,7 @@ class ee extends b {
106
132
  return "ERR_JWT_INVALID";
107
133
  }
108
134
  }
109
- class _e extends b {
135
+ class Ve extends C {
110
136
  constructor() {
111
137
  super(...arguments), this.code = "ERR_JWS_SIGNATURE_VERIFICATION_FAILED", this.message = "signature verification failed";
112
138
  }
@@ -114,16 +140,16 @@ class _e extends b {
114
140
  return "ERR_JWS_SIGNATURE_VERIFICATION_FAILED";
115
141
  }
116
142
  }
117
- function E(e, t = "algorithm.name") {
143
+ function _(e, t = "algorithm.name") {
118
144
  return new TypeError(`CryptoKey does not support this operation, its ${t} must be ${e}`);
119
145
  }
120
- function R(e, t) {
146
+ function $(e, t) {
121
147
  return e.name === t;
122
148
  }
123
- function D(e) {
149
+ function q(e) {
124
150
  return parseInt(e.name.slice(4), 10);
125
151
  }
126
- function be(e) {
152
+ function Ye(e) {
127
153
  switch (e) {
128
154
  case "ES256":
129
155
  return "P-256";
@@ -135,7 +161,7 @@ function be(e) {
135
161
  throw new Error("unreachable");
136
162
  }
137
163
  }
138
- function Ie(e, t) {
164
+ function Fe(e, t) {
139
165
  if (t.length && !t.some((o) => e.usages.includes(o))) {
140
166
  let o = "CryptoKey does not support this operation, its usages must include ";
141
167
  if (t.length > 2) {
@@ -146,59 +172,59 @@ function Ie(e, t) {
146
172
  throw new TypeError(o);
147
173
  }
148
174
  }
149
- function Te(e, t, ...o) {
175
+ function Ge(e, t, ...o) {
150
176
  switch (t) {
151
177
  case "HS256":
152
178
  case "HS384":
153
179
  case "HS512": {
154
- if (!R(e.algorithm, "HMAC"))
155
- throw E("HMAC");
180
+ if (!$(e.algorithm, "HMAC"))
181
+ throw _("HMAC");
156
182
  const r = parseInt(t.slice(2), 10);
157
- if (D(e.algorithm.hash) !== r)
158
- throw E(`SHA-${r}`, "algorithm.hash");
183
+ if (q(e.algorithm.hash) !== r)
184
+ throw _(`SHA-${r}`, "algorithm.hash");
159
185
  break;
160
186
  }
161
187
  case "RS256":
162
188
  case "RS384":
163
189
  case "RS512": {
164
- if (!R(e.algorithm, "RSASSA-PKCS1-v1_5"))
165
- throw E("RSASSA-PKCS1-v1_5");
190
+ if (!$(e.algorithm, "RSASSA-PKCS1-v1_5"))
191
+ throw _("RSASSA-PKCS1-v1_5");
166
192
  const r = parseInt(t.slice(2), 10);
167
- if (D(e.algorithm.hash) !== r)
168
- throw E(`SHA-${r}`, "algorithm.hash");
193
+ if (q(e.algorithm.hash) !== r)
194
+ throw _(`SHA-${r}`, "algorithm.hash");
169
195
  break;
170
196
  }
171
197
  case "PS256":
172
198
  case "PS384":
173
199
  case "PS512": {
174
- if (!R(e.algorithm, "RSA-PSS"))
175
- throw E("RSA-PSS");
200
+ if (!$(e.algorithm, "RSA-PSS"))
201
+ throw _("RSA-PSS");
176
202
  const r = parseInt(t.slice(2), 10);
177
- if (D(e.algorithm.hash) !== r)
178
- throw E(`SHA-${r}`, "algorithm.hash");
203
+ if (q(e.algorithm.hash) !== r)
204
+ throw _(`SHA-${r}`, "algorithm.hash");
179
205
  break;
180
206
  }
181
207
  case "EdDSA": {
182
208
  if (e.algorithm.name !== "Ed25519" && e.algorithm.name !== "Ed448")
183
- throw E("Ed25519 or Ed448");
209
+ throw _("Ed25519 or Ed448");
184
210
  break;
185
211
  }
186
212
  case "ES256":
187
213
  case "ES384":
188
214
  case "ES512": {
189
- if (!R(e.algorithm, "ECDSA"))
190
- throw E("ECDSA");
191
- const r = be(t);
215
+ if (!$(e.algorithm, "ECDSA"))
216
+ throw _("ECDSA");
217
+ const r = Ye(t);
192
218
  if (e.algorithm.namedCurve !== r)
193
- throw E(r, "algorithm.namedCurve");
219
+ throw _(r, "algorithm.namedCurve");
194
220
  break;
195
221
  }
196
222
  default:
197
223
  throw new TypeError("CryptoKey does not support this operation");
198
224
  }
199
- Ie(e, o);
225
+ Fe(e, o);
200
226
  }
201
- function te(e, t, ...o) {
227
+ function ge(e, t, ...o) {
202
228
  var r;
203
229
  if (o.length > 2) {
204
230
  const a = o.pop();
@@ -207,11 +233,11 @@ function te(e, t, ...o) {
207
233
  o.length === 2 ? e += `one of type ${o[0]} or ${o[1]}.` : e += `of type ${o[0]}.`;
208
234
  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
235
  }
210
- const Y = (e, ...t) => te("Key must be ", e, ...t);
211
- function re(e, t, ...o) {
212
- return te(`Key for the ${e} algorithm must be `, t, ...o);
236
+ const ne = (e, ...t) => ge("Key must be ", e, ...t);
237
+ function Ae(e, t, ...o) {
238
+ return ge(`Key for the ${e} algorithm must be `, t, ...o);
213
239
  }
214
- const oe = (e) => Z(e), A = ["CryptoKey"], ve = (...e) => {
240
+ const _e = (e) => Ee(e), I = ["CryptoKey"], Be = (...e) => {
215
241
  const t = e.filter(Boolean);
216
242
  if (t.length === 0 || t.length === 1)
217
243
  return !0;
@@ -230,11 +256,11 @@ const oe = (e) => Z(e), A = ["CryptoKey"], ve = (...e) => {
230
256
  }
231
257
  return !0;
232
258
  };
233
- function Re(e) {
259
+ function qe(e) {
234
260
  return typeof e == "object" && e !== null;
235
261
  }
236
- function W(e) {
237
- if (!Re(e) || Object.prototype.toString.call(e) !== "[object Object]")
262
+ function ee(e) {
263
+ if (!qe(e) || Object.prototype.toString.call(e) !== "[object Object]")
238
264
  return !1;
239
265
  if (Object.getPrototypeOf(e) === null)
240
266
  return !0;
@@ -243,39 +269,39 @@ function W(e) {
243
269
  t = Object.getPrototypeOf(t);
244
270
  return Object.getPrototypeOf(e) === t;
245
271
  }
246
- const ke = (e, t) => {
272
+ const ze = (e, t) => {
247
273
  if (e.startsWith("RS") || e.startsWith("PS")) {
248
274
  const { modulusLength: o } = t.algorithm;
249
275
  if (typeof o != "number" || o < 2048)
250
276
  throw new TypeError(`${e} requires key modulusLength to be 2048 bits or larger`);
251
277
  }
252
- }, g = (e, t, o = 0) => {
278
+ }, b = (e, t, o = 0) => {
253
279
  o === 0 && (t.unshift(t.length), t.unshift(6));
254
280
  const r = e.indexOf(t[0], o);
255
281
  if (r === -1)
256
282
  return !1;
257
283
  const a = e.subarray(r, r + t.length);
258
- return a.length !== t.length ? !1 : a.every((s, n) => s === t[n]) || g(e, t, r + 1);
259
- }, G = (e) => {
284
+ return a.length !== t.length ? !1 : a.every((s, n) => s === t[n]) || b(e, t, r + 1);
285
+ }, se = (e) => {
260
286
  switch (!0) {
261
- case g(e, [42, 134, 72, 206, 61, 3, 1, 7]):
287
+ case b(e, [42, 134, 72, 206, 61, 3, 1, 7]):
262
288
  return "P-256";
263
- case g(e, [43, 129, 4, 0, 34]):
289
+ case b(e, [43, 129, 4, 0, 34]):
264
290
  return "P-384";
265
- case g(e, [43, 129, 4, 0, 35]):
291
+ case b(e, [43, 129, 4, 0, 35]):
266
292
  return "P-521";
267
- case g(e, [43, 101, 110]):
293
+ case b(e, [43, 101, 110]):
268
294
  return "X25519";
269
- case g(e, [43, 101, 111]):
295
+ case b(e, [43, 101, 111]):
270
296
  return "X448";
271
- case g(e, [43, 101, 112]):
297
+ case b(e, [43, 101, 112]):
272
298
  return "Ed25519";
273
- case g(e, [43, 101, 113]):
299
+ case b(e, [43, 101, 113]):
274
300
  return "Ed448";
275
301
  default:
276
- throw new P("Invalid or unsupported EC Key Curve or OKP Key Sub Type");
302
+ throw new F("Invalid or unsupported EC Key Curve or OKP Key Sub Type");
277
303
  }
278
- }, Ce = async (e, t, o, r, a) => {
304
+ }, Xe = async (e, t, o, r, a) => {
279
305
  let s, n;
280
306
  const i = new Uint8Array(atob(o.replace(e, "")).split("").map((c) => c.charCodeAt(0)));
281
307
  switch (r) {
@@ -311,43 +337,43 @@ const ke = (e, t) => {
311
337
  case "ECDH-ES+A128KW":
312
338
  case "ECDH-ES+A192KW":
313
339
  case "ECDH-ES+A256KW": {
314
- const c = G(i);
340
+ const c = se(i);
315
341
  s = c.startsWith("P-") ? { name: "ECDH", namedCurve: c } : { name: c }, n = [];
316
342
  break;
317
343
  }
318
344
  case "EdDSA":
319
- s = { name: G(i) }, n = ["verify"];
345
+ s = { name: se(i) }, n = ["verify"];
320
346
  break;
321
347
  default:
322
- throw new P('Invalid or unsupported "alg" (Algorithm) value');
348
+ throw new F('Invalid or unsupported "alg" (Algorithm) value');
323
349
  }
324
- return x.subtle.importKey(t, i, s, !1, n);
325
- }, Pe = (e, t, o) => Ce(/(?:-----(?:BEGIN|END) PUBLIC KEY-----|\s)/g, "spki", e, t);
326
- async function Oe(e, t, o) {
350
+ return te.subtle.importKey(t, i, s, !1, n);
351
+ }, Qe = (e, t, o) => Xe(/(?:-----(?:BEGIN|END) PUBLIC KEY-----|\s)/g, "spki", e, t);
352
+ async function Ze(e, t, o) {
327
353
  if (e.indexOf("-----BEGIN PUBLIC KEY-----") !== 0)
328
354
  throw new TypeError('"spki" must be SPKI formatted string');
329
- return Pe(e, t);
355
+ return Qe(e, t);
330
356
  }
331
- const Ne = (e, t) => {
357
+ const et = (e, t) => {
332
358
  if (!(t instanceof Uint8Array)) {
333
- if (!oe(t))
334
- throw new TypeError(re(e, t, ...A, "Uint8Array"));
359
+ if (!_e(t))
360
+ throw new TypeError(Ae(e, t, ...I, "Uint8Array"));
335
361
  if (t.type !== "secret")
336
- throw new TypeError(`${A.join(" or ")} instances for symmetric algorithms must be of type "secret"`);
362
+ throw new TypeError(`${I.join(" or ")} instances for symmetric algorithms must be of type "secret"`);
337
363
  }
338
- }, De = (e, t, o) => {
339
- if (!oe(t))
340
- throw new TypeError(re(e, t, ...A));
364
+ }, tt = (e, t, o) => {
365
+ if (!_e(t))
366
+ throw new TypeError(Ae(e, t, ...I));
341
367
  if (t.type === "secret")
342
- throw new TypeError(`${A.join(" or ")} instances for asymmetric algorithms must not be of type "secret"`);
368
+ throw new TypeError(`${I.join(" or ")} instances for asymmetric algorithms must not be of type "secret"`);
343
369
  if (t.algorithm && o === "verify" && t.type === "private")
344
- throw new TypeError(`${A.join(" or ")} instances for asymmetric algorithm verifying must be of type "public"`);
370
+ throw new TypeError(`${I.join(" or ")} instances for asymmetric algorithm verifying must be of type "public"`);
345
371
  if (t.algorithm && o === "encrypt" && t.type === "private")
346
- throw new TypeError(`${A.join(" or ")} instances for asymmetric algorithm encryption must be of type "public"`);
347
- }, Ue = (e, t, o) => {
348
- e.startsWith("HS") || e === "dir" || e.startsWith("PBES2") || /^A\d{3}(?:GCM)?KW$/.test(e) ? Ne(e, t) : De(e, t, o);
372
+ throw new TypeError(`${I.join(" or ")} instances for asymmetric algorithm encryption must be of type "public"`);
373
+ }, rt = (e, t, o) => {
374
+ e.startsWith("HS") || e === "dir" || e.startsWith("PBES2") || /^A\d{3}(?:GCM)?KW$/.test(e) ? et(e, t) : tt(e, t, o);
349
375
  };
350
- function He(e, t, o, r, a) {
376
+ function ot(e, t, o, r, a) {
351
377
  if (a.crit !== void 0 && (r == null ? void 0 : r.crit) === void 0)
352
378
  throw new e('"crit" (Critical) Header Parameter MUST be integrity protected');
353
379
  if (!r || r.crit === void 0)
@@ -358,7 +384,7 @@ function He(e, t, o, r, a) {
358
384
  o !== void 0 ? s = new Map([...Object.entries(o), ...t.entries()]) : s = t;
359
385
  for (const n of r.crit) {
360
386
  if (!s.has(n))
361
- throw new P(`Extension Header Parameter "${n}" is not recognized`);
387
+ throw new F(`Extension Header Parameter "${n}" is not recognized`);
362
388
  if (a[n] === void 0)
363
389
  throw new e(`Extension Header Parameter "${n}" is missing`);
364
390
  if (s.get(n) && r[n] === void 0)
@@ -366,13 +392,13 @@ function He(e, t, o, r, a) {
366
392
  }
367
393
  return new Set(r.crit);
368
394
  }
369
- const Le = (e, t) => {
395
+ const at = (e, t) => {
370
396
  if (t !== void 0 && (!Array.isArray(t) || t.some((o) => typeof o != "string")))
371
397
  throw new TypeError(`"${e}" option must be an array of strings`);
372
398
  if (t)
373
399
  return new Set(t);
374
400
  };
375
- function $e(e, t) {
401
+ function nt(e, t) {
376
402
  const o = `SHA-${e.slice(-3)}`;
377
403
  switch (e) {
378
404
  case "HS256":
@@ -394,104 +420,104 @@ function $e(e, t) {
394
420
  case "EdDSA":
395
421
  return { name: t.name };
396
422
  default:
397
- throw new P(`alg ${e} is not supported either by JOSE or your javascript runtime`);
423
+ throw new F(`alg ${e} is not supported either by JOSE or your javascript runtime`);
398
424
  }
399
425
  }
400
- function Je(e, t, o) {
401
- if (Z(t))
402
- return Te(t, e, o), t;
426
+ function st(e, t, o) {
427
+ if (Ee(t))
428
+ return Ge(t, e, o), t;
403
429
  if (t instanceof Uint8Array) {
404
430
  if (!e.startsWith("HS"))
405
- throw new TypeError(Y(t, ...A));
406
- return x.subtle.importKey("raw", t, { hash: `SHA-${e.slice(-3)}`, name: "HMAC" }, !1, [o]);
431
+ throw new TypeError(ne(t, ...I));
432
+ return te.subtle.importKey("raw", t, { hash: `SHA-${e.slice(-3)}`, name: "HMAC" }, !1, [o]);
407
433
  }
408
- throw new TypeError(Y(t, ...A, "Uint8Array"));
434
+ throw new TypeError(ne(t, ...I, "Uint8Array"));
409
435
  }
410
- const Ke = async (e, t, o, r) => {
411
- const a = await Je(e, t, "verify");
412
- ke(e, a);
413
- const s = $e(e, a.algorithm);
436
+ const ct = async (e, t, o, r) => {
437
+ const a = await st(e, t, "verify");
438
+ ze(e, a);
439
+ const s = nt(e, a.algorithm);
414
440
  try {
415
- return await x.subtle.verify(s, a, o, r);
441
+ return await te.subtle.verify(s, a, o, r);
416
442
  } catch {
417
443
  return !1;
418
444
  }
419
445
  };
420
- async function We(e, t, o) {
421
- if (!W(e))
422
- throw new d("Flattened JWS must be an object");
446
+ async function it(e, t, o) {
447
+ if (!ee(e))
448
+ throw new h("Flattened JWS must be an object");
423
449
  if (e.protected === void 0 && e.header === void 0)
424
- throw new d('Flattened JWS must have either of the "protected" or "header" members');
450
+ throw new h('Flattened JWS must have either of the "protected" or "header" members');
425
451
  if (e.protected !== void 0 && typeof e.protected != "string")
426
- throw new d("JWS Protected Header incorrect type");
452
+ throw new h("JWS Protected Header incorrect type");
427
453
  if (e.payload === void 0)
428
- throw new d("JWS Payload missing");
454
+ throw new h("JWS Payload missing");
429
455
  if (typeof e.signature != "string")
430
- throw new d("JWS Signature missing or incorrect type");
431
- if (e.header !== void 0 && !W(e.header))
432
- throw new d("JWS Unprotected Header incorrect type");
456
+ throw new h("JWS Signature missing or incorrect type");
457
+ if (e.header !== void 0 && !ee(e.header))
458
+ throw new h("JWS Unprotected Header incorrect type");
433
459
  let r = {};
434
460
  if (e.protected)
435
461
  try {
436
- const w = N(e.protected);
437
- r = JSON.parse(C.decode(w));
462
+ const m = B(e.protected);
463
+ r = JSON.parse(Y.decode(m));
438
464
  } catch {
439
- throw new d("JWS Protected Header is invalid");
465
+ throw new h("JWS Protected Header is invalid");
440
466
  }
441
- if (!ve(r, e.header))
442
- throw new d("JWS Protected and JWS Unprotected Header Parameter names must be disjoint");
467
+ if (!Be(r, e.header))
468
+ throw new h("JWS Protected and JWS Unprotected Header Parameter names must be disjoint");
443
469
  const a = {
444
470
  ...r,
445
471
  ...e.header
446
- }, s = He(d, /* @__PURE__ */ new Map([["b64", !0]]), o == null ? void 0 : o.crit, r, a);
472
+ }, s = ot(h, /* @__PURE__ */ new Map([["b64", !0]]), o == null ? void 0 : o.crit, r, a);
447
473
  let n = !0;
448
474
  if (s.has("b64") && (n = r.b64, typeof n != "boolean"))
449
- throw new d('The "b64" (base64url-encode payload) Header Parameter must be a boolean');
475
+ throw new h('The "b64" (base64url-encode payload) Header Parameter must be a boolean');
450
476
  const { alg: i } = a;
451
477
  if (typeof i != "string" || !i)
452
- throw new d('JWS "alg" (Algorithm) Header Parameter missing or invalid');
453
- const c = o && Le("algorithms", o.algorithms);
478
+ throw new h('JWS "alg" (Algorithm) Header Parameter missing or invalid');
479
+ const c = o && at("algorithms", o.algorithms);
454
480
  if (c && !c.has(i))
455
- throw new Ae('"alg" (Algorithm) Header Parameter value not allowed');
481
+ throw new Me('"alg" (Algorithm) Header Parameter value not allowed');
456
482
  if (n) {
457
483
  if (typeof e.payload != "string")
458
- throw new d("JWS Payload must be a string");
484
+ throw new h("JWS Payload must be a string");
459
485
  } else if (typeof e.payload != "string" && !(e.payload instanceof Uint8Array))
460
- throw new d("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), Ue(i, t, "verify");
463
- const y = Ee(v.encode(e.protected ?? ""), v.encode("."), typeof e.payload == "string" ? v.encode(e.payload) : e.payload);
464
- let l;
486
+ throw new h("JWS Payload must be a string or an Uint8Array instance");
487
+ let u = !1;
488
+ typeof t == "function" && (t = await t(r, e), u = !0), rt(i, t, "verify");
489
+ const y = xe(L.encode(e.protected ?? ""), L.encode("."), typeof e.payload == "string" ? L.encode(e.payload) : e.payload);
490
+ let p;
465
491
  try {
466
- l = N(e.signature);
492
+ p = B(e.signature);
467
493
  } catch {
468
- throw new d("Failed to base64url decode the signature");
494
+ throw new h("Failed to base64url decode the signature");
469
495
  }
470
- if (!await Ke(i, t, l, y))
471
- throw new _e();
472
- let m;
496
+ if (!await ct(i, t, p, y))
497
+ throw new Ve();
498
+ let T;
473
499
  if (n)
474
500
  try {
475
- m = N(e.payload);
501
+ T = B(e.payload);
476
502
  } catch {
477
- throw new d("Failed to base64url decode the payload");
503
+ throw new h("Failed to base64url decode the payload");
478
504
  }
479
505
  else
480
- typeof e.payload == "string" ? m = v.encode(e.payload) : m = e.payload;
481
- const h = { payload: m };
482
- return e.protected !== void 0 && (h.protectedHeader = r), e.header !== void 0 && (h.unprotectedHeader = e.header), p ? { ...h, key: t } : h;
506
+ typeof e.payload == "string" ? T = L.encode(e.payload) : T = e.payload;
507
+ const E = { payload: T };
508
+ return e.protected !== void 0 && (E.protectedHeader = r), e.header !== void 0 && (E.unprotectedHeader = e.header), u ? { ...E, key: t } : E;
483
509
  }
484
- async function xe(e, t, o) {
485
- if (e instanceof Uint8Array && (e = C.decode(e)), typeof e != "string")
486
- throw new d("Compact JWS must be a string or Uint8Array");
510
+ async function ut(e, t, o) {
511
+ if (e instanceof Uint8Array && (e = Y.decode(e)), typeof e != "string")
512
+ throw new h("Compact JWS must be a string or Uint8Array");
487
513
  const { 0: r, 1: a, 2: s, length: n } = e.split(".");
488
514
  if (n !== 3)
489
- throw new d("Invalid Compact JWS");
490
- const i = await We({ payload: a, protected: r, signature: s }, t, o), c = { payload: i.payload, protectedHeader: i.protectedHeader };
515
+ throw new h("Invalid Compact JWS");
516
+ const i = await it({ payload: a, protected: r, signature: s }, t, o), c = { payload: i.payload, protectedHeader: i.protectedHeader };
491
517
  return typeof t == "function" ? { ...c, key: i.key } : c;
492
518
  }
493
- const je = (e) => Math.floor(e.getTime() / 1e3), ae = 60, ne = ae * 60, j = ne * 24, Me = j * 7, Ve = j * 365.25, Ye = /^(\+|\-)? ?(\d+|\d+\.\d+) ?(seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)(?: (ago|from now))?$/i, B = (e) => {
494
- const t = Ye.exec(e);
519
+ const dt = (e) => Math.floor(e.getTime() / 1e3), Te = 60, be = Te * 60, re = be * 24, lt = re * 7, ht = re * 365.25, pt = /^(\+|\-)? ?(\d+|\d+\.\d+) ?(seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)(?: (ago|from now))?$/i, ce = (e) => {
520
+ const t = pt.exec(e);
495
521
  if (!t || t[4] && t[1])
496
522
  throw new TypeError("Invalid time period format");
497
523
  const o = parseFloat(t[2]), r = t[3].toLowerCase();
@@ -509,237 +535,260 @@ const je = (e) => Math.floor(e.getTime() / 1e3), ae = 60, ne = ae * 60, j = ne *
509
535
  case "min":
510
536
  case "mins":
511
537
  case "m":
512
- a = Math.round(o * ae);
538
+ a = Math.round(o * Te);
513
539
  break;
514
540
  case "hour":
515
541
  case "hours":
516
542
  case "hr":
517
543
  case "hrs":
518
544
  case "h":
519
- a = Math.round(o * ne);
545
+ a = Math.round(o * be);
520
546
  break;
521
547
  case "day":
522
548
  case "days":
523
549
  case "d":
524
- a = Math.round(o * j);
550
+ a = Math.round(o * re);
525
551
  break;
526
552
  case "week":
527
553
  case "weeks":
528
554
  case "w":
529
- a = Math.round(o * Me);
555
+ a = Math.round(o * lt);
530
556
  break;
531
557
  default:
532
- a = Math.round(o * Ve);
558
+ a = Math.round(o * ht);
533
559
  break;
534
560
  }
535
561
  return t[1] === "-" || t[4] === "ago" ? -a : a;
536
- }, F = (e) => e.toLowerCase().replace(/^application\//, ""), Ge = (e, t) => typeof e == "string" ? t.includes(e) : Array.isArray(e) ? t.some(Set.prototype.has.bind(new Set(e))) : !1, Be = (e, t, o = {}) => {
562
+ }, ie = (e) => e.toLowerCase().replace(/^application\//, ""), ft = (e, t) => typeof e == "string" ? t.includes(e) : Array.isArray(e) ? t.some(Set.prototype.has.bind(new Set(e))) : !1, yt = (e, t, o = {}) => {
537
563
  let r;
538
564
  try {
539
- r = JSON.parse(C.decode(t));
565
+ r = JSON.parse(Y.decode(t));
540
566
  } catch {
541
567
  }
542
- if (!W(r))
543
- throw new ee("JWT Claims Set must be a top-level JSON object");
568
+ if (!ee(r))
569
+ throw new Se("JWT Claims Set must be a top-level JSON object");
544
570
  const { typ: a } = o;
545
- if (a && (typeof e.typ != "string" || F(e.typ) !== F(a)))
546
- throw new S('unexpected "typ" JWT header value', r, "typ", "check_failed");
547
- const { requiredClaims: s = [], issuer: n, subject: i, audience: c, maxTokenAge: p } = o, y = [...s];
548
- p !== void 0 && y.push("iat"), c !== void 0 && y.push("aud"), i !== void 0 && y.push("sub"), n !== void 0 && y.push("iss");
549
- for (const w of new Set(y.reverse()))
550
- if (!(w in r))
551
- throw new S(`missing required "${w}" claim`, r, w, "missing");
571
+ if (a && (typeof e.typ != "string" || ie(e.typ) !== ie(a)))
572
+ throw new g('unexpected "typ" JWT header value', r, "typ", "check_failed");
573
+ const { requiredClaims: s = [], issuer: n, subject: i, audience: c, maxTokenAge: u } = o, y = [...s];
574
+ u !== void 0 && y.push("iat"), c !== void 0 && y.push("aud"), i !== void 0 && y.push("sub"), n !== void 0 && y.push("iss");
575
+ for (const m of new Set(y.reverse()))
576
+ if (!(m in r))
577
+ throw new g(`missing required "${m}" claim`, r, m, "missing");
552
578
  if (n && !(Array.isArray(n) ? n : [n]).includes(r.iss))
553
- throw new S('unexpected "iss" claim value', r, "iss", "check_failed");
579
+ throw new g('unexpected "iss" claim value', r, "iss", "check_failed");
554
580
  if (i && r.sub !== i)
555
- throw new S('unexpected "sub" claim value', r, "sub", "check_failed");
556
- if (c && !Ge(r.aud, typeof c == "string" ? [c] : c))
557
- throw new S('unexpected "aud" claim value', r, "aud", "check_failed");
558
- let l;
581
+ throw new g('unexpected "sub" claim value', r, "sub", "check_failed");
582
+ if (c && !ft(r.aud, typeof c == "string" ? [c] : c))
583
+ throw new g('unexpected "aud" claim value', r, "aud", "check_failed");
584
+ let p;
559
585
  switch (typeof o.clockTolerance) {
560
586
  case "string":
561
- l = B(o.clockTolerance);
587
+ p = ce(o.clockTolerance);
562
588
  break;
563
589
  case "number":
564
- l = o.clockTolerance;
590
+ p = o.clockTolerance;
565
591
  break;
566
592
  case "undefined":
567
- l = 0;
593
+ p = 0;
568
594
  break;
569
595
  default:
570
596
  throw new TypeError("Invalid clockTolerance option type");
571
597
  }
572
- const { currentDate: m } = o, h = je(m || /* @__PURE__ */ new Date());
573
- if ((r.iat !== void 0 || p) && typeof r.iat != "number")
574
- throw new S('"iat" claim must be a number', r, "iat", "invalid");
598
+ const { currentDate: T } = o, E = dt(T || /* @__PURE__ */ new Date());
599
+ if ((r.iat !== void 0 || u) && typeof r.iat != "number")
600
+ throw new g('"iat" claim must be a number', r, "iat", "invalid");
575
601
  if (r.nbf !== void 0) {
576
602
  if (typeof r.nbf != "number")
577
- throw new S('"nbf" claim must be a number', r, "nbf", "invalid");
578
- if (r.nbf > h + l)
579
- throw new S('"nbf" claim timestamp check failed', r, "nbf", "check_failed");
603
+ throw new g('"nbf" claim must be a number', r, "nbf", "invalid");
604
+ if (r.nbf > E + p)
605
+ throw new g('"nbf" claim timestamp check failed', r, "nbf", "check_failed");
580
606
  }
581
607
  if (r.exp !== void 0) {
582
608
  if (typeof r.exp != "number")
583
- throw new S('"exp" claim must be a number', r, "exp", "invalid");
584
- if (r.exp <= h - l)
585
- throw new V('"exp" claim timestamp check failed', r, "exp", "check_failed");
609
+ throw new g('"exp" claim must be a number', r, "exp", "invalid");
610
+ if (r.exp <= E - p)
611
+ throw new ae('"exp" claim timestamp check failed', r, "exp", "check_failed");
586
612
  }
587
- if (p) {
588
- const w = h - r.iat, O = typeof p == "number" ? p : B(p);
589
- if (w - l > O)
590
- throw new V('"iat" claim timestamp check failed (too far in the past)', r, "iat", "check_failed");
591
- if (w < 0 - l)
592
- throw new S('"iat" claim timestamp check failed (it should be in the past)', r, "iat", "check_failed");
613
+ if (u) {
614
+ const m = E - r.iat, v = typeof u == "number" ? u : ce(u);
615
+ if (m - p > v)
616
+ throw new ae('"iat" claim timestamp check failed (too far in the past)', r, "iat", "check_failed");
617
+ if (m < 0 - p)
618
+ throw new g('"iat" claim timestamp check failed (it should be in the past)', r, "iat", "check_failed");
593
619
  }
594
620
  return r;
595
621
  };
596
- async function Fe(e, t, o) {
622
+ async function mt(e, t, o) {
597
623
  var r;
598
- const a = await xe(e, t, o);
624
+ const a = await ut(e, t, o);
599
625
  if ((r = a.protectedHeader.crit) != null && r.includes("b64") && a.protectedHeader.b64 === !1)
600
- throw new ee("JWTs MUST NOT use unencoded payload");
601
- const s = { payload: Be(a.protectedHeader, a.payload, o), protectedHeader: a.protectedHeader };
626
+ throw new Se("JWTs MUST NOT use unencoded payload");
627
+ const s = { payload: yt(a.protectedHeader, a.payload, o), protectedHeader: a.protectedHeader };
602
628
  return typeof t == "function" ? { ...s, key: a.key } : s;
603
629
  }
604
- const qe = {
605
- ID_TOKEN: "id_token",
606
- ACCESS_TOKEN: "token",
607
- ID_AND_ACCESS_TOKEN: "id_token token"
608
- }, ze = {
609
- CLIENT_ID: "X-Auth-ClientId"
610
- }, _ = {
611
- ALG: "RS256",
612
- USER_ID_KEY: "_id",
613
- TOKEN_ID_KEY: "__raw",
614
- NONCE_KEY: "_nonce",
615
- ISSUER: "gizmette.com"
616
- }, Xe = `-----BEGIN PUBLIC KEY-----
617
- MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAsF6i3Jd9fY/3COqCw/m7
618
- w5PKyTYLGAI2I6SIIdpe6i6DOCbEkmDz7LdVsBqwNtVi8gvWYIj+8ol6rU3qu1v5
619
- i1Jd45GSK4kzkVdgCmQZbM5ak0KI99q5wsrAIzUd+LRJ2HRvWtr5IYdsIiXaQjle
620
- aMwPFOIcJH+rKfFgNcHLcaS5syp7zU1ANwZ+trgR+DifBr8TLVkBynmNeTyhDm2+
621
- l0haqjMk0UoNPPE8iYBWUHQJJE1Dqstj65d6Eh5g64Pao25y4cmYJbKjiblIGEkE
622
- sjqybA9mARAqh9k/eiIopecWSiffNQTwVQVd2I9ZH3BalhEXHlqFgrjz51kFqg81
623
- awIDAQAB
624
- -----END PUBLIC KEY-----`, se = async (e, t) => {
630
+ const N = async (e) => {
625
631
  try {
626
- const o = _.ALG, r = await Oe(Xe, o);
627
- return await Fe(e, r, {
628
- issuer: _.ISSUER,
629
- audience: t
632
+ const t = f.ALG, o = await Ze(We, t);
633
+ return await mt(e, o, {
634
+ issuer: f.ISSUER
630
635
  });
631
636
  } catch {
632
637
  return;
633
638
  }
634
639
  };
635
- function ie(e, t) {
640
+ var d = [];
641
+ for (var z = 0; z < 256; ++z)
642
+ d.push((z + 256).toString(16).slice(1));
643
+ function wt(e, t = 0) {
644
+ 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();
645
+ }
646
+ var K, Et = new Uint8Array(16);
647
+ function St() {
648
+ if (!K && (K = typeof crypto < "u" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto), !K))
649
+ throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
650
+ return K(Et);
651
+ }
652
+ var gt = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto);
653
+ const ue = {
654
+ randomUUID: gt
655
+ };
656
+ function de(e, t, o) {
657
+ if (ue.randomUUID && !t && !e)
658
+ return ue.randomUUID();
659
+ e = e || {};
660
+ var r = e.random || (e.rng || St)();
661
+ return r[6] = r[6] & 15 | 64, r[8] = r[8] & 63 | 128, wt(r);
662
+ }
663
+ const le = globalThis.crypto, At = (e) => `${de()}${de()}`.slice(0, e), _t = (e) => btoa(
664
+ [...new Uint8Array(e)].map((t) => String.fromCharCode(t)).join("")
665
+ );
666
+ async function Tt(e) {
667
+ if (!le.subtle)
668
+ throw new Error(
669
+ "crypto.subtle is available only in secure contexts (HTTPS)."
670
+ );
671
+ const t = new TextEncoder().encode(e), o = await le.subtle.digest("SHA-256", t);
672
+ return _t(o).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
673
+ }
674
+ async function bt(e) {
675
+ const o = At(43), r = await Tt(o);
676
+ return {
677
+ code_verifier: o,
678
+ code_challenge: r
679
+ };
680
+ }
681
+ function Ie(e, t) {
636
682
  window.dispatchEvent(new StorageEvent("storage", { key: e, newValue: t }));
637
683
  }
638
- const q = (e, t) => {
684
+ const he = (e, t) => {
639
685
  const o = JSON.stringify(
640
686
  typeof t == "function" ? t() : t
641
687
  );
642
- window.localStorage.setItem(e, o), ie(e, o);
643
- }, Qe = (e) => {
644
- window.localStorage.removeItem(e), ie(e, null);
645
- }, z = (e) => window.localStorage.getItem(e), Ze = (e) => (window.addEventListener("storage", e), () => window.removeEventListener("storage", e));
646
- function U({
688
+ window.localStorage.setItem(e, o), Ie(e, o);
689
+ }, It = (e) => {
690
+ window.localStorage.removeItem(e), Ie(e, null);
691
+ }, pe = (e) => window.localStorage.getItem(e), vt = (e) => (window.addEventListener("storage", e), () => window.removeEventListener("storage", e));
692
+ function J({
647
693
  key: e,
648
694
  initialValue: t
649
695
  }) {
650
- const o = () => z(e), r = I.useSyncExternalStore(
651
- Ze,
696
+ const o = () => pe(e), r = D.useSyncExternalStore(
697
+ vt,
652
698
  o
653
- ), a = I.useCallback(
699
+ ), a = D.useCallback(
654
700
  (i) => {
655
701
  try {
656
702
  const c = typeof i == "function" ? i(JSON.parse(r)) : i;
657
- c == null ? Qe(e) : q(e, c);
703
+ c == null ? It(e) : he(e, c);
658
704
  } catch (c) {
659
705
  console.warn(c);
660
706
  }
661
707
  },
662
708
  [e, r]
663
- ), s = I.useCallback(() => {
709
+ ), s = D.useCallback(() => {
664
710
  a(t);
665
- }, [t, a]), n = I.useCallback(() => {
711
+ }, [t, a]), n = D.useCallback(() => {
666
712
  a(null);
667
713
  }, [a]);
668
- return I.useEffect(() => {
714
+ return D.useEffect(() => {
669
715
  try {
670
- z(e) === null && typeof t < "u" && q(e, t);
716
+ pe(e) === null && typeof t < "u" && he(e, t);
671
717
  } catch (i) {
672
718
  console.warn(i);
673
719
  }
674
720
  }, [e, t]), [r ? JSON.parse(r) : null, a, s, n];
675
721
  }
676
- var u = [];
677
- for (var H = 0; H < 256; ++H)
678
- u.push((H + 256).toString(16).slice(1));
679
- function et(e, t = 0) {
680
- return (u[e[t + 0]] + u[e[t + 1]] + u[e[t + 2]] + u[e[t + 3]] + "-" + u[e[t + 4]] + u[e[t + 5]] + "-" + u[e[t + 6]] + u[e[t + 7]] + "-" + u[e[t + 8]] + u[e[t + 9]] + "-" + u[e[t + 10]] + u[e[t + 11]] + u[e[t + 12]] + u[e[t + 13]] + u[e[t + 14]] + u[e[t + 15]]).toLowerCase();
722
+ var l = [];
723
+ for (var X = 0; X < 256; ++X)
724
+ l.push((X + 256).toString(16).slice(1));
725
+ function Rt(e, t = 0) {
726
+ return (l[e[t + 0]] + l[e[t + 1]] + l[e[t + 2]] + l[e[t + 3]] + "-" + l[e[t + 4]] + l[e[t + 5]] + "-" + l[e[t + 6]] + l[e[t + 7]] + "-" + l[e[t + 8]] + l[e[t + 9]] + "-" + l[e[t + 10]] + l[e[t + 11]] + l[e[t + 12]] + l[e[t + 13]] + l[e[t + 14]] + l[e[t + 15]]).toLowerCase();
681
727
  }
682
- var k, tt = new Uint8Array(16);
683
- function rt() {
684
- if (!k && (k = typeof crypto < "u" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto), !k))
728
+ var W, kt = new Uint8Array(16);
729
+ function Ct() {
730
+ if (!W && (W = typeof crypto < "u" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto), !W))
685
731
  throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
686
- return k(tt);
732
+ return W(kt);
687
733
  }
688
- var ot = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto);
689
- const X = {
690
- randomUUID: ot
734
+ var Ot = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto);
735
+ const fe = {
736
+ randomUUID: Ot
691
737
  };
692
- function at(e, t, o) {
693
- if (X.randomUUID && !t && !e)
694
- return X.randomUUID();
738
+ function Pt(e, t, o) {
739
+ if (fe.randomUUID && !t && !e)
740
+ return fe.randomUUID();
695
741
  e = e || {};
696
- var r = e.random || (e.rng || rt)();
697
- return r[6] = r[6] & 15 | 64, r[8] = r[8] & 63 | 128, et(r);
742
+ var r = e.random || (e.rng || Ct)();
743
+ return r[6] = r[6] & 15 | 64, r[8] = r[8] & 63 | 128, Rt(r);
698
744
  }
699
- const L = "Oops! It looks like your session has expired. For your security, please log in again to continue.", nt = "Your session has been successfully terminated.", st = "Login failed. Please try again.", it = "You forgot to wrap your component in <AuthProvider>.", Q = {
745
+ const Q = "Oops! It looks like your session has expired. For your security, please log in again to continue.", Dt = "Your session has been successfully terminated.", ye = "Login failed. Please try again.", U = "Error getting access token, please re-authenticate.", Ut = "You forgot to wrap your component in <AuthProvider>.", me = {
700
746
  dev: "https://auth.gizmette.local.com:3003",
701
747
  prod: "https://mylogin.gizmette.com"
702
- }, $ = "@@auth@@", ct = process.env.NODE_ENV === "production", ut = !ct, ce = {
703
- AUTHENTICATE: "authenticate",
704
- LOGOUT: "logout"
705
- }, ue = async ({ type: e, params: t = {} }) => {
748
+ }, x = "@@auth@@", Nt = process.env.NODE_ENV === "production", Ht = !Nt, G = async ({
749
+ type: e,
750
+ clientId: t,
751
+ params: o = {}
752
+ }) => {
706
753
  try {
707
- const o = await fetch(
708
- ut ? `${Q.dev}/${e}` : `${Q.prod}/${e}`,
754
+ const r = await fetch(
755
+ Ht ? `${me.dev}/${e}` : `${me.prod}/${e}`,
709
756
  {
710
757
  credentials: "include",
711
758
  method: "POST",
712
759
  headers: {
713
760
  "Content-Type": "application/json",
714
- [ze.CLIENT_ID]: `${t.clientId}`
761
+ [Je.CLIENT_ID]: `${t}`
715
762
  },
716
- body: JSON.stringify(t)
763
+ body: JSON.stringify(o)
717
764
  }
718
765
  );
719
- if (o.status !== 200)
720
- return { status: o.status, data: [] };
721
- const { data: r, errors: a } = await o.json();
766
+ if (r.status !== 200)
767
+ return { status: r.status, data: [] };
768
+ const { data: a, errors: s } = await r.json();
722
769
  return {
723
- status: o.status,
724
- data: r,
725
- errors: a
770
+ status: r.status,
771
+ data: a,
772
+ errors: s
726
773
  };
727
- } catch (o) {
728
- return console.error(o), { status: 500, data: [] };
774
+ } catch (r) {
775
+ return console.error(r), { status: 500, data: [] };
729
776
  }
730
- }, J = async ({
777
+ }, Z = async ({
731
778
  idToken: e,
732
779
  accessToken: t,
733
- clientId: o
780
+ refreshToken: o,
781
+ clientId: r
734
782
  }) => {
735
783
  try {
736
784
  return {
737
- status: (await ue({
738
- type: ce.LOGOUT,
785
+ status: (await G({
786
+ type: V.LOGOUT,
787
+ clientId: r,
739
788
  params: {
740
789
  idToken: e,
741
790
  accessToken: t,
742
- clientId: o
791
+ refreshToken: o
743
792
  }
744
793
  })).status === 200
745
794
  };
@@ -748,29 +797,93 @@ const L = "Oops! It looks like your session has expired. For your security, plea
748
797
  status: !1
749
798
  };
750
799
  }
751
- }, dt = async ({
800
+ }, we = async ({
752
801
  username: e,
753
802
  password: t,
754
803
  clientId: o,
755
804
  nonce: r,
756
- sessionExpiration: a
805
+ type: a,
806
+ sessionExpiration: s,
807
+ code: n,
808
+ code_verifier: i
757
809
  }) => {
758
810
  try {
759
- const s = await ue({
760
- type: ce.AUTHENTICATE,
811
+ const c = await G({
812
+ type: V.AUTHENTICATE,
813
+ clientId: o,
761
814
  params: {
762
- type: qe.ID_AND_ACCESS_TOKEN,
815
+ type: a || M.ID_AND_ACCESS_TOKEN,
763
816
  username: e,
764
817
  password: t,
765
- sessionExpiration: a,
766
- clientId: o,
767
- nonce: r
818
+ sessionExpiration: s,
819
+ nonce: r,
820
+ code: n,
821
+ code_verifier: i
768
822
  }
769
- }), n = await se(s.data.idToken, o);
770
- return n && n.payload[_.USER_ID_KEY] !== "" && n.payload[_.NONCE_KEY] === r ? {
771
- idToken: s.data.idToken,
823
+ }), u = await N(c.data.idToken);
824
+ return u && u.payload[f.USER_ID_KEY] !== "" && u.payload[f.NONCE_KEY] === r ? {
825
+ idToken: c.data.idToken,
826
+ accessToken: c.data.accessToken,
827
+ refreshToken: c.data.refreshToken,
828
+ userId: u.payload[f.USER_ID_KEY],
829
+ status: !0
830
+ } : {
831
+ status: !1
832
+ };
833
+ } catch {
834
+ return {
835
+ status: !1
836
+ };
837
+ }
838
+ }, Lt = async ({
839
+ nonce: e,
840
+ clientId: t,
841
+ code_challenge: o
842
+ }) => {
843
+ try {
844
+ const r = await G({
845
+ type: V.CODE,
846
+ clientId: t,
847
+ params: {
848
+ type: M.CODE,
849
+ nonce: e,
850
+ code_challenge: o
851
+ }
852
+ });
853
+ return r.data.code ? {
854
+ status: !0,
855
+ code: r.data.code
856
+ } : {
857
+ status: !1
858
+ };
859
+ } catch {
860
+ return {
861
+ status: !1
862
+ };
863
+ }
864
+ }, $t = async ({
865
+ clientId: e,
866
+ userId: t,
867
+ nonce: o,
868
+ refreshToken: r,
869
+ accessToken: a
870
+ }) => {
871
+ try {
872
+ const s = await G({
873
+ type: V.AUTHENTICATE,
874
+ clientId: e,
875
+ params: {
876
+ type: M.REFRESH_TOKEN,
877
+ userId: t,
878
+ nonce: o,
879
+ refreshToken: r,
880
+ accessToken: a
881
+ }
882
+ }), n = await N(s.data.accessToken);
883
+ return n && n.payload[f.USER_ID_KEY] !== "" && n.payload[f.NONCE_KEY] === o ? {
772
884
  accessToken: s.data.accessToken,
773
- userId: n.payload[_.USER_ID_KEY],
885
+ refreshToken: s.data.refreshToken,
886
+ userId: n.payload[f.USER_ID_KEY],
774
887
  status: !0
775
888
  } : {
776
889
  status: !1
@@ -780,112 +893,166 @@ const L = "Oops! It looks like your session has expired. For your security, plea
780
893
  status: !1
781
894
  };
782
895
  }
783
- }, K = () => {
784
- throw new Error(it);
785
- }, de = fe({
896
+ }, j = () => {
897
+ throw new Error(Ut);
898
+ }, ve = Ne({
786
899
  isAuthenticated: !1,
787
900
  isLoading: !1,
788
- login: K,
789
- logout: K,
790
- getAccessToken: K,
791
- logoutReason: "",
792
- idTokenClaims: null
793
- }), yt = ({
901
+ login: j,
902
+ logout: j,
903
+ getAccessToken: j,
904
+ getIdToken: j,
905
+ logoutReason: ""
906
+ }), xt = ({
794
907
  children: e,
795
908
  sessionExpiration: t,
796
909
  clientId: o
797
910
  }) => {
798
- const [r, a, , s] = U({
799
- key: `${$}::${o}::@@user@@`
800
- }), [n, i, , c] = U({
801
- key: `${$}::${o}::@@access@@`
802
- }), [, p, , y] = U({
803
- key: `${$}::${o}::@@nonce@@`
804
- }), [l, m] = ye({
911
+ const [r, a, , s] = J({
912
+ key: `${x}::${o}::@@user@@`
913
+ }), [n, i, , c] = J({
914
+ key: `${x}::${o}::@@access@@`
915
+ }), [u, y, , p] = J(
916
+ {
917
+ key: `${x}::${o}::@@refresh@@`
918
+ }
919
+ ), [T, E, , m] = J({
920
+ key: `${x}::${o}::@@nonce@@`
921
+ }), [v, H] = He({
805
922
  isLoading: !0,
806
923
  isAuthenticated: !1,
807
- logoutReason: "",
808
924
  userId: "",
809
- idTokenClaims: null
810
- }), h = me(
811
- (f) => {
812
- m({
925
+ logoutReason: ""
926
+ }), A = Le(
927
+ (w) => {
928
+ H({
813
929
  isLoading: !1,
814
930
  isAuthenticated: !1,
815
- logoutReason: f || L,
816
931
  userId: "",
817
- idTokenClaims: null
818
- }), s(), c(), y();
932
+ logoutReason: w || Q
933
+ }), s(), c(), p(), m();
819
934
  },
820
- [s, c, y]
935
+ [s, c, m, p]
821
936
  );
822
- we(() => {
823
- l.isLoading && r !== null && (async () => {
937
+ $e(() => {
938
+ v.isLoading && r !== null && (async () => {
824
939
  try {
825
- const f = await se(r, o);
826
- f && f.payload[_.USER_ID_KEY] !== "" ? m({
940
+ const w = await N(r);
941
+ w && w.payload[f.USER_ID_KEY] !== "" ? H({
827
942
  isLoading: !1,
828
943
  isAuthenticated: !0,
829
- logoutReason: "",
830
- userId: f.payload[_.USER_ID_KEY],
831
- idTokenClaims: {
832
- ...f == null ? void 0 : f.payload,
833
- [_.TOKEN_ID_KEY]: r
834
- }
835
- }) : (h(L), await J({
944
+ userId: w.payload[f.USER_ID_KEY],
945
+ logoutReason: ""
946
+ }) : (A(Q), await Z({
836
947
  idToken: r,
837
948
  accessToken: n,
949
+ refreshToken: u,
838
950
  clientId: o
839
951
  }));
840
952
  } catch {
841
- h(L), await J({
953
+ A(Q), await Z({
842
954
  idToken: r,
843
955
  accessToken: n,
956
+ refreshToken: u,
844
957
  clientId: o
845
958
  });
846
959
  }
847
960
  })();
848
961
  }, [
849
- l.isLoading,
962
+ v.isLoading,
850
963
  n,
851
964
  r,
965
+ u,
852
966
  o,
853
- h
967
+ A
854
968
  ]);
855
- const w = async (f, he) => {
856
- const M = at();
857
- p(M);
858
- const T = await dt({
859
- username: f,
860
- password: he,
969
+ const Re = async (w, O, R) => {
970
+ const k = Pt();
971
+ if (E(k), R === M.CODE) {
972
+ const { code_verifier: Pe, code_challenge: De } = await bt(), oe = await Lt({
973
+ nonce: k,
974
+ clientId: o,
975
+ code_challenge: De
976
+ });
977
+ if (oe.status) {
978
+ const P = await we({
979
+ username: w,
980
+ password: O,
981
+ clientId: o,
982
+ sessionExpiration: t,
983
+ nonce: k,
984
+ type: R,
985
+ code: oe.code,
986
+ code_verifier: Pe
987
+ });
988
+ return P.status ? (a(P.idToken), i(P.accessToken), y(P.refreshToken), H({
989
+ isLoading: !1,
990
+ isAuthenticated: !0,
991
+ userId: P.userId,
992
+ logoutReason: ""
993
+ }), !0) : (A(ye), !1);
994
+ }
995
+ return !1;
996
+ }
997
+ const S = await we({
998
+ username: w,
999
+ password: O,
861
1000
  clientId: o,
862
1001
  sessionExpiration: t,
863
- nonce: M
1002
+ nonce: k,
1003
+ type: R
864
1004
  });
865
- return T.status ? (a(T.idToken), i(T.accessToken), m({
1005
+ return S.status ? (a(S.idToken), i(S.accessToken), y(S.refreshToken), H({
866
1006
  isLoading: !1,
867
1007
  isAuthenticated: !0,
868
- userId: T.userId
869
- }), !0) : (h(st), !1);
870
- }, O = async () => {
871
- h(nt), await J({
1008
+ userId: S.userId
1009
+ }), !0) : (A(ye), !1);
1010
+ }, ke = async () => {
1011
+ A(Dt), await Z({
872
1012
  idToken: r,
873
1013
  accessToken: n,
1014
+ refreshToken: u,
874
1015
  clientId: o
875
1016
  });
876
- }, le = () => {
877
- if (l.isAuthenticated && n)
878
- return n;
1017
+ }, Ce = async () => {
1018
+ const { isAuthenticated: w, userId: O } = v;
1019
+ try {
1020
+ if (w && O && n) {
1021
+ const R = await N(n);
1022
+ if (R && R.payload[f.USER_ID_KEY] !== "")
1023
+ return n;
1024
+ const k = await N(u);
1025
+ if (k && k.payload[f.USER_ID_KEY] !== "") {
1026
+ const S = await $t({
1027
+ clientId: o,
1028
+ userId: O,
1029
+ nonce: T,
1030
+ refreshToken: u,
1031
+ accessToken: n
1032
+ });
1033
+ if (S.status)
1034
+ return i(S.accessToken), y(S.refreshToken), S.accessToken;
1035
+ A(U);
1036
+ }
1037
+ return A(U), console.error(U), "";
1038
+ }
1039
+ } catch {
1040
+ return A(U), console.error(U), "";
1041
+ }
1042
+ }, Oe = () => {
1043
+ if (v.isAuthenticated && r)
1044
+ return r;
879
1045
  };
880
- return /* @__PURE__ */ pe(
881
- de.Provider,
1046
+ return /* @__PURE__ */ Ue(
1047
+ ve.Provider,
882
1048
  {
883
- value: { ...l, login: w, logout: O, getAccessToken: le },
1049
+ value: { ...v, login: Re, logout: ke, getAccessToken: Ce, getIdToken: Oe },
884
1050
  children: e
885
1051
  }
886
1052
  );
887
- }, mt = (e = de) => Se(e);
1053
+ }, jt = (e = ve) => Ke(e);
888
1054
  export {
889
- yt as AuthProvider,
890
- mt as useAuth
1055
+ M as AUTH_TYPES,
1056
+ xt as AuthProvider,
1057
+ jt as useAuth
891
1058
  };