@versini/auth-provider 3.0.0 → 3.1.0

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