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