@versini/auth-provider 5.1.2 → 5.1.3
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 +172 -167
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -4,13 +4,13 @@ var L = (e, t, r) => Be(e, typeof t != "symbol" ? t + "" : t, r);
|
|
|
4
4
|
import { jsx as Fe } from "react/jsx-runtime";
|
|
5
5
|
import { useSyncExternalStore as Ge, useCallback as H, useEffect as ve, createContext as qe, useRef as ze, useState as Xe, useContext as Qe } from "react";
|
|
6
6
|
/*!
|
|
7
|
-
@versini/auth-provider v5.1.
|
|
7
|
+
@versini/auth-provider v5.1.3
|
|
8
8
|
© 2024 gizmette.com
|
|
9
9
|
*/
|
|
10
10
|
try {
|
|
11
11
|
window.__VERSINI_AUTH_CLIENT__ || (window.__VERSINI_AUTH_CLIENT__ = {
|
|
12
|
-
version: "5.1.
|
|
13
|
-
buildTime: "07/09/2024
|
|
12
|
+
version: "5.1.3",
|
|
13
|
+
buildTime: "07/09/2024 03:32 PM EDT",
|
|
14
14
|
homepage: "https://github.com/aversini/auth-client",
|
|
15
15
|
license: "MIT"
|
|
16
16
|
});
|
|
@@ -23,7 +23,7 @@ try {
|
|
|
23
23
|
try {
|
|
24
24
|
window.__VERSINI_AUTH_COMMON__ || (window.__VERSINI_AUTH_COMMON__ = {
|
|
25
25
|
version: "2.11.0",
|
|
26
|
-
buildTime: "07/09/2024
|
|
26
|
+
buildTime: "07/09/2024 03:32 PM EDT",
|
|
27
27
|
homepage: "https://github.com/aversini/auth-client",
|
|
28
28
|
license: "MIT"
|
|
29
29
|
});
|
|
@@ -58,7 +58,7 @@ awIDAQAB
|
|
|
58
58
|
LOGOUT: "logout"
|
|
59
59
|
}, X = crypto, be = (e) => e instanceof CryptoKey, $ = new TextEncoder(), Q = new TextDecoder();
|
|
60
60
|
function tt(...e) {
|
|
61
|
-
const t = e.reduce((n, { length:
|
|
61
|
+
const t = e.reduce((n, { length: o }) => n + o, 0), r = new Uint8Array(t);
|
|
62
62
|
let a = 0;
|
|
63
63
|
for (const n of e)
|
|
64
64
|
r.set(n, a), a += n.length;
|
|
@@ -78,7 +78,7 @@ const rt = (e) => {
|
|
|
78
78
|
throw new TypeError("The input to be decoded is not correctly encoded.");
|
|
79
79
|
}
|
|
80
80
|
};
|
|
81
|
-
class
|
|
81
|
+
class P extends Error {
|
|
82
82
|
static get code() {
|
|
83
83
|
return "ERR_JOSE_GENERIC";
|
|
84
84
|
}
|
|
@@ -87,7 +87,7 @@ class C extends Error {
|
|
|
87
87
|
super(t), this.code = "ERR_JOSE_GENERIC", this.name = this.constructor.name, (r = Error.captureStackTrace) == null || r.call(Error, this, this.constructor);
|
|
88
88
|
}
|
|
89
89
|
}
|
|
90
|
-
class
|
|
90
|
+
class T extends P {
|
|
91
91
|
static get code() {
|
|
92
92
|
return "ERR_JWT_CLAIM_VALIDATION_FAILED";
|
|
93
93
|
}
|
|
@@ -95,7 +95,7 @@ class A extends C {
|
|
|
95
95
|
super(t), this.code = "ERR_JWT_CLAIM_VALIDATION_FAILED", this.claim = a, this.reason = n, this.payload = r;
|
|
96
96
|
}
|
|
97
97
|
}
|
|
98
|
-
class le extends
|
|
98
|
+
class le extends P {
|
|
99
99
|
static get code() {
|
|
100
100
|
return "ERR_JWT_EXPIRED";
|
|
101
101
|
}
|
|
@@ -103,7 +103,7 @@ class le extends C {
|
|
|
103
103
|
super(t), this.code = "ERR_JWT_EXPIRED", this.claim = a, this.reason = n, this.payload = r;
|
|
104
104
|
}
|
|
105
105
|
}
|
|
106
|
-
class at extends
|
|
106
|
+
class at extends P {
|
|
107
107
|
constructor() {
|
|
108
108
|
super(...arguments), this.code = "ERR_JOSE_ALG_NOT_ALLOWED";
|
|
109
109
|
}
|
|
@@ -111,7 +111,7 @@ class at extends C {
|
|
|
111
111
|
return "ERR_JOSE_ALG_NOT_ALLOWED";
|
|
112
112
|
}
|
|
113
113
|
}
|
|
114
|
-
class b extends
|
|
114
|
+
class b extends P {
|
|
115
115
|
constructor() {
|
|
116
116
|
super(...arguments), this.code = "ERR_JOSE_NOT_SUPPORTED";
|
|
117
117
|
}
|
|
@@ -119,7 +119,7 @@ class b extends C {
|
|
|
119
119
|
return "ERR_JOSE_NOT_SUPPORTED";
|
|
120
120
|
}
|
|
121
121
|
}
|
|
122
|
-
class f extends
|
|
122
|
+
class f extends P {
|
|
123
123
|
constructor() {
|
|
124
124
|
super(...arguments), this.code = "ERR_JWS_INVALID";
|
|
125
125
|
}
|
|
@@ -127,7 +127,7 @@ class f extends C {
|
|
|
127
127
|
return "ERR_JWS_INVALID";
|
|
128
128
|
}
|
|
129
129
|
}
|
|
130
|
-
let Re = class extends
|
|
130
|
+
let Re = class extends P {
|
|
131
131
|
constructor() {
|
|
132
132
|
super(...arguments), this.code = "ERR_JWT_INVALID";
|
|
133
133
|
}
|
|
@@ -135,7 +135,7 @@ let Re = class extends C {
|
|
|
135
135
|
return "ERR_JWT_INVALID";
|
|
136
136
|
}
|
|
137
137
|
};
|
|
138
|
-
class nt extends
|
|
138
|
+
class nt extends P {
|
|
139
139
|
constructor() {
|
|
140
140
|
super(...arguments), this.code = "ERR_JWS_SIGNATURE_VERIFICATION_FAILED", this.message = "signature verification failed";
|
|
141
141
|
}
|
|
@@ -143,7 +143,7 @@ class nt extends C {
|
|
|
143
143
|
return "ERR_JWS_SIGNATURE_VERIFICATION_FAILED";
|
|
144
144
|
}
|
|
145
145
|
}
|
|
146
|
-
function
|
|
146
|
+
function _(e, t = "algorithm.name") {
|
|
147
147
|
return new TypeError(`CryptoKey does not support this operation, its ${t} must be ${e}`);
|
|
148
148
|
}
|
|
149
149
|
function W(e, t) {
|
|
@@ -180,45 +180,45 @@ function it(e, t, ...r) {
|
|
|
180
180
|
case "HS384":
|
|
181
181
|
case "HS512": {
|
|
182
182
|
if (!W(e.algorithm, "HMAC"))
|
|
183
|
-
throw
|
|
183
|
+
throw _("HMAC");
|
|
184
184
|
const a = parseInt(t.slice(2), 10);
|
|
185
185
|
if (te(e.algorithm.hash) !== a)
|
|
186
|
-
throw
|
|
186
|
+
throw _(`SHA-${a}`, "algorithm.hash");
|
|
187
187
|
break;
|
|
188
188
|
}
|
|
189
189
|
case "RS256":
|
|
190
190
|
case "RS384":
|
|
191
191
|
case "RS512": {
|
|
192
192
|
if (!W(e.algorithm, "RSASSA-PKCS1-v1_5"))
|
|
193
|
-
throw
|
|
193
|
+
throw _("RSASSA-PKCS1-v1_5");
|
|
194
194
|
const a = parseInt(t.slice(2), 10);
|
|
195
195
|
if (te(e.algorithm.hash) !== a)
|
|
196
|
-
throw
|
|
196
|
+
throw _(`SHA-${a}`, "algorithm.hash");
|
|
197
197
|
break;
|
|
198
198
|
}
|
|
199
199
|
case "PS256":
|
|
200
200
|
case "PS384":
|
|
201
201
|
case "PS512": {
|
|
202
202
|
if (!W(e.algorithm, "RSA-PSS"))
|
|
203
|
-
throw
|
|
203
|
+
throw _("RSA-PSS");
|
|
204
204
|
const a = parseInt(t.slice(2), 10);
|
|
205
205
|
if (te(e.algorithm.hash) !== a)
|
|
206
|
-
throw
|
|
206
|
+
throw _(`SHA-${a}`, "algorithm.hash");
|
|
207
207
|
break;
|
|
208
208
|
}
|
|
209
209
|
case "EdDSA": {
|
|
210
210
|
if (e.algorithm.name !== "Ed25519" && e.algorithm.name !== "Ed448")
|
|
211
|
-
throw
|
|
211
|
+
throw _("Ed25519 or Ed448");
|
|
212
212
|
break;
|
|
213
213
|
}
|
|
214
214
|
case "ES256":
|
|
215
215
|
case "ES384":
|
|
216
216
|
case "ES512": {
|
|
217
217
|
if (!W(e.algorithm, "ECDSA"))
|
|
218
|
-
throw
|
|
218
|
+
throw _("ECDSA");
|
|
219
219
|
const a = st(t);
|
|
220
220
|
if (e.algorithm.namedCurve !== a)
|
|
221
|
-
throw
|
|
221
|
+
throw _(a, "algorithm.namedCurve");
|
|
222
222
|
break;
|
|
223
223
|
}
|
|
224
224
|
default:
|
|
@@ -249,10 +249,10 @@ const Pe = (e) => be(e) ? !0 : (e == null ? void 0 : e[Symbol.toStringTag]) ===
|
|
|
249
249
|
r = new Set(n);
|
|
250
250
|
continue;
|
|
251
251
|
}
|
|
252
|
-
for (const
|
|
253
|
-
if (r.has(
|
|
252
|
+
for (const o of n) {
|
|
253
|
+
if (r.has(o))
|
|
254
254
|
return !1;
|
|
255
|
-
r.add(
|
|
255
|
+
r.add(o);
|
|
256
256
|
}
|
|
257
257
|
}
|
|
258
258
|
return !0;
|
|
@@ -364,8 +364,8 @@ const De = (e) => (e == null ? void 0 : e[Symbol.toStringTag]) === "KeyObject",
|
|
|
364
364
|
let n = e.get(t);
|
|
365
365
|
if (n != null && n[a])
|
|
366
366
|
return n[a];
|
|
367
|
-
const
|
|
368
|
-
return n ? n[a] =
|
|
367
|
+
const o = await ht({ ...r, alg: a });
|
|
368
|
+
return n ? n[a] = o : e.set(t, { [a]: o }), o;
|
|
369
369
|
}, ft = (e, t) => {
|
|
370
370
|
if (De(e)) {
|
|
371
371
|
let r = e.export({ format: "jwk" });
|
|
@@ -384,7 +384,7 @@ const De = (e) => (e == null ? void 0 : e[Symbol.toStringTag]) === "KeyObject",
|
|
|
384
384
|
if (a === -1)
|
|
385
385
|
return !1;
|
|
386
386
|
const n = e.subarray(a, a + t.length);
|
|
387
|
-
return n.length !== t.length ? !1 : n.every((
|
|
387
|
+
return n.length !== t.length ? !1 : n.every((o, s) => o === t[s]) || v(e, t, a + 1);
|
|
388
388
|
}, fe = (e) => {
|
|
389
389
|
switch (!0) {
|
|
390
390
|
case v(e, [42, 134, 72, 206, 61, 3, 1, 7]):
|
|
@@ -405,52 +405,52 @@ const De = (e) => (e == null ? void 0 : e[Symbol.toStringTag]) === "KeyObject",
|
|
|
405
405
|
throw new b("Invalid or unsupported EC Key Curve or OKP Key Sub Type");
|
|
406
406
|
}
|
|
407
407
|
}, wt = async (e, t, r, a, n) => {
|
|
408
|
-
let
|
|
408
|
+
let o, s;
|
|
409
409
|
const i = new Uint8Array(atob(r.replace(e, "")).split("").map((c) => c.charCodeAt(0)));
|
|
410
410
|
switch (a) {
|
|
411
411
|
case "PS256":
|
|
412
412
|
case "PS384":
|
|
413
413
|
case "PS512":
|
|
414
|
-
|
|
414
|
+
o = { name: "RSA-PSS", hash: `SHA-${a.slice(-3)}` }, s = ["verify"];
|
|
415
415
|
break;
|
|
416
416
|
case "RS256":
|
|
417
417
|
case "RS384":
|
|
418
418
|
case "RS512":
|
|
419
|
-
|
|
419
|
+
o = { name: "RSASSA-PKCS1-v1_5", hash: `SHA-${a.slice(-3)}` }, s = ["verify"];
|
|
420
420
|
break;
|
|
421
421
|
case "RSA-OAEP":
|
|
422
422
|
case "RSA-OAEP-256":
|
|
423
423
|
case "RSA-OAEP-384":
|
|
424
424
|
case "RSA-OAEP-512":
|
|
425
|
-
|
|
425
|
+
o = {
|
|
426
426
|
name: "RSA-OAEP",
|
|
427
427
|
hash: `SHA-${parseInt(a.slice(-3), 10) || 1}`
|
|
428
|
-
},
|
|
428
|
+
}, s = ["encrypt", "wrapKey"];
|
|
429
429
|
break;
|
|
430
430
|
case "ES256":
|
|
431
|
-
|
|
431
|
+
o = { name: "ECDSA", namedCurve: "P-256" }, s = ["verify"];
|
|
432
432
|
break;
|
|
433
433
|
case "ES384":
|
|
434
|
-
|
|
434
|
+
o = { name: "ECDSA", namedCurve: "P-384" }, s = ["verify"];
|
|
435
435
|
break;
|
|
436
436
|
case "ES512":
|
|
437
|
-
|
|
437
|
+
o = { name: "ECDSA", namedCurve: "P-521" }, s = ["verify"];
|
|
438
438
|
break;
|
|
439
439
|
case "ECDH-ES":
|
|
440
440
|
case "ECDH-ES+A128KW":
|
|
441
441
|
case "ECDH-ES+A192KW":
|
|
442
442
|
case "ECDH-ES+A256KW": {
|
|
443
443
|
const c = fe(i);
|
|
444
|
-
|
|
444
|
+
o = c.startsWith("P-") ? { name: "ECDH", namedCurve: c } : { name: c }, s = [];
|
|
445
445
|
break;
|
|
446
446
|
}
|
|
447
447
|
case "EdDSA":
|
|
448
|
-
|
|
448
|
+
o = { name: fe(i) }, s = ["verify"];
|
|
449
449
|
break;
|
|
450
450
|
default:
|
|
451
451
|
throw new b('Invalid or unsupported "alg" (Algorithm) value');
|
|
452
452
|
}
|
|
453
|
-
return X.subtle.importKey(t, i,
|
|
453
|
+
return X.subtle.importKey(t, i, o, !1, s);
|
|
454
454
|
}, mt = (e, t, r) => wt(/(?:-----(?:BEGIN|END) PUBLIC KEY-----|\s)/g, "spki", e, t);
|
|
455
455
|
async function Et(e, t, r) {
|
|
456
456
|
if (e.indexOf("-----BEGIN PUBLIC KEY-----") !== 0)
|
|
@@ -481,17 +481,17 @@ function Tt(e, t, r, a, n) {
|
|
|
481
481
|
throw new e('"crit" (Critical) Header Parameter MUST be integrity protected');
|
|
482
482
|
if (!a || a.crit === void 0)
|
|
483
483
|
return /* @__PURE__ */ new Set();
|
|
484
|
-
if (!Array.isArray(a.crit) || a.crit.length === 0 || a.crit.some((
|
|
484
|
+
if (!Array.isArray(a.crit) || a.crit.length === 0 || a.crit.some((s) => typeof s != "string" || s.length === 0))
|
|
485
485
|
throw new e('"crit" (Critical) Header Parameter MUST be an array of non-empty strings when present');
|
|
486
|
-
let
|
|
487
|
-
r !== void 0 ?
|
|
488
|
-
for (const
|
|
489
|
-
if (!
|
|
490
|
-
throw new b(`Extension Header Parameter "${
|
|
491
|
-
if (n[
|
|
492
|
-
throw new e(`Extension Header Parameter "${
|
|
493
|
-
if (
|
|
494
|
-
throw new e(`Extension Header Parameter "${
|
|
486
|
+
let o;
|
|
487
|
+
r !== void 0 ? o = new Map([...Object.entries(r), ...t.entries()]) : o = t;
|
|
488
|
+
for (const s of a.crit) {
|
|
489
|
+
if (!o.has(s))
|
|
490
|
+
throw new b(`Extension Header Parameter "${s}" is not recognized`);
|
|
491
|
+
if (n[s] === void 0)
|
|
492
|
+
throw new e(`Extension Header Parameter "${s}" is missing`);
|
|
493
|
+
if (o.get(s) && a[s] === void 0)
|
|
494
|
+
throw new e(`Extension Header Parameter "${s}" MUST be integrity protected`);
|
|
495
495
|
}
|
|
496
496
|
return new Set(a.crit);
|
|
497
497
|
}
|
|
@@ -539,9 +539,9 @@ async function vt(e, t, r) {
|
|
|
539
539
|
const bt = async (e, t, r, a) => {
|
|
540
540
|
const n = await vt(e, t, "verify");
|
|
541
541
|
dt(e, n);
|
|
542
|
-
const
|
|
542
|
+
const o = _t(e, n.algorithm);
|
|
543
543
|
try {
|
|
544
|
-
return await X.subtle.verify(
|
|
544
|
+
return await X.subtle.verify(o, n, r, a);
|
|
545
545
|
} catch {
|
|
546
546
|
return !1;
|
|
547
547
|
}
|
|
@@ -562,8 +562,8 @@ async function Rt(e, t, r) {
|
|
|
562
562
|
let a = {};
|
|
563
563
|
if (e.protected)
|
|
564
564
|
try {
|
|
565
|
-
const
|
|
566
|
-
a = JSON.parse(Q.decode(
|
|
565
|
+
const g = B(e.protected);
|
|
566
|
+
a = JSON.parse(Q.decode(g));
|
|
567
567
|
} catch {
|
|
568
568
|
throw new f("JWS Protected Header is invalid");
|
|
569
569
|
}
|
|
@@ -572,9 +572,9 @@ async function Rt(e, t, r) {
|
|
|
572
572
|
const n = {
|
|
573
573
|
...a,
|
|
574
574
|
...e.header
|
|
575
|
-
},
|
|
576
|
-
let
|
|
577
|
-
if (
|
|
575
|
+
}, o = Tt(f, /* @__PURE__ */ new Map([["b64", !0]]), r == null ? void 0 : r.crit, a, n);
|
|
576
|
+
let s = !0;
|
|
577
|
+
if (o.has("b64") && (s = a.b64, typeof s != "boolean"))
|
|
578
578
|
throw new f('The "b64" (base64url-encode payload) Header Parameter must be a boolean');
|
|
579
579
|
const { alg: i } = n;
|
|
580
580
|
if (typeof i != "string" || !i)
|
|
@@ -582,7 +582,7 @@ async function Rt(e, t, r) {
|
|
|
582
582
|
const c = r && kt("algorithms", r.algorithms);
|
|
583
583
|
if (c && !c.has(i))
|
|
584
584
|
throw new at('"alg" (Algorithm) Header Parameter value not allowed');
|
|
585
|
-
if (
|
|
585
|
+
if (s) {
|
|
586
586
|
if (typeof e.payload != "string")
|
|
587
587
|
throw new f("JWS Payload must be a string");
|
|
588
588
|
} else if (typeof e.payload != "string" && !(e.payload instanceof Uint8Array))
|
|
@@ -598,24 +598,24 @@ async function Rt(e, t, r) {
|
|
|
598
598
|
}
|
|
599
599
|
if (!await bt(i, t, y, p))
|
|
600
600
|
throw new nt();
|
|
601
|
-
let
|
|
602
|
-
if (
|
|
601
|
+
let S;
|
|
602
|
+
if (s)
|
|
603
603
|
try {
|
|
604
|
-
|
|
604
|
+
S = B(e.payload);
|
|
605
605
|
} catch {
|
|
606
606
|
throw new f("Failed to base64url decode the payload");
|
|
607
607
|
}
|
|
608
|
-
else typeof e.payload == "string" ?
|
|
609
|
-
const m = { payload:
|
|
608
|
+
else typeof e.payload == "string" ? S = $.encode(e.payload) : S = e.payload;
|
|
609
|
+
const m = { payload: S };
|
|
610
610
|
return e.protected !== void 0 && (m.protectedHeader = a), e.header !== void 0 && (m.unprotectedHeader = e.header), d ? { ...m, key: t } : m;
|
|
611
611
|
}
|
|
612
612
|
async function It(e, t, r) {
|
|
613
613
|
if (e instanceof Uint8Array && (e = Q.decode(e)), typeof e != "string")
|
|
614
614
|
throw new f("Compact JWS must be a string or Uint8Array");
|
|
615
|
-
const { 0: a, 1: n, 2:
|
|
616
|
-
if (
|
|
615
|
+
const { 0: a, 1: n, 2: o, length: s } = e.split(".");
|
|
616
|
+
if (s !== 3)
|
|
617
617
|
throw new f("Invalid Compact JWS");
|
|
618
|
-
const i = await Rt({ payload: n, protected: a, signature:
|
|
618
|
+
const i = await Rt({ payload: n, protected: a, signature: o }, t, r), c = { payload: i.payload, protectedHeader: i.protectedHeader };
|
|
619
619
|
return typeof t == "function" ? { ...c, key: i.key } : c;
|
|
620
620
|
}
|
|
621
621
|
const Ct = (e) => Math.floor(e.getTime() / 1e3), He = 60, Ke = He * 60, ce = Ke * 24, Pt = ce * 7, Ot = ce * 365.25, Dt = /^(\+|\-)? ?(\d+|\d+\.\d+) ?(seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)(?: (ago|from now))?$/i, pe = (e) => {
|
|
@@ -671,18 +671,18 @@ const Ct = (e) => Math.floor(e.getTime() / 1e3), He = 60, Ke = He * 60, ce = Ke
|
|
|
671
671
|
throw new Re("JWT Claims Set must be a top-level JSON object");
|
|
672
672
|
const { typ: n } = r;
|
|
673
673
|
if (n && (typeof e.typ != "string" || ye(e.typ) !== ye(n)))
|
|
674
|
-
throw new
|
|
675
|
-
const { requiredClaims:
|
|
676
|
-
d !== void 0 && p.push("iat"), c !== void 0 && p.push("aud"), i !== void 0 && p.push("sub"),
|
|
677
|
-
for (const
|
|
678
|
-
if (!(
|
|
679
|
-
throw new
|
|
680
|
-
if (
|
|
681
|
-
throw new
|
|
674
|
+
throw new T('unexpected "typ" JWT header value', a, "typ", "check_failed");
|
|
675
|
+
const { requiredClaims: o = [], issuer: s, subject: i, audience: c, maxTokenAge: d } = r, p = [...o];
|
|
676
|
+
d !== void 0 && p.push("iat"), c !== void 0 && p.push("aud"), i !== void 0 && p.push("sub"), s !== void 0 && p.push("iss");
|
|
677
|
+
for (const g of new Set(p.reverse()))
|
|
678
|
+
if (!(g in a))
|
|
679
|
+
throw new T(`missing required "${g}" claim`, a, g, "missing");
|
|
680
|
+
if (s && !(Array.isArray(s) ? s : [s]).includes(a.iss))
|
|
681
|
+
throw new T('unexpected "iss" claim value', a, "iss", "check_failed");
|
|
682
682
|
if (i && a.sub !== i)
|
|
683
|
-
throw new
|
|
683
|
+
throw new T('unexpected "sub" claim value', a, "sub", "check_failed");
|
|
684
684
|
if (c && !Ut(a.aud, typeof c == "string" ? [c] : c))
|
|
685
|
-
throw new
|
|
685
|
+
throw new T('unexpected "aud" claim value', a, "aud", "check_failed");
|
|
686
686
|
let y;
|
|
687
687
|
switch (typeof r.clockTolerance) {
|
|
688
688
|
case "string":
|
|
@@ -697,27 +697,27 @@ const Ct = (e) => Math.floor(e.getTime() / 1e3), He = 60, Ke = He * 60, ce = Ke
|
|
|
697
697
|
default:
|
|
698
698
|
throw new TypeError("Invalid clockTolerance option type");
|
|
699
699
|
}
|
|
700
|
-
const { currentDate:
|
|
700
|
+
const { currentDate: S } = r, m = Ct(S || /* @__PURE__ */ new Date());
|
|
701
701
|
if ((a.iat !== void 0 || d) && typeof a.iat != "number")
|
|
702
|
-
throw new
|
|
702
|
+
throw new T('"iat" claim must be a number', a, "iat", "invalid");
|
|
703
703
|
if (a.nbf !== void 0) {
|
|
704
704
|
if (typeof a.nbf != "number")
|
|
705
|
-
throw new
|
|
705
|
+
throw new T('"nbf" claim must be a number', a, "nbf", "invalid");
|
|
706
706
|
if (a.nbf > m + y)
|
|
707
|
-
throw new
|
|
707
|
+
throw new T('"nbf" claim timestamp check failed', a, "nbf", "check_failed");
|
|
708
708
|
}
|
|
709
709
|
if (a.exp !== void 0) {
|
|
710
710
|
if (typeof a.exp != "number")
|
|
711
|
-
throw new
|
|
711
|
+
throw new T('"exp" claim must be a number', a, "exp", "invalid");
|
|
712
712
|
if (a.exp <= m - y)
|
|
713
713
|
throw new le('"exp" claim timestamp check failed', a, "exp", "check_failed");
|
|
714
714
|
}
|
|
715
715
|
if (d) {
|
|
716
|
-
const
|
|
717
|
-
if (
|
|
716
|
+
const g = m - a.iat, ee = typeof d == "number" ? d : pe(d);
|
|
717
|
+
if (g - y > ee)
|
|
718
718
|
throw new le('"iat" claim timestamp check failed (too far in the past)', a, "iat", "check_failed");
|
|
719
|
-
if (
|
|
720
|
-
throw new
|
|
719
|
+
if (g < 0 - y)
|
|
720
|
+
throw new T('"iat" claim timestamp check failed (it should be in the past)', a, "iat", "check_failed");
|
|
721
721
|
}
|
|
722
722
|
return a;
|
|
723
723
|
};
|
|
@@ -726,8 +726,8 @@ async function Kt(e, t, r) {
|
|
|
726
726
|
const n = await It(e, t, r);
|
|
727
727
|
if ((a = n.protectedHeader.crit) != null && a.includes("b64") && n.protectedHeader.b64 === !1)
|
|
728
728
|
throw new Re("JWTs MUST NOT use unencoded payload");
|
|
729
|
-
const
|
|
730
|
-
return typeof t == "function" ? { ...
|
|
729
|
+
const o = { payload: Ht(n.protectedHeader, n.payload, r), protectedHeader: n.protectedHeader };
|
|
730
|
+
return typeof t == "function" ? { ...o, key: n.key } : o;
|
|
731
731
|
}
|
|
732
732
|
const K = async (e) => {
|
|
733
733
|
try {
|
|
@@ -796,9 +796,9 @@ function x({
|
|
|
796
796
|
initialValue: t
|
|
797
797
|
}) {
|
|
798
798
|
const r = Ge(Yt, () => ge(e)), a = H(
|
|
799
|
-
(
|
|
799
|
+
(s) => {
|
|
800
800
|
try {
|
|
801
|
-
const i = typeof
|
|
801
|
+
const i = typeof s == "function" ? s(JSON.parse(r)) : s;
|
|
802
802
|
i == null ? Vt(e) : Se(e, i);
|
|
803
803
|
} catch (i) {
|
|
804
804
|
console.warn(i);
|
|
@@ -807,16 +807,16 @@ function x({
|
|
|
807
807
|
[e, r]
|
|
808
808
|
), n = H(() => {
|
|
809
809
|
a(t);
|
|
810
|
-
}, [t, a]),
|
|
810
|
+
}, [t, a]), o = H(() => {
|
|
811
811
|
a(null);
|
|
812
812
|
}, [a]);
|
|
813
813
|
return ve(() => {
|
|
814
814
|
try {
|
|
815
815
|
ge(e) === null && typeof t < "u" && Se(e, t);
|
|
816
|
-
} catch (
|
|
817
|
-
console.warn(
|
|
816
|
+
} catch (s) {
|
|
817
|
+
console.warn(s);
|
|
818
818
|
}
|
|
819
|
-
}, [e, t]), [r ? JSON.parse(r) : null, a, n,
|
|
819
|
+
}, [e, t]), [r ? JSON.parse(r) : null, a, n, o];
|
|
820
820
|
}
|
|
821
821
|
var h = [];
|
|
822
822
|
for (var se = 0; se < 256; ++se)
|
|
@@ -864,32 +864,34 @@ const M = "Oops! It looks like your session has expired. For your security, plea
|
|
|
864
864
|
);
|
|
865
865
|
if (a.status !== 200)
|
|
866
866
|
return { status: a.status, data: [] };
|
|
867
|
-
const { data: n, errors:
|
|
867
|
+
const { data: n, errors: o } = await a.json();
|
|
868
868
|
return {
|
|
869
869
|
status: a.status,
|
|
870
870
|
data: n,
|
|
871
|
-
errors:
|
|
871
|
+
errors: o
|
|
872
872
|
};
|
|
873
873
|
} catch (a) {
|
|
874
874
|
return console.error(a), { status: 500, data: [] };
|
|
875
875
|
}
|
|
876
876
|
}, tr = async ({
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
877
|
+
userId: e,
|
|
878
|
+
idToken: t,
|
|
879
|
+
accessToken: r,
|
|
880
|
+
refreshToken: a,
|
|
881
|
+
clientId: n,
|
|
882
|
+
domain: o
|
|
882
883
|
}) => {
|
|
883
884
|
try {
|
|
884
885
|
return {
|
|
885
886
|
status: (await Z({
|
|
886
887
|
type: z.LOGOUT,
|
|
887
|
-
clientId:
|
|
888
|
+
clientId: n,
|
|
888
889
|
params: {
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
890
|
+
userId: e,
|
|
891
|
+
idToken: t,
|
|
892
|
+
accessToken: r,
|
|
893
|
+
refreshToken: a,
|
|
894
|
+
domain: o
|
|
893
895
|
}
|
|
894
896
|
})).status === 200
|
|
895
897
|
};
|
|
@@ -904,8 +906,8 @@ const M = "Oops! It looks like your session has expired. For your security, plea
|
|
|
904
906
|
clientId: r,
|
|
905
907
|
nonce: a,
|
|
906
908
|
type: n,
|
|
907
|
-
sessionExpiration:
|
|
908
|
-
code:
|
|
909
|
+
sessionExpiration: o,
|
|
910
|
+
code: s,
|
|
909
911
|
code_verifier: i,
|
|
910
912
|
domain: c
|
|
911
913
|
}) => {
|
|
@@ -917,9 +919,9 @@ const M = "Oops! It looks like your session has expired. For your security, plea
|
|
|
917
919
|
type: n || q.ID_AND_ACCESS_TOKEN,
|
|
918
920
|
username: e,
|
|
919
921
|
password: t,
|
|
920
|
-
sessionExpiration:
|
|
922
|
+
sessionExpiration: o,
|
|
921
923
|
nonce: a,
|
|
922
|
-
code:
|
|
924
|
+
code: s,
|
|
923
925
|
code_verifier: i,
|
|
924
926
|
domain: c
|
|
925
927
|
}
|
|
@@ -970,10 +972,10 @@ const M = "Oops! It looks like your session has expired. For your security, plea
|
|
|
970
972
|
nonce: r,
|
|
971
973
|
refreshToken: a,
|
|
972
974
|
accessToken: n,
|
|
973
|
-
domain:
|
|
975
|
+
domain: o
|
|
974
976
|
}) => {
|
|
975
977
|
try {
|
|
976
|
-
const
|
|
978
|
+
const s = await Z({
|
|
977
979
|
type: z.AUTHENTICATE,
|
|
978
980
|
clientId: e,
|
|
979
981
|
params: {
|
|
@@ -982,12 +984,12 @@ const M = "Oops! It looks like your session has expired. For your security, plea
|
|
|
982
984
|
nonce: r,
|
|
983
985
|
refreshToken: a,
|
|
984
986
|
accessToken: n,
|
|
985
|
-
domain:
|
|
987
|
+
domain: o
|
|
986
988
|
}
|
|
987
|
-
}), i = await K(
|
|
989
|
+
}), i = await K(s.data.accessToken);
|
|
988
990
|
return i && i.payload[w.USER_ID_KEY] !== "" && i.payload[w.NONCE_KEY] === r ? {
|
|
989
|
-
accessToken:
|
|
990
|
-
refreshToken:
|
|
991
|
+
accessToken: s.data.accessToken,
|
|
992
|
+
refreshToken: s.data.refreshToken,
|
|
991
993
|
userId: i.payload[w.USER_ID_KEY],
|
|
992
994
|
status: !0
|
|
993
995
|
} : {
|
|
@@ -1030,9 +1032,9 @@ class nr {
|
|
|
1030
1032
|
nonce: a,
|
|
1031
1033
|
domain: n
|
|
1032
1034
|
}) {
|
|
1033
|
-
const
|
|
1034
|
-
if (
|
|
1035
|
-
const
|
|
1035
|
+
const o = await K(this.refreshToken);
|
|
1036
|
+
if (o && o.payload[w.USER_ID_KEY] !== "") {
|
|
1037
|
+
const s = await ar({
|
|
1036
1038
|
clientId: t,
|
|
1037
1039
|
userId: r,
|
|
1038
1040
|
nonce: a,
|
|
@@ -1040,10 +1042,10 @@ class nr {
|
|
|
1040
1042
|
accessToken: this.accessToken,
|
|
1041
1043
|
domain: n
|
|
1042
1044
|
});
|
|
1043
|
-
return
|
|
1045
|
+
return s.status ? (this.accessToken = s.accessToken, this.refreshToken = s.refreshToken, {
|
|
1044
1046
|
status: "success",
|
|
1045
|
-
newAccessToken:
|
|
1046
|
-
newRefreshToken:
|
|
1047
|
+
newAccessToken: s.accessToken,
|
|
1048
|
+
newRefreshToken: s.refreshToken
|
|
1047
1049
|
}) : {
|
|
1048
1050
|
status: "failure"
|
|
1049
1051
|
};
|
|
@@ -1069,24 +1071,24 @@ const Y = () => {
|
|
|
1069
1071
|
clientId: r,
|
|
1070
1072
|
domain: a = ""
|
|
1071
1073
|
}) => {
|
|
1072
|
-
const n = ze(!1), [
|
|
1074
|
+
const n = ze(!1), [o, s, , i] = x({
|
|
1073
1075
|
key: `${V}::${r}::@@user@@`
|
|
1074
1076
|
}), [c, d, , p] = x({
|
|
1075
1077
|
key: `${V}::${r}::@@access@@`
|
|
1076
|
-
}), [y,
|
|
1078
|
+
}), [y, S, , m] = x(
|
|
1077
1079
|
{
|
|
1078
1080
|
key: `${V}::${r}::@@refresh@@`
|
|
1079
1081
|
}
|
|
1080
|
-
), [
|
|
1082
|
+
), [g, ee, , ue] = x({
|
|
1081
1083
|
key: `${V}::${r}::@@nonce@@`
|
|
1082
|
-
}), $e = new nr(c, y), [
|
|
1084
|
+
}), $e = new nr(c, y), [R, k] = Xe({
|
|
1083
1085
|
isLoading: !0,
|
|
1084
1086
|
isAuthenticated: !1,
|
|
1085
1087
|
user: void 0,
|
|
1086
1088
|
logoutReason: ""
|
|
1087
1089
|
}), N = H(
|
|
1088
1090
|
(u) => {
|
|
1089
|
-
console.warn(u),
|
|
1091
|
+
console.warn(u), k({
|
|
1090
1092
|
isLoading: !0,
|
|
1091
1093
|
isAuthenticated: !1,
|
|
1092
1094
|
user: void 0,
|
|
@@ -1094,34 +1096,37 @@ const Y = () => {
|
|
|
1094
1096
|
}), i(), p(), m(), ue();
|
|
1095
1097
|
},
|
|
1096
1098
|
[p, i, ue, m]
|
|
1097
|
-
),
|
|
1099
|
+
), I = H(
|
|
1098
1100
|
async (u) => {
|
|
1101
|
+
const { user: A } = R;
|
|
1099
1102
|
N(u || M), await tr({
|
|
1100
|
-
|
|
1103
|
+
userId: (A == null ? void 0 : A.userId) || "",
|
|
1104
|
+
idToken: o,
|
|
1101
1105
|
accessToken: c,
|
|
1102
1106
|
refreshToken: y,
|
|
1103
1107
|
clientId: r,
|
|
1104
1108
|
domain: a
|
|
1105
|
-
}),
|
|
1106
|
-
...
|
|
1109
|
+
}), k((E) => ({
|
|
1110
|
+
...E,
|
|
1107
1111
|
isLoading: !1
|
|
1108
1112
|
}));
|
|
1109
1113
|
},
|
|
1110
1114
|
[
|
|
1111
1115
|
c,
|
|
1116
|
+
R,
|
|
1112
1117
|
r,
|
|
1113
1118
|
a,
|
|
1114
|
-
|
|
1119
|
+
o,
|
|
1115
1120
|
y,
|
|
1116
1121
|
N
|
|
1117
1122
|
]
|
|
1118
1123
|
);
|
|
1119
1124
|
ve(() => {
|
|
1120
1125
|
if (!n.current)
|
|
1121
|
-
return
|
|
1126
|
+
return R.isLoading && o !== null ? (async () => {
|
|
1122
1127
|
try {
|
|
1123
|
-
const u = await K(
|
|
1124
|
-
u && u.payload[w.USER_ID_KEY] !== "" ?
|
|
1128
|
+
const u = await K(o);
|
|
1129
|
+
u && u.payload[w.USER_ID_KEY] !== "" ? k({
|
|
1125
1130
|
isLoading: !1,
|
|
1126
1131
|
isAuthenticated: !0,
|
|
1127
1132
|
user: {
|
|
@@ -1129,41 +1134,41 @@ const Y = () => {
|
|
|
1129
1134
|
username: u.payload[w.USERNAME_KEY]
|
|
1130
1135
|
},
|
|
1131
1136
|
logoutReason: ""
|
|
1132
|
-
}) : await
|
|
1137
|
+
}) : await I(M);
|
|
1133
1138
|
} catch {
|
|
1134
|
-
await
|
|
1139
|
+
await I(M);
|
|
1135
1140
|
}
|
|
1136
|
-
})() :
|
|
1141
|
+
})() : k((u) => ({
|
|
1137
1142
|
...u,
|
|
1138
1143
|
isLoading: !1
|
|
1139
1144
|
})), () => {
|
|
1140
1145
|
n.current = !0;
|
|
1141
1146
|
};
|
|
1142
|
-
}, [
|
|
1143
|
-
const We = async (u,
|
|
1144
|
-
const
|
|
1145
|
-
if (ee(
|
|
1147
|
+
}, [R.isLoading, o, I]);
|
|
1148
|
+
const We = async (u, A, E) => {
|
|
1149
|
+
const C = zt();
|
|
1150
|
+
if (ee(C), k((D) => ({
|
|
1146
1151
|
...D,
|
|
1147
1152
|
isLoading: !0
|
|
1148
|
-
})), i(), p(), m(),
|
|
1153
|
+
})), i(), p(), m(), E === q.CODE) {
|
|
1149
1154
|
const { code_verifier: D, code_challenge: Me } = await Mt(), de = await rr({
|
|
1150
|
-
nonce:
|
|
1155
|
+
nonce: C,
|
|
1151
1156
|
clientId: r,
|
|
1152
1157
|
code_challenge: Me
|
|
1153
1158
|
});
|
|
1154
1159
|
if (de.status) {
|
|
1155
1160
|
const U = await _e({
|
|
1156
1161
|
username: u,
|
|
1157
|
-
password:
|
|
1162
|
+
password: A,
|
|
1158
1163
|
clientId: r,
|
|
1159
1164
|
sessionExpiration: t,
|
|
1160
|
-
nonce:
|
|
1161
|
-
type:
|
|
1165
|
+
nonce: C,
|
|
1166
|
+
type: E,
|
|
1162
1167
|
code: de.code,
|
|
1163
1168
|
code_verifier: D,
|
|
1164
1169
|
domain: a
|
|
1165
1170
|
});
|
|
1166
|
-
return U.status ? (
|
|
1171
|
+
return U.status ? (s(U.idToken), d(U.accessToken), S(U.refreshToken), k({
|
|
1167
1172
|
isLoading: !1,
|
|
1168
1173
|
isAuthenticated: !0,
|
|
1169
1174
|
user: {
|
|
@@ -1171,7 +1176,7 @@ const Y = () => {
|
|
|
1171
1176
|
username: u
|
|
1172
1177
|
},
|
|
1173
1178
|
logoutReason: ""
|
|
1174
|
-
}), !0) : (N(Te),
|
|
1179
|
+
}), !0) : (N(Te), k((Ve) => ({
|
|
1175
1180
|
...Ve,
|
|
1176
1181
|
isLoading: !1
|
|
1177
1182
|
})), !1);
|
|
@@ -1180,55 +1185,55 @@ const Y = () => {
|
|
|
1180
1185
|
}
|
|
1181
1186
|
const O = await _e({
|
|
1182
1187
|
username: u,
|
|
1183
|
-
password:
|
|
1188
|
+
password: A,
|
|
1184
1189
|
clientId: r,
|
|
1185
1190
|
sessionExpiration: t,
|
|
1186
|
-
nonce:
|
|
1187
|
-
type:
|
|
1191
|
+
nonce: C,
|
|
1192
|
+
type: E,
|
|
1188
1193
|
domain: a
|
|
1189
1194
|
});
|
|
1190
|
-
return O.status ? (
|
|
1195
|
+
return O.status ? (s(O.idToken), d(O.accessToken), S(O.refreshToken), k({
|
|
1191
1196
|
isLoading: !1,
|
|
1192
1197
|
isAuthenticated: !0,
|
|
1193
1198
|
user: {
|
|
1194
1199
|
userId: O.userId,
|
|
1195
1200
|
username: u
|
|
1196
1201
|
}
|
|
1197
|
-
}), !0) : (N(Te),
|
|
1202
|
+
}), !0) : (N(Te), k((D) => ({
|
|
1198
1203
|
...D,
|
|
1199
1204
|
isLoading: !1
|
|
1200
1205
|
})), !1);
|
|
1201
1206
|
}, Je = async (u) => {
|
|
1202
|
-
u == null || u.preventDefault(), await
|
|
1207
|
+
u == null || u.preventDefault(), await I(Xt);
|
|
1203
1208
|
}, xe = async () => {
|
|
1204
|
-
const { isAuthenticated: u, user:
|
|
1209
|
+
const { isAuthenticated: u, user: A } = R;
|
|
1205
1210
|
try {
|
|
1206
|
-
if (u &&
|
|
1211
|
+
if (u && A && A.userId) {
|
|
1207
1212
|
if (c) {
|
|
1208
|
-
const
|
|
1209
|
-
if (
|
|
1213
|
+
const C = await K(c);
|
|
1214
|
+
if (C && C.payload[w.USER_ID_KEY] !== "")
|
|
1210
1215
|
return c;
|
|
1211
1216
|
}
|
|
1212
|
-
const
|
|
1217
|
+
const E = await $e.refreshtoken({
|
|
1213
1218
|
clientId: r,
|
|
1214
|
-
userId:
|
|
1215
|
-
nonce:
|
|
1219
|
+
userId: A.userId,
|
|
1220
|
+
nonce: g,
|
|
1216
1221
|
domain: a
|
|
1217
1222
|
});
|
|
1218
|
-
return
|
|
1223
|
+
return E.status && E.status === "success" ? (d(E.newAccessToken), S(E.newRefreshToken), E.newAccessToken) : (await I(oe), "");
|
|
1219
1224
|
}
|
|
1220
|
-
return await
|
|
1225
|
+
return await I(oe), "";
|
|
1221
1226
|
} catch {
|
|
1222
|
-
return await
|
|
1227
|
+
return await I(oe), "";
|
|
1223
1228
|
}
|
|
1224
1229
|
}, je = () => {
|
|
1225
|
-
if (
|
|
1226
|
-
return
|
|
1230
|
+
if (R.isAuthenticated && o)
|
|
1231
|
+
return o;
|
|
1227
1232
|
};
|
|
1228
1233
|
return /* @__PURE__ */ Fe(
|
|
1229
1234
|
Le.Provider,
|
|
1230
1235
|
{
|
|
1231
|
-
value: { ...
|
|
1236
|
+
value: { ...R, login: We, logout: Je, getAccessToken: xe, getIdToken: je },
|
|
1232
1237
|
children: e
|
|
1233
1238
|
}
|
|
1234
1239
|
);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@versini/auth-provider",
|
|
3
|
-
"version": "5.1.
|
|
3
|
+
"version": "5.1.3",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Arno Versini",
|
|
6
6
|
"publishConfig": {
|
|
@@ -49,5 +49,5 @@
|
|
|
49
49
|
"jose": "5.6.3",
|
|
50
50
|
"uuid": "10.0.0"
|
|
51
51
|
},
|
|
52
|
-
"gitHead": "
|
|
52
|
+
"gitHead": "7e11120613639298318e8075445b3e56f7e01404"
|
|
53
53
|
}
|