@versini/auth-provider 4.0.0 → 4.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.js +289 -250
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { jsx as
|
|
1
|
+
import { jsx as pe } from "react/jsx-runtime";
|
|
2
2
|
import * as I from "react";
|
|
3
|
-
import {
|
|
3
|
+
import { createContext as fe, useState as ye, useCallback as me, useEffect as we, useContext as Se } from "react";
|
|
4
4
|
/*!
|
|
5
|
-
@versini/auth-provider v4.
|
|
5
|
+
@versini/auth-provider v4.1.0
|
|
6
6
|
© 2024 gizmette.com
|
|
7
7
|
*/
|
|
8
8
|
try {
|
|
9
9
|
window.__VERSINI_AUTH_CLIENT__ || (window.__VERSINI_AUTH_CLIENT__ = {
|
|
10
|
-
version: "4.
|
|
11
|
-
buildTime: "06/26/2024
|
|
10
|
+
version: "4.1.0",
|
|
11
|
+
buildTime: "06/26/2024 12:59 PM EDT",
|
|
12
12
|
homepage: "https://github.com/aversini/auth-client",
|
|
13
13
|
license: "MIT"
|
|
14
14
|
});
|
|
@@ -21,21 +21,21 @@ try {
|
|
|
21
21
|
try {
|
|
22
22
|
window.__VERSINI_AUTH_COMMON__ || (window.__VERSINI_AUTH_COMMON__ = {
|
|
23
23
|
version: "2.6.0",
|
|
24
|
-
buildTime: "06/26/2024
|
|
24
|
+
buildTime: "06/26/2024 12:59 PM EDT",
|
|
25
25
|
homepage: "https://github.com/aversini/auth-client",
|
|
26
26
|
license: "MIT"
|
|
27
27
|
});
|
|
28
28
|
} catch {
|
|
29
29
|
}
|
|
30
|
-
const
|
|
31
|
-
function
|
|
32
|
-
const t = e.reduce((
|
|
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);
|
|
33
33
|
let r = 0;
|
|
34
|
-
for (const
|
|
35
|
-
o.set(
|
|
34
|
+
for (const a of e)
|
|
35
|
+
o.set(a, r), r += a.length;
|
|
36
36
|
return o;
|
|
37
37
|
}
|
|
38
|
-
const
|
|
38
|
+
const ge = (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);
|
|
@@ -44,7 +44,7 @@ const Ee = (e) => {
|
|
|
44
44
|
let t = e;
|
|
45
45
|
t instanceof Uint8Array && (t = C.decode(t)), t = t.replace(/-/g, "+").replace(/_/g, "/").replace(/\s/g, "");
|
|
46
46
|
try {
|
|
47
|
-
return
|
|
47
|
+
return ge(t);
|
|
48
48
|
} catch {
|
|
49
49
|
throw new TypeError("The input to be decoded is not correctly encoded.");
|
|
50
50
|
}
|
|
@@ -62,19 +62,19 @@ class S extends b {
|
|
|
62
62
|
static get code() {
|
|
63
63
|
return "ERR_JWT_CLAIM_VALIDATION_FAILED";
|
|
64
64
|
}
|
|
65
|
-
constructor(t, o, r = "unspecified",
|
|
66
|
-
super(t), this.code = "ERR_JWT_CLAIM_VALIDATION_FAILED", this.claim = r, this.reason =
|
|
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;
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
|
-
class
|
|
69
|
+
class V extends b {
|
|
70
70
|
static get code() {
|
|
71
71
|
return "ERR_JWT_EXPIRED";
|
|
72
72
|
}
|
|
73
|
-
constructor(t, o, r = "unspecified",
|
|
74
|
-
super(t), this.code = "ERR_JWT_EXPIRED", this.claim = r, this.reason =
|
|
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;
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
|
-
class
|
|
77
|
+
class Ae extends b {
|
|
78
78
|
constructor() {
|
|
79
79
|
super(...arguments), this.code = "ERR_JOSE_ALG_NOT_ALLOWED";
|
|
80
80
|
}
|
|
@@ -106,7 +106,7 @@ class ee extends b {
|
|
|
106
106
|
return "ERR_JWT_INVALID";
|
|
107
107
|
}
|
|
108
108
|
}
|
|
109
|
-
class
|
|
109
|
+
class _e extends b {
|
|
110
110
|
constructor() {
|
|
111
111
|
super(...arguments), this.code = "ERR_JWS_SIGNATURE_VERIFICATION_FAILED", this.message = "signature verification failed";
|
|
112
112
|
}
|
|
@@ -123,7 +123,7 @@ function R(e, t) {
|
|
|
123
123
|
function D(e) {
|
|
124
124
|
return parseInt(e.name.slice(4), 10);
|
|
125
125
|
}
|
|
126
|
-
function
|
|
126
|
+
function be(e) {
|
|
127
127
|
switch (e) {
|
|
128
128
|
case "ES256":
|
|
129
129
|
return "P-256";
|
|
@@ -135,7 +135,7 @@ function _e(e) {
|
|
|
135
135
|
throw new Error("unreachable");
|
|
136
136
|
}
|
|
137
137
|
}
|
|
138
|
-
function
|
|
138
|
+
function Ie(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,7 +146,7 @@ function be(e, t) {
|
|
|
146
146
|
throw new TypeError(o);
|
|
147
147
|
}
|
|
148
148
|
}
|
|
149
|
-
function
|
|
149
|
+
function Te(e, t, ...o) {
|
|
150
150
|
switch (t) {
|
|
151
151
|
case "HS256":
|
|
152
152
|
case "HS384":
|
|
@@ -188,7 +188,7 @@ function Ie(e, t, ...o) {
|
|
|
188
188
|
case "ES512": {
|
|
189
189
|
if (!R(e.algorithm, "ECDSA"))
|
|
190
190
|
throw E("ECDSA");
|
|
191
|
-
const r =
|
|
191
|
+
const r = be(t);
|
|
192
192
|
if (e.algorithm.namedCurve !== r)
|
|
193
193
|
throw E(r, "algorithm.namedCurve");
|
|
194
194
|
break;
|
|
@@ -196,18 +196,18 @@ function Ie(e, t, ...o) {
|
|
|
196
196
|
default:
|
|
197
197
|
throw new TypeError("CryptoKey does not support this operation");
|
|
198
198
|
}
|
|
199
|
-
|
|
199
|
+
Ie(e, o);
|
|
200
200
|
}
|
|
201
201
|
function te(e, t, ...o) {
|
|
202
202
|
var r;
|
|
203
203
|
if (o.length > 2) {
|
|
204
|
-
const
|
|
205
|
-
e += `one of type ${o.join(", ")}, or ${
|
|
204
|
+
const a = o.pop();
|
|
205
|
+
e += `one of type ${o.join(", ")}, or ${a}.`;
|
|
206
206
|
} else
|
|
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
|
|
210
|
+
const Y = (e, ...t) => te("Key must be ", e, ...t);
|
|
211
211
|
function re(e, t, ...o) {
|
|
212
212
|
return te(`Key for the ${e} algorithm must be `, t, ...o);
|
|
213
213
|
}
|
|
@@ -217,12 +217,12 @@ const oe = (e) => Z(e), A = ["CryptoKey"], ve = (...e) => {
|
|
|
217
217
|
return !0;
|
|
218
218
|
let o;
|
|
219
219
|
for (const r of t) {
|
|
220
|
-
const
|
|
220
|
+
const a = Object.keys(r);
|
|
221
221
|
if (!o || o.size === 0) {
|
|
222
|
-
o = new Set(
|
|
222
|
+
o = new Set(a);
|
|
223
223
|
continue;
|
|
224
224
|
}
|
|
225
|
-
for (const s of
|
|
225
|
+
for (const s of a) {
|
|
226
226
|
if (o.has(s))
|
|
227
227
|
return !1;
|
|
228
228
|
o.add(s);
|
|
@@ -230,11 +230,11 @@ const oe = (e) => Z(e), A = ["CryptoKey"], ve = (...e) => {
|
|
|
230
230
|
}
|
|
231
231
|
return !0;
|
|
232
232
|
};
|
|
233
|
-
function
|
|
233
|
+
function Re(e) {
|
|
234
234
|
return typeof e == "object" && e !== null;
|
|
235
235
|
}
|
|
236
|
-
function
|
|
237
|
-
if (!
|
|
236
|
+
function W(e) {
|
|
237
|
+
if (!Re(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 K(e) {
|
|
|
243
243
|
t = Object.getPrototypeOf(t);
|
|
244
244
|
return Object.getPrototypeOf(e) === t;
|
|
245
245
|
}
|
|
246
|
-
const
|
|
246
|
+
const ke = (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)
|
|
@@ -254,9 +254,9 @@ const Re = (e, t) => {
|
|
|
254
254
|
const r = e.indexOf(t[0], o);
|
|
255
255
|
if (r === -1)
|
|
256
256
|
return !1;
|
|
257
|
-
const
|
|
258
|
-
return
|
|
259
|
-
},
|
|
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) => {
|
|
260
260
|
switch (!0) {
|
|
261
261
|
case g(e, [42, 134, 72, 206, 61, 3, 1, 7]):
|
|
262
262
|
return "P-256";
|
|
@@ -275,19 +275,19 @@ const Re = (e, t) => {
|
|
|
275
275
|
default:
|
|
276
276
|
throw new P("Invalid or unsupported EC Key Curve or OKP Key Sub Type");
|
|
277
277
|
}
|
|
278
|
-
},
|
|
279
|
-
let s,
|
|
278
|
+
}, Ce = async (e, t, o, r, a) => {
|
|
279
|
+
let s, n;
|
|
280
280
|
const i = new Uint8Array(atob(o.replace(e, "")).split("").map((c) => c.charCodeAt(0)));
|
|
281
281
|
switch (r) {
|
|
282
282
|
case "PS256":
|
|
283
283
|
case "PS384":
|
|
284
284
|
case "PS512":
|
|
285
|
-
s = { name: "RSA-PSS", hash: `SHA-${r.slice(-3)}` },
|
|
285
|
+
s = { name: "RSA-PSS", hash: `SHA-${r.slice(-3)}` }, n = ["verify"];
|
|
286
286
|
break;
|
|
287
287
|
case "RS256":
|
|
288
288
|
case "RS384":
|
|
289
289
|
case "RS512":
|
|
290
|
-
s = { name: "RSASSA-PKCS1-v1_5", hash: `SHA-${r.slice(-3)}` },
|
|
290
|
+
s = { name: "RSASSA-PKCS1-v1_5", hash: `SHA-${r.slice(-3)}` }, n = ["verify"];
|
|
291
291
|
break;
|
|
292
292
|
case "RSA-OAEP":
|
|
293
293
|
case "RSA-OAEP-256":
|
|
@@ -296,46 +296,46 @@ const Re = (e, t) => {
|
|
|
296
296
|
s = {
|
|
297
297
|
name: "RSA-OAEP",
|
|
298
298
|
hash: `SHA-${parseInt(r.slice(-3), 10) || 1}`
|
|
299
|
-
},
|
|
299
|
+
}, n = ["encrypt", "wrapKey"];
|
|
300
300
|
break;
|
|
301
301
|
case "ES256":
|
|
302
|
-
s = { name: "ECDSA", namedCurve: "P-256" },
|
|
302
|
+
s = { name: "ECDSA", namedCurve: "P-256" }, n = ["verify"];
|
|
303
303
|
break;
|
|
304
304
|
case "ES384":
|
|
305
|
-
s = { name: "ECDSA", namedCurve: "P-384" },
|
|
305
|
+
s = { name: "ECDSA", namedCurve: "P-384" }, n = ["verify"];
|
|
306
306
|
break;
|
|
307
307
|
case "ES512":
|
|
308
|
-
s = { name: "ECDSA", namedCurve: "P-521" },
|
|
308
|
+
s = { name: "ECDSA", namedCurve: "P-521" }, n = ["verify"];
|
|
309
309
|
break;
|
|
310
310
|
case "ECDH-ES":
|
|
311
311
|
case "ECDH-ES+A128KW":
|
|
312
312
|
case "ECDH-ES+A192KW":
|
|
313
313
|
case "ECDH-ES+A256KW": {
|
|
314
|
-
const c =
|
|
315
|
-
s = c.startsWith("P-") ? { name: "ECDH", namedCurve: c } : { name: c },
|
|
314
|
+
const c = G(i);
|
|
315
|
+
s = c.startsWith("P-") ? { name: "ECDH", namedCurve: c } : { name: c }, n = [];
|
|
316
316
|
break;
|
|
317
317
|
}
|
|
318
318
|
case "EdDSA":
|
|
319
|
-
s = { name:
|
|
319
|
+
s = { name: G(i) }, n = ["verify"];
|
|
320
320
|
break;
|
|
321
321
|
default:
|
|
322
322
|
throw new P('Invalid or unsupported "alg" (Algorithm) value');
|
|
323
323
|
}
|
|
324
|
-
return
|
|
325
|
-
},
|
|
326
|
-
async function
|
|
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) {
|
|
327
327
|
if (e.indexOf("-----BEGIN PUBLIC KEY-----") !== 0)
|
|
328
328
|
throw new TypeError('"spki" must be SPKI formatted string');
|
|
329
|
-
return
|
|
329
|
+
return Pe(e, t);
|
|
330
330
|
}
|
|
331
|
-
const
|
|
331
|
+
const Ne = (e, t) => {
|
|
332
332
|
if (!(t instanceof Uint8Array)) {
|
|
333
333
|
if (!oe(t))
|
|
334
334
|
throw new TypeError(re(e, t, ...A, "Uint8Array"));
|
|
335
335
|
if (t.type !== "secret")
|
|
336
336
|
throw new TypeError(`${A.join(" or ")} instances for symmetric algorithms must be of type "secret"`);
|
|
337
337
|
}
|
|
338
|
-
},
|
|
338
|
+
}, De = (e, t, o) => {
|
|
339
339
|
if (!oe(t))
|
|
340
340
|
throw new TypeError(re(e, t, ...A));
|
|
341
341
|
if (t.type === "secret")
|
|
@@ -344,35 +344,35 @@ const Oe = (e, t) => {
|
|
|
344
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
346
|
throw new TypeError(`${A.join(" or ")} instances for asymmetric algorithm encryption must be of type "public"`);
|
|
347
|
-
},
|
|
348
|
-
e.startsWith("HS") || e === "dir" || e.startsWith("PBES2") || /^A\d{3}(?:GCM)?KW$/.test(e) ?
|
|
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);
|
|
349
349
|
};
|
|
350
|
-
function He(e, t, o, r,
|
|
351
|
-
if (
|
|
350
|
+
function He(e, t, o, r, a) {
|
|
351
|
+
if (a.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)
|
|
354
354
|
return /* @__PURE__ */ new Set();
|
|
355
|
-
if (!Array.isArray(r.crit) || r.crit.length === 0 || r.crit.some((
|
|
355
|
+
if (!Array.isArray(r.crit) || r.crit.length === 0 || r.crit.some((n) => typeof n != "string" || n.length === 0))
|
|
356
356
|
throw new e('"crit" (Critical) Header Parameter MUST be an array of non-empty strings when present');
|
|
357
357
|
let s;
|
|
358
358
|
o !== void 0 ? s = new Map([...Object.entries(o), ...t.entries()]) : s = t;
|
|
359
|
-
for (const
|
|
360
|
-
if (!s.has(
|
|
361
|
-
throw new P(`Extension Header Parameter "${
|
|
362
|
-
if (n
|
|
363
|
-
throw new e(`Extension Header Parameter "${
|
|
364
|
-
if (s.get(
|
|
365
|
-
throw new e(`Extension Header Parameter "${
|
|
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`);
|
|
366
366
|
}
|
|
367
367
|
return new Set(r.crit);
|
|
368
368
|
}
|
|
369
|
-
const
|
|
369
|
+
const Le = (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
|
|
375
|
+
function $e(e, t) {
|
|
376
376
|
const o = `SHA-${e.slice(-3)}`;
|
|
377
377
|
switch (e) {
|
|
378
378
|
case "HS256":
|
|
@@ -397,28 +397,28 @@ function Le(e, t) {
|
|
|
397
397
|
throw new P(`alg ${e} is not supported either by JOSE or your javascript runtime`);
|
|
398
398
|
}
|
|
399
399
|
}
|
|
400
|
-
function
|
|
400
|
+
function Je(e, t, o) {
|
|
401
401
|
if (Z(t))
|
|
402
|
-
return
|
|
402
|
+
return Te(t, e, o), t;
|
|
403
403
|
if (t instanceof Uint8Array) {
|
|
404
404
|
if (!e.startsWith("HS"))
|
|
405
|
-
throw new TypeError(
|
|
406
|
-
return
|
|
405
|
+
throw new TypeError(Y(t, ...A));
|
|
406
|
+
return x.subtle.importKey("raw", t, { hash: `SHA-${e.slice(-3)}`, name: "HMAC" }, !1, [o]);
|
|
407
407
|
}
|
|
408
|
-
throw new TypeError(
|
|
408
|
+
throw new TypeError(Y(t, ...A, "Uint8Array"));
|
|
409
409
|
}
|
|
410
|
-
const
|
|
411
|
-
const
|
|
412
|
-
|
|
413
|
-
const s =
|
|
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);
|
|
414
414
|
try {
|
|
415
|
-
return await
|
|
415
|
+
return await x.subtle.verify(s, a, o, r);
|
|
416
416
|
} catch {
|
|
417
417
|
return !1;
|
|
418
418
|
}
|
|
419
419
|
};
|
|
420
|
-
async function
|
|
421
|
-
if (!
|
|
420
|
+
async function We(e, t, o) {
|
|
421
|
+
if (!W(e))
|
|
422
422
|
throw new d("Flattened JWS must be an object");
|
|
423
423
|
if (e.protected === void 0 && e.header === void 0)
|
|
424
424
|
throw new d('Flattened JWS must have either of the "protected" or "header" members');
|
|
@@ -428,184 +428,184 @@ async function Ke(e, t, o) {
|
|
|
428
428
|
throw new d("JWS Payload missing");
|
|
429
429
|
if (typeof e.signature != "string")
|
|
430
430
|
throw new d("JWS Signature missing or incorrect type");
|
|
431
|
-
if (e.header !== void 0 && !
|
|
431
|
+
if (e.header !== void 0 && !W(e.header))
|
|
432
432
|
throw new d("JWS Unprotected Header incorrect type");
|
|
433
433
|
let r = {};
|
|
434
434
|
if (e.protected)
|
|
435
435
|
try {
|
|
436
|
-
const
|
|
437
|
-
r = JSON.parse(C.decode(
|
|
436
|
+
const w = N(e.protected);
|
|
437
|
+
r = JSON.parse(C.decode(w));
|
|
438
438
|
} catch {
|
|
439
439
|
throw new d("JWS Protected Header is invalid");
|
|
440
440
|
}
|
|
441
441
|
if (!ve(r, e.header))
|
|
442
442
|
throw new d("JWS Protected and JWS Unprotected Header Parameter names must be disjoint");
|
|
443
|
-
const
|
|
443
|
+
const a = {
|
|
444
444
|
...r,
|
|
445
445
|
...e.header
|
|
446
|
-
}, s = He(d, /* @__PURE__ */ new Map([["b64", !0]]), o == null ? void 0 : o.crit, r,
|
|
447
|
-
let
|
|
448
|
-
if (s.has("b64") && (
|
|
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
449
|
throw new d('The "b64" (base64url-encode payload) Header Parameter must be a boolean');
|
|
450
|
-
const { alg: i } =
|
|
450
|
+
const { alg: i } = a;
|
|
451
451
|
if (typeof i != "string" || !i)
|
|
452
452
|
throw new d('JWS "alg" (Algorithm) Header Parameter missing or invalid');
|
|
453
|
-
const c = o &&
|
|
453
|
+
const c = o && Le("algorithms", o.algorithms);
|
|
454
454
|
if (c && !c.has(i))
|
|
455
|
-
throw new
|
|
456
|
-
if (
|
|
455
|
+
throw new Ae('"alg" (Algorithm) Header Parameter value not allowed');
|
|
456
|
+
if (n) {
|
|
457
457
|
if (typeof e.payload != "string")
|
|
458
458
|
throw new d("JWS Payload must be a string");
|
|
459
459
|
} else if (typeof e.payload != "string" && !(e.payload instanceof Uint8Array))
|
|
460
460
|
throw new d("JWS Payload must be a string or an Uint8Array instance");
|
|
461
461
|
let p = !1;
|
|
462
|
-
typeof t == "function" && (t = await t(r, e), p = !0),
|
|
463
|
-
const
|
|
464
|
-
let
|
|
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;
|
|
465
465
|
try {
|
|
466
|
-
|
|
466
|
+
l = N(e.signature);
|
|
467
467
|
} catch {
|
|
468
468
|
throw new d("Failed to base64url decode the signature");
|
|
469
469
|
}
|
|
470
|
-
if (!await
|
|
471
|
-
throw new
|
|
472
|
-
let
|
|
473
|
-
if (
|
|
470
|
+
if (!await Ke(i, t, l, y))
|
|
471
|
+
throw new _e();
|
|
472
|
+
let m;
|
|
473
|
+
if (n)
|
|
474
474
|
try {
|
|
475
|
-
|
|
475
|
+
m = N(e.payload);
|
|
476
476
|
} catch {
|
|
477
477
|
throw new d("Failed to base64url decode the payload");
|
|
478
478
|
}
|
|
479
479
|
else
|
|
480
|
-
typeof e.payload == "string" ?
|
|
481
|
-
const
|
|
482
|
-
return e.protected !== void 0 && (
|
|
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
483
|
}
|
|
484
|
-
async function
|
|
484
|
+
async function xe(e, t, o) {
|
|
485
485
|
if (e instanceof Uint8Array && (e = C.decode(e)), typeof e != "string")
|
|
486
486
|
throw new d("Compact JWS must be a string or Uint8Array");
|
|
487
|
-
const { 0: r, 1:
|
|
488
|
-
if (
|
|
487
|
+
const { 0: r, 1: a, 2: s, length: n } = e.split(".");
|
|
488
|
+
if (n !== 3)
|
|
489
489
|
throw new d("Invalid Compact JWS");
|
|
490
|
-
const i = await
|
|
490
|
+
const i = await We({ payload: a, protected: r, signature: s }, t, o), c = { payload: i.payload, protectedHeader: i.protectedHeader };
|
|
491
491
|
return typeof t == "function" ? { ...c, key: i.key } : c;
|
|
492
492
|
}
|
|
493
|
-
const
|
|
494
|
-
const t =
|
|
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);
|
|
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();
|
|
498
|
-
let
|
|
498
|
+
let a;
|
|
499
499
|
switch (r) {
|
|
500
500
|
case "sec":
|
|
501
501
|
case "secs":
|
|
502
502
|
case "second":
|
|
503
503
|
case "seconds":
|
|
504
504
|
case "s":
|
|
505
|
-
|
|
505
|
+
a = Math.round(o);
|
|
506
506
|
break;
|
|
507
507
|
case "minute":
|
|
508
508
|
case "minutes":
|
|
509
509
|
case "min":
|
|
510
510
|
case "mins":
|
|
511
511
|
case "m":
|
|
512
|
-
|
|
512
|
+
a = Math.round(o * ae);
|
|
513
513
|
break;
|
|
514
514
|
case "hour":
|
|
515
515
|
case "hours":
|
|
516
516
|
case "hr":
|
|
517
517
|
case "hrs":
|
|
518
518
|
case "h":
|
|
519
|
-
|
|
519
|
+
a = Math.round(o * ne);
|
|
520
520
|
break;
|
|
521
521
|
case "day":
|
|
522
522
|
case "days":
|
|
523
523
|
case "d":
|
|
524
|
-
|
|
524
|
+
a = Math.round(o * j);
|
|
525
525
|
break;
|
|
526
526
|
case "week":
|
|
527
527
|
case "weeks":
|
|
528
528
|
case "w":
|
|
529
|
-
|
|
529
|
+
a = Math.round(o * Me);
|
|
530
530
|
break;
|
|
531
531
|
default:
|
|
532
|
-
|
|
532
|
+
a = Math.round(o * Ve);
|
|
533
533
|
break;
|
|
534
534
|
}
|
|
535
|
-
return t[1] === "-" || t[4] === "ago" ? -
|
|
536
|
-
}, F = (e) => e.toLowerCase().replace(/^application\//, ""),
|
|
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 = {}) => {
|
|
537
537
|
let r;
|
|
538
538
|
try {
|
|
539
539
|
r = JSON.parse(C.decode(t));
|
|
540
540
|
} catch {
|
|
541
541
|
}
|
|
542
|
-
if (!
|
|
542
|
+
if (!W(r))
|
|
543
543
|
throw new ee("JWT Claims Set must be a top-level JSON object");
|
|
544
|
-
const { typ:
|
|
545
|
-
if (
|
|
544
|
+
const { typ: a } = o;
|
|
545
|
+
if (a && (typeof e.typ != "string" || F(e.typ) !== F(a)))
|
|
546
546
|
throw new S('unexpected "typ" JWT header value', r, "typ", "check_failed");
|
|
547
|
-
const { requiredClaims: s = [], issuer:
|
|
548
|
-
p !== void 0 &&
|
|
549
|
-
for (const
|
|
550
|
-
if (!(
|
|
551
|
-
throw new S(`missing required "${
|
|
552
|
-
if (
|
|
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
553
|
throw new S('unexpected "iss" claim value', r, "iss", "check_failed");
|
|
554
554
|
if (i && r.sub !== i)
|
|
555
555
|
throw new S('unexpected "sub" claim value', r, "sub", "check_failed");
|
|
556
|
-
if (c && !
|
|
556
|
+
if (c && !Ge(r.aud, typeof c == "string" ? [c] : c))
|
|
557
557
|
throw new S('unexpected "aud" claim value', r, "aud", "check_failed");
|
|
558
|
-
let
|
|
558
|
+
let l;
|
|
559
559
|
switch (typeof o.clockTolerance) {
|
|
560
560
|
case "string":
|
|
561
|
-
|
|
561
|
+
l = B(o.clockTolerance);
|
|
562
562
|
break;
|
|
563
563
|
case "number":
|
|
564
|
-
|
|
564
|
+
l = o.clockTolerance;
|
|
565
565
|
break;
|
|
566
566
|
case "undefined":
|
|
567
|
-
|
|
567
|
+
l = 0;
|
|
568
568
|
break;
|
|
569
569
|
default:
|
|
570
570
|
throw new TypeError("Invalid clockTolerance option type");
|
|
571
571
|
}
|
|
572
|
-
const { currentDate:
|
|
572
|
+
const { currentDate: m } = o, h = je(m || /* @__PURE__ */ new Date());
|
|
573
573
|
if ((r.iat !== void 0 || p) && typeof r.iat != "number")
|
|
574
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
577
|
throw new S('"nbf" claim must be a number', r, "nbf", "invalid");
|
|
578
|
-
if (r.nbf >
|
|
578
|
+
if (r.nbf > h + l)
|
|
579
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
583
|
throw new S('"exp" claim must be a number', r, "exp", "invalid");
|
|
584
|
-
if (r.exp <=
|
|
585
|
-
throw new
|
|
584
|
+
if (r.exp <= h - l)
|
|
585
|
+
throw new V('"exp" claim timestamp check failed', r, "exp", "check_failed");
|
|
586
586
|
}
|
|
587
587
|
if (p) {
|
|
588
|
-
const
|
|
589
|
-
if (
|
|
590
|
-
throw new
|
|
591
|
-
if (
|
|
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
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
596
|
async function Fe(e, t, o) {
|
|
597
597
|
var r;
|
|
598
|
-
const
|
|
599
|
-
if ((r =
|
|
598
|
+
const a = await xe(e, t, o);
|
|
599
|
+
if ((r = a.protectedHeader.crit) != null && r.includes("b64") && a.protectedHeader.b64 === !1)
|
|
600
600
|
throw new ee("JWTs MUST NOT use unencoded payload");
|
|
601
|
-
const s = { payload: Be(
|
|
602
|
-
return typeof t == "function" ? { ...s, key:
|
|
601
|
+
const s = { payload: Be(a.protectedHeader, a.payload, o), protectedHeader: a.protectedHeader };
|
|
602
|
+
return typeof t == "function" ? { ...s, key: a.key } : s;
|
|
603
603
|
}
|
|
604
|
-
const
|
|
604
|
+
const qe = {
|
|
605
605
|
ID_TOKEN: "id_token",
|
|
606
606
|
ACCESS_TOKEN: "token",
|
|
607
607
|
ID_AND_ACCESS_TOKEN: "id_token token"
|
|
608
|
-
},
|
|
608
|
+
}, ze = {
|
|
609
609
|
CLIENT_ID: "X-Auth-ClientId"
|
|
610
610
|
}, _ = {
|
|
611
611
|
ALG: "RS256",
|
|
@@ -613,7 +613,7 @@ const Ge = {
|
|
|
613
613
|
TOKEN_ID_KEY: "__raw",
|
|
614
614
|
NONCE_KEY: "_nonce",
|
|
615
615
|
ISSUER: "gizmette.com"
|
|
616
|
-
},
|
|
616
|
+
}, Xe = `-----BEGIN PUBLIC KEY-----
|
|
617
617
|
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAsF6i3Jd9fY/3COqCw/m7
|
|
618
618
|
w5PKyTYLGAI2I6SIIdpe6i6DOCbEkmDz7LdVsBqwNtVi8gvWYIj+8ol6rU3qu1v5
|
|
619
619
|
i1Jd45GSK4kzkVdgCmQZbM5ak0KI99q5wsrAIzUd+LRJ2HRvWtr5IYdsIiXaQjle
|
|
@@ -623,7 +623,7 @@ sjqybA9mARAqh9k/eiIopecWSiffNQTwVQVd2I9ZH3BalhEXHlqFgrjz51kFqg81
|
|
|
623
623
|
awIDAQAB
|
|
624
624
|
-----END PUBLIC KEY-----`, se = async (e, t) => {
|
|
625
625
|
try {
|
|
626
|
-
const o = _.ALG, r = await
|
|
626
|
+
const o = _.ALG, r = await Oe(Xe, o);
|
|
627
627
|
return await Fe(e, r, {
|
|
628
628
|
issuer: _.ISSUER,
|
|
629
629
|
audience: t
|
|
@@ -635,117 +635,142 @@ awIDAQAB
|
|
|
635
635
|
function ie(e, t) {
|
|
636
636
|
window.dispatchEvent(new StorageEvent("storage", { key: e, newValue: t }));
|
|
637
637
|
}
|
|
638
|
-
const
|
|
638
|
+
const q = (e, t) => {
|
|
639
639
|
const o = JSON.stringify(
|
|
640
640
|
typeof t == "function" ? t() : t
|
|
641
641
|
);
|
|
642
642
|
window.localStorage.setItem(e, o), ie(e, o);
|
|
643
|
-
},
|
|
643
|
+
}, Qe = (e) => {
|
|
644
644
|
window.localStorage.removeItem(e), ie(e, null);
|
|
645
|
-
},
|
|
646
|
-
function
|
|
645
|
+
}, z = (e) => window.localStorage.getItem(e), Ze = (e) => (window.addEventListener("storage", e), () => window.removeEventListener("storage", e));
|
|
646
|
+
function U({
|
|
647
647
|
key: e,
|
|
648
648
|
initialValue: t
|
|
649
649
|
}) {
|
|
650
|
-
const o = () =>
|
|
651
|
-
|
|
650
|
+
const o = () => z(e), r = I.useSyncExternalStore(
|
|
651
|
+
Ze,
|
|
652
652
|
o
|
|
653
|
-
),
|
|
653
|
+
), a = I.useCallback(
|
|
654
654
|
(i) => {
|
|
655
655
|
try {
|
|
656
656
|
const c = typeof i == "function" ? i(JSON.parse(r)) : i;
|
|
657
|
-
c == null ?
|
|
657
|
+
c == null ? Qe(e) : q(e, c);
|
|
658
658
|
} catch (c) {
|
|
659
659
|
console.warn(c);
|
|
660
660
|
}
|
|
661
661
|
},
|
|
662
662
|
[e, r]
|
|
663
663
|
), s = I.useCallback(() => {
|
|
664
|
-
|
|
665
|
-
}, [t,
|
|
666
|
-
|
|
667
|
-
}, [
|
|
664
|
+
a(t);
|
|
665
|
+
}, [t, a]), n = I.useCallback(() => {
|
|
666
|
+
a(null);
|
|
667
|
+
}, [a]);
|
|
668
668
|
return I.useEffect(() => {
|
|
669
669
|
try {
|
|
670
|
-
|
|
670
|
+
z(e) === null && typeof t < "u" && q(e, t);
|
|
671
671
|
} catch (i) {
|
|
672
672
|
console.warn(i);
|
|
673
673
|
}
|
|
674
|
-
}, [e, t]), [r ? JSON.parse(r) : null,
|
|
674
|
+
}, [e, t]), [r ? JSON.parse(r) : null, a, s, n];
|
|
675
675
|
}
|
|
676
676
|
var u = [];
|
|
677
|
-
for (var
|
|
678
|
-
u.push((
|
|
679
|
-
function
|
|
677
|
+
for (var H = 0; H < 256; ++H)
|
|
678
|
+
u.push((H + 256).toString(16).slice(1));
|
|
679
|
+
function et(e, t = 0) {
|
|
680
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();
|
|
681
681
|
}
|
|
682
|
-
var k,
|
|
683
|
-
function
|
|
682
|
+
var k, tt = new Uint8Array(16);
|
|
683
|
+
function rt() {
|
|
684
684
|
if (!k && (k = typeof crypto < "u" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto), !k))
|
|
685
685
|
throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
|
|
686
|
-
return k(
|
|
686
|
+
return k(tt);
|
|
687
687
|
}
|
|
688
|
-
var
|
|
689
|
-
const
|
|
690
|
-
randomUUID:
|
|
688
|
+
var ot = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto);
|
|
689
|
+
const X = {
|
|
690
|
+
randomUUID: ot
|
|
691
691
|
};
|
|
692
|
-
function
|
|
693
|
-
if (
|
|
694
|
-
return
|
|
692
|
+
function at(e, t, o) {
|
|
693
|
+
if (X.randomUUID && !t && !e)
|
|
694
|
+
return X.randomUUID();
|
|
695
695
|
e = e || {};
|
|
696
|
-
var r = e.random || (e.rng ||
|
|
697
|
-
return r[6] = r[6] & 15 | 64, r[8] = r[8] & 63 | 128,
|
|
696
|
+
var r = e.random || (e.rng || rt)();
|
|
697
|
+
return r[6] = r[6] & 15 | 64, r[8] = r[8] & 63 | 128, et(r);
|
|
698
698
|
}
|
|
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.",
|
|
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 = {
|
|
700
700
|
dev: "https://auth.gizmette.local.com:3003",
|
|
701
701
|
prod: "https://mylogin.gizmette.com"
|
|
702
|
-
}, $ = "@@auth@@",
|
|
702
|
+
}, $ = "@@auth@@", ct = process.env.NODE_ENV === "production", ut = !ct, ce = {
|
|
703
|
+
AUTHENTICATE: "authenticate",
|
|
704
|
+
LOGOUT: "logout"
|
|
705
|
+
}, ue = async ({ type: e, params: t = {} }) => {
|
|
703
706
|
try {
|
|
704
|
-
const
|
|
705
|
-
|
|
707
|
+
const o = await fetch(
|
|
708
|
+
ut ? `${Q.dev}/${e}` : `${Q.prod}/${e}`,
|
|
706
709
|
{
|
|
707
710
|
credentials: "include",
|
|
708
711
|
method: "POST",
|
|
709
712
|
headers: {
|
|
710
713
|
"Content-Type": "application/json",
|
|
711
|
-
[
|
|
714
|
+
[ze.CLIENT_ID]: `${t.clientId}`
|
|
712
715
|
},
|
|
713
|
-
body: JSON.stringify(
|
|
716
|
+
body: JSON.stringify(t)
|
|
714
717
|
}
|
|
715
718
|
);
|
|
716
|
-
if (
|
|
717
|
-
return { status:
|
|
718
|
-
const { data:
|
|
719
|
+
if (o.status !== 200)
|
|
720
|
+
return { status: o.status, data: [] };
|
|
721
|
+
const { data: r, errors: a } = await o.json();
|
|
719
722
|
return {
|
|
720
|
-
status:
|
|
721
|
-
data:
|
|
722
|
-
errors:
|
|
723
|
+
status: o.status,
|
|
724
|
+
data: r,
|
|
725
|
+
errors: a
|
|
726
|
+
};
|
|
727
|
+
} catch (o) {
|
|
728
|
+
return console.error(o), { status: 500, data: [] };
|
|
729
|
+
}
|
|
730
|
+
}, J = async ({
|
|
731
|
+
idToken: e,
|
|
732
|
+
accessToken: t,
|
|
733
|
+
clientId: o
|
|
734
|
+
}) => {
|
|
735
|
+
try {
|
|
736
|
+
return {
|
|
737
|
+
status: (await ue({
|
|
738
|
+
type: ce.LOGOUT,
|
|
739
|
+
params: {
|
|
740
|
+
idToken: e,
|
|
741
|
+
accessToken: t,
|
|
742
|
+
clientId: o
|
|
743
|
+
}
|
|
744
|
+
})).status === 200
|
|
745
|
+
};
|
|
746
|
+
} catch {
|
|
747
|
+
return {
|
|
748
|
+
status: !1
|
|
723
749
|
};
|
|
724
|
-
} catch (t) {
|
|
725
|
-
return console.error(t), { status: 500, data: [] };
|
|
726
750
|
}
|
|
727
751
|
}, dt = async ({
|
|
728
752
|
username: e,
|
|
729
753
|
password: t,
|
|
730
754
|
clientId: o,
|
|
731
755
|
nonce: r,
|
|
732
|
-
sessionExpiration:
|
|
756
|
+
sessionExpiration: a
|
|
733
757
|
}) => {
|
|
734
758
|
try {
|
|
735
|
-
const s = await
|
|
759
|
+
const s = await ue({
|
|
760
|
+
type: ce.AUTHENTICATE,
|
|
736
761
|
params: {
|
|
737
|
-
type:
|
|
762
|
+
type: qe.ID_AND_ACCESS_TOKEN,
|
|
738
763
|
username: e,
|
|
739
764
|
password: t,
|
|
740
|
-
sessionExpiration:
|
|
765
|
+
sessionExpiration: a,
|
|
741
766
|
clientId: o,
|
|
742
767
|
nonce: r
|
|
743
768
|
}
|
|
744
|
-
}),
|
|
745
|
-
return
|
|
769
|
+
}), n = await se(s.data.idToken, o);
|
|
770
|
+
return n && n.payload[_.USER_ID_KEY] !== "" && n.payload[_.NONCE_KEY] === r ? {
|
|
746
771
|
idToken: s.data.idToken,
|
|
747
772
|
accessToken: s.data.accessToken,
|
|
748
|
-
userId:
|
|
773
|
+
userId: n.payload[_.USER_ID_KEY],
|
|
749
774
|
status: !0
|
|
750
775
|
} : {
|
|
751
776
|
status: !1
|
|
@@ -755,98 +780,112 @@ const L = "Oops! It looks like your session has expired. For your security, plea
|
|
|
755
780
|
status: !1
|
|
756
781
|
};
|
|
757
782
|
}
|
|
758
|
-
}
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
return Q(() => {
|
|
762
|
-
t.current = e;
|
|
763
|
-
}), t.current;
|
|
764
|
-
}
|
|
765
|
-
const J = () => {
|
|
766
|
-
throw new Error(st);
|
|
767
|
-
}, ce = fe({
|
|
783
|
+
}, K = () => {
|
|
784
|
+
throw new Error(it);
|
|
785
|
+
}, de = fe({
|
|
768
786
|
isAuthenticated: !1,
|
|
769
787
|
isLoading: !1,
|
|
770
|
-
login:
|
|
771
|
-
logout:
|
|
772
|
-
getAccessToken:
|
|
788
|
+
login: K,
|
|
789
|
+
logout: K,
|
|
790
|
+
getAccessToken: K,
|
|
773
791
|
logoutReason: "",
|
|
774
792
|
idTokenClaims: null
|
|
775
|
-
}),
|
|
793
|
+
}), yt = ({
|
|
776
794
|
children: e,
|
|
777
795
|
sessionExpiration: t,
|
|
778
796
|
clientId: o
|
|
779
797
|
}) => {
|
|
780
|
-
const [r,
|
|
798
|
+
const [r, a, , s] = U({
|
|
781
799
|
key: `${$}::${o}::@@user@@`
|
|
782
|
-
}), [
|
|
800
|
+
}), [n, i, , c] = U({
|
|
783
801
|
key: `${$}::${o}::@@access@@`
|
|
784
|
-
}), [, p, ,
|
|
802
|
+
}), [, p, , y] = U({
|
|
785
803
|
key: `${$}::${o}::@@nonce@@`
|
|
786
|
-
}), [
|
|
804
|
+
}), [l, m] = ye({
|
|
787
805
|
isLoading: !0,
|
|
788
806
|
isAuthenticated: !1,
|
|
789
807
|
logoutReason: "",
|
|
790
808
|
userId: "",
|
|
791
809
|
idTokenClaims: null
|
|
792
|
-
}),
|
|
793
|
-
(
|
|
794
|
-
|
|
810
|
+
}), h = me(
|
|
811
|
+
(f) => {
|
|
812
|
+
m({
|
|
795
813
|
isLoading: !1,
|
|
796
814
|
isAuthenticated: !1,
|
|
797
|
-
logoutReason:
|
|
815
|
+
logoutReason: f || L,
|
|
798
816
|
userId: "",
|
|
799
817
|
idTokenClaims: null
|
|
800
|
-
}), s(), c(),
|
|
818
|
+
}), s(), c(), y();
|
|
801
819
|
},
|
|
802
|
-
[s, c,
|
|
820
|
+
[s, c, y]
|
|
803
821
|
);
|
|
804
|
-
|
|
805
|
-
|
|
822
|
+
we(() => {
|
|
823
|
+
l.isLoading && r !== null && (async () => {
|
|
806
824
|
try {
|
|
807
|
-
const
|
|
808
|
-
|
|
825
|
+
const f = await se(r, o);
|
|
826
|
+
f && f.payload[_.USER_ID_KEY] !== "" ? m({
|
|
809
827
|
isLoading: !1,
|
|
810
828
|
isAuthenticated: !0,
|
|
811
829
|
logoutReason: "",
|
|
812
|
-
userId:
|
|
830
|
+
userId: f.payload[_.USER_ID_KEY],
|
|
813
831
|
idTokenClaims: {
|
|
814
|
-
...
|
|
832
|
+
...f == null ? void 0 : f.payload,
|
|
815
833
|
[_.TOKEN_ID_KEY]: r
|
|
816
834
|
}
|
|
817
|
-
}) :
|
|
835
|
+
}) : (h(L), await J({
|
|
836
|
+
idToken: r,
|
|
837
|
+
accessToken: n,
|
|
838
|
+
clientId: o
|
|
839
|
+
}));
|
|
818
840
|
} catch {
|
|
819
|
-
|
|
841
|
+
h(L), await J({
|
|
842
|
+
idToken: r,
|
|
843
|
+
accessToken: n,
|
|
844
|
+
clientId: o
|
|
845
|
+
});
|
|
820
846
|
}
|
|
821
847
|
})();
|
|
822
|
-
}, [
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
848
|
+
}, [
|
|
849
|
+
l.isLoading,
|
|
850
|
+
n,
|
|
851
|
+
r,
|
|
852
|
+
o,
|
|
853
|
+
h
|
|
854
|
+
]);
|
|
855
|
+
const w = async (f, he) => {
|
|
856
|
+
const M = at();
|
|
857
|
+
p(M);
|
|
858
|
+
const T = await dt({
|
|
859
|
+
username: f,
|
|
860
|
+
password: he,
|
|
829
861
|
clientId: o,
|
|
830
862
|
sessionExpiration: t,
|
|
831
|
-
nonce:
|
|
863
|
+
nonce: M
|
|
832
864
|
});
|
|
833
|
-
return
|
|
865
|
+
return T.status ? (a(T.idToken), i(T.accessToken), m({
|
|
834
866
|
isLoading: !1,
|
|
835
867
|
isAuthenticated: !0,
|
|
836
|
-
userId:
|
|
837
|
-
}), !0) : (
|
|
838
|
-
},
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
868
|
+
userId: T.userId
|
|
869
|
+
}), !0) : (h(st), !1);
|
|
870
|
+
}, O = async () => {
|
|
871
|
+
h(nt), await J({
|
|
872
|
+
idToken: r,
|
|
873
|
+
accessToken: n,
|
|
874
|
+
clientId: o
|
|
875
|
+
});
|
|
876
|
+
}, le = () => {
|
|
877
|
+
if (l.isAuthenticated && n)
|
|
878
|
+
return n;
|
|
879
|
+
};
|
|
880
|
+
return /* @__PURE__ */ pe(
|
|
881
|
+
de.Provider,
|
|
843
882
|
{
|
|
844
|
-
value: { ...
|
|
883
|
+
value: { ...l, login: w, logout: O, getAccessToken: le },
|
|
845
884
|
children: e
|
|
846
885
|
}
|
|
847
886
|
);
|
|
848
|
-
},
|
|
887
|
+
}, mt = (e = de) => Se(e);
|
|
849
888
|
export {
|
|
850
|
-
|
|
851
|
-
|
|
889
|
+
yt as AuthProvider,
|
|
890
|
+
mt as useAuth
|
|
852
891
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@versini/auth-provider",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.1.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Arno Versini",
|
|
6
6
|
"publishConfig": {
|
|
@@ -49,5 +49,5 @@
|
|
|
49
49
|
"jose": "5.4.1",
|
|
50
50
|
"uuid": "10.0.0"
|
|
51
51
|
},
|
|
52
|
-
"gitHead": "
|
|
52
|
+
"gitHead": "7d1b235e792243f979ae462cca442c9ae2a3c180"
|
|
53
53
|
}
|