@versini/auth-provider 4.4.0 → 5.0.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 +4 -1
- package/dist/index.js +146 -136
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -2,26 +2,26 @@ import { jsx as We } from "react/jsx-runtime";
|
|
|
2
2
|
import * as D from "react";
|
|
3
3
|
import { createContext as Je, useState as xe, useCallback as je, useEffect as Me, useContext as Ve } from "react";
|
|
4
4
|
/*!
|
|
5
|
-
@versini/auth-provider
|
|
5
|
+
@versini/auth-provider v5.0.0
|
|
6
6
|
© 2024 gizmette.com
|
|
7
7
|
*/
|
|
8
8
|
try {
|
|
9
9
|
window.__VERSINI_AUTH_CLIENT__ || (window.__VERSINI_AUTH_CLIENT__ = {
|
|
10
|
-
version: "
|
|
11
|
-
buildTime: "06/29/2024
|
|
10
|
+
version: "5.0.0",
|
|
11
|
+
buildTime: "06/29/2024 02:02 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.10.
|
|
18
|
+
@versini/auth-common v2.10.1
|
|
19
19
|
© 2024 gizmette.com
|
|
20
20
|
*/
|
|
21
21
|
try {
|
|
22
22
|
window.__VERSINI_AUTH_COMMON__ || (window.__VERSINI_AUTH_COMMON__ = {
|
|
23
|
-
version: "2.10.
|
|
24
|
-
buildTime: "06/29/2024
|
|
23
|
+
version: "2.10.1",
|
|
24
|
+
buildTime: "06/29/2024 02:02 PM EDT",
|
|
25
25
|
homepage: "https://github.com/aversini/auth-client",
|
|
26
26
|
license: "MIT"
|
|
27
27
|
});
|
|
@@ -35,11 +35,12 @@ const B = {
|
|
|
35
35
|
REFRESH_TOKEN: "refresh_token"
|
|
36
36
|
}, Ye = {
|
|
37
37
|
CLIENT_ID: "X-Auth-ClientId"
|
|
38
|
-
},
|
|
38
|
+
}, f = {
|
|
39
39
|
ALG: "RS256",
|
|
40
40
|
USER_ID_KEY: "sub",
|
|
41
41
|
TOKEN_ID_KEY: "__raw",
|
|
42
42
|
NONCE_KEY: "_nonce",
|
|
43
|
+
USERNAME_KEY: "username",
|
|
43
44
|
ISSUER: "gizmette.com"
|
|
44
45
|
}, Be = `-----BEGIN PUBLIC KEY-----
|
|
45
46
|
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAsF6i3Jd9fY/3COqCw/m7
|
|
@@ -53,7 +54,7 @@ awIDAQAB
|
|
|
53
54
|
AUTHENTICATE: "authenticate",
|
|
54
55
|
CODE: "code",
|
|
55
56
|
LOGOUT: "logout"
|
|
56
|
-
}, G = crypto, Ae = (e) => e instanceof CryptoKey,
|
|
57
|
+
}, G = crypto, Ae = (e) => e instanceof CryptoKey, N = new TextEncoder(), q = new TextDecoder();
|
|
57
58
|
function Fe(...e) {
|
|
58
59
|
const t = e.reduce((n, { length: s }) => n + s, 0), r = new Uint8Array(t);
|
|
59
60
|
let a = 0;
|
|
@@ -92,7 +93,7 @@ class g extends C {
|
|
|
92
93
|
super(t), this.code = "ERR_JWT_CLAIM_VALIDATION_FAILED", this.claim = a, this.reason = n, this.payload = r;
|
|
93
94
|
}
|
|
94
95
|
}
|
|
95
|
-
class
|
|
96
|
+
class ie extends C {
|
|
96
97
|
static get code() {
|
|
97
98
|
return "ERR_JWT_EXPIRED";
|
|
98
99
|
}
|
|
@@ -232,7 +233,7 @@ function _e(e, t, ...r) {
|
|
|
232
233
|
r.length === 2 ? e += `one of type ${r[0]} or ${r[1]}.` : e += `of type ${r[0]}.`;
|
|
233
234
|
return t == null ? e += ` Received ${t}` : typeof t == "function" && t.name ? e += ` Received function ${t.name}` : typeof t == "object" && t != null && (a = t.constructor) != null && a.name && (e += ` Received an instance of ${t.constructor.name}`), e;
|
|
234
235
|
}
|
|
235
|
-
const
|
|
236
|
+
const ce = (e, ...t) => _e("Key must be ", e, ...t);
|
|
236
237
|
function ve(e, t, ...r) {
|
|
237
238
|
return _e(`Key for the ${e} algorithm must be `, t, ...r);
|
|
238
239
|
}
|
|
@@ -358,25 +359,25 @@ const nt = async (e) => {
|
|
|
358
359
|
return delete n.alg, delete n.use, G.subtle.importKey("jwk", n, ...a);
|
|
359
360
|
}, ke = (e) => M(e);
|
|
360
361
|
let Q, Z;
|
|
361
|
-
const
|
|
362
|
+
const Re = (e) => (e == null ? void 0 : e[Symbol.toStringTag]) === "KeyObject", Ie = async (e, t, r, a) => {
|
|
362
363
|
let n = e.get(t);
|
|
363
364
|
if (n != null && n[a])
|
|
364
365
|
return n[a];
|
|
365
366
|
const s = await nt({ ...r, alg: a });
|
|
366
367
|
return n ? n[a] = s : e.set(t, { [a]: s }), s;
|
|
367
368
|
}, ot = (e, t) => {
|
|
368
|
-
if (
|
|
369
|
+
if (Re(e)) {
|
|
369
370
|
let r = e.export({ format: "jwk" });
|
|
370
|
-
return delete r.d, delete r.dp, delete r.dq, delete r.p, delete r.q, delete r.qi, r.k ? ke(r.k) : (Z || (Z = /* @__PURE__ */ new WeakMap()),
|
|
371
|
+
return delete r.d, delete r.dp, delete r.dq, delete r.p, delete r.q, delete r.qi, r.k ? ke(r.k) : (Z || (Z = /* @__PURE__ */ new WeakMap()), Ie(Z, e, r, t));
|
|
371
372
|
}
|
|
372
373
|
return e;
|
|
373
374
|
}, st = (e, t) => {
|
|
374
|
-
if (
|
|
375
|
+
if (Re(e)) {
|
|
375
376
|
let r = e.export({ format: "jwk" });
|
|
376
|
-
return r.k ? ke(r.k) : (Q || (Q = /* @__PURE__ */ new WeakMap()),
|
|
377
|
+
return r.k ? ke(r.k) : (Q || (Q = /* @__PURE__ */ new WeakMap()), Ie(Q, e, r, t));
|
|
377
378
|
}
|
|
378
379
|
return e;
|
|
379
|
-
},
|
|
380
|
+
}, it = { normalizePublicKey: ot, normalizePrivateKey: st }, v = (e, t, r = 0) => {
|
|
380
381
|
r === 0 && (t.unshift(t.length), t.unshift(6));
|
|
381
382
|
const a = e.indexOf(t[0], r);
|
|
382
383
|
if (a === -1)
|
|
@@ -402,9 +403,9 @@ const Ie = (e) => (e == null ? void 0 : e[Symbol.toStringTag]) === "KeyObject",
|
|
|
402
403
|
default:
|
|
403
404
|
throw new T("Invalid or unsupported EC Key Curve or OKP Key Sub Type");
|
|
404
405
|
}
|
|
405
|
-
},
|
|
406
|
+
}, ct = async (e, t, r, a, n) => {
|
|
406
407
|
let s, o;
|
|
407
|
-
const
|
|
408
|
+
const c = new Uint8Array(atob(r.replace(e, "")).split("").map((i) => i.charCodeAt(0)));
|
|
408
409
|
switch (a) {
|
|
409
410
|
case "PS256":
|
|
410
411
|
case "PS384":
|
|
@@ -438,18 +439,18 @@ const Ie = (e) => (e == null ? void 0 : e[Symbol.toStringTag]) === "KeyObject",
|
|
|
438
439
|
case "ECDH-ES+A128KW":
|
|
439
440
|
case "ECDH-ES+A192KW":
|
|
440
441
|
case "ECDH-ES+A256KW": {
|
|
441
|
-
const
|
|
442
|
-
s =
|
|
442
|
+
const i = ue(c);
|
|
443
|
+
s = i.startsWith("P-") ? { name: "ECDH", namedCurve: i } : { name: i }, o = [];
|
|
443
444
|
break;
|
|
444
445
|
}
|
|
445
446
|
case "EdDSA":
|
|
446
|
-
s = { name: ue(
|
|
447
|
+
s = { name: ue(c) }, o = ["verify"];
|
|
447
448
|
break;
|
|
448
449
|
default:
|
|
449
450
|
throw new T('Invalid or unsupported "alg" (Algorithm) value');
|
|
450
451
|
}
|
|
451
|
-
return G.subtle.importKey(t,
|
|
452
|
-
}, ut = (e, t, r) =>
|
|
452
|
+
return G.subtle.importKey(t, c, s, !1, o);
|
|
453
|
+
}, ut = (e, t, r) => ct(/(?:-----(?:BEGIN|END) PUBLIC KEY-----|\s)/g, "spki", e, t);
|
|
453
454
|
async function dt(e, t, r) {
|
|
454
455
|
if (e.indexOf("-----BEGIN PUBLIC KEY-----") !== 0)
|
|
455
456
|
throw new TypeError('"spki" must be SPKI formatted string');
|
|
@@ -525,16 +526,16 @@ function mt(e, t) {
|
|
|
525
526
|
}
|
|
526
527
|
}
|
|
527
528
|
async function wt(e, t, r) {
|
|
528
|
-
if (t = await
|
|
529
|
+
if (t = await it.normalizePublicKey(t, e), Ae(t))
|
|
529
530
|
return Ze(t, e, r), t;
|
|
530
531
|
if (t instanceof Uint8Array) {
|
|
531
532
|
if (!e.startsWith("HS"))
|
|
532
|
-
throw new TypeError(
|
|
533
|
+
throw new TypeError(ce(t, ...Y));
|
|
533
534
|
return G.subtle.importKey("raw", t, { hash: `SHA-${e.slice(-3)}`, name: "HMAC" }, !1, [r]);
|
|
534
535
|
}
|
|
535
|
-
throw new TypeError(
|
|
536
|
+
throw new TypeError(ce(t, ...Y, "Uint8Array"));
|
|
536
537
|
}
|
|
537
|
-
const
|
|
538
|
+
const Et = async (e, t, r, a) => {
|
|
538
539
|
const n = await wt(e, t, "verify");
|
|
539
540
|
rt(e, n);
|
|
540
541
|
const s = mt(e, n.algorithm);
|
|
@@ -544,7 +545,7 @@ const St = async (e, t, r, a) => {
|
|
|
544
545
|
return !1;
|
|
545
546
|
}
|
|
546
547
|
};
|
|
547
|
-
async function
|
|
548
|
+
async function St(e, t, r) {
|
|
548
549
|
if (!ne(e))
|
|
549
550
|
throw new h("Flattened JWS must be an object");
|
|
550
551
|
if (e.protected === void 0 && e.header === void 0)
|
|
@@ -560,8 +561,8 @@ async function Et(e, t, r) {
|
|
|
560
561
|
let a = {};
|
|
561
562
|
if (e.protected)
|
|
562
563
|
try {
|
|
563
|
-
const
|
|
564
|
-
a = JSON.parse(q.decode(
|
|
564
|
+
const w = M(e.protected);
|
|
565
|
+
a = JSON.parse(q.decode(w));
|
|
565
566
|
} catch {
|
|
566
567
|
throw new h("JWS Protected Header is invalid");
|
|
567
568
|
}
|
|
@@ -574,11 +575,11 @@ async function Et(e, t, r) {
|
|
|
574
575
|
let o = !0;
|
|
575
576
|
if (s.has("b64") && (o = a.b64, typeof o != "boolean"))
|
|
576
577
|
throw new h('The "b64" (base64url-encode payload) Header Parameter must be a boolean');
|
|
577
|
-
const { alg:
|
|
578
|
-
if (typeof
|
|
578
|
+
const { alg: c } = n;
|
|
579
|
+
if (typeof c != "string" || !c)
|
|
579
580
|
throw new h('JWS "alg" (Algorithm) Header Parameter missing or invalid');
|
|
580
|
-
const
|
|
581
|
-
if (
|
|
581
|
+
const i = r && ft("algorithms", r.algorithms);
|
|
582
|
+
if (i && !i.has(c))
|
|
582
583
|
throw new qe('"alg" (Algorithm) Header Parameter value not allowed');
|
|
583
584
|
if (o) {
|
|
584
585
|
if (typeof e.payload != "string")
|
|
@@ -586,15 +587,15 @@ async function Et(e, t, r) {
|
|
|
586
587
|
} else if (typeof e.payload != "string" && !(e.payload instanceof Uint8Array))
|
|
587
588
|
throw new h("JWS Payload must be a string or an Uint8Array instance");
|
|
588
589
|
let u = !1;
|
|
589
|
-
typeof t == "function" && (t = await t(a, e), u = !0), pt(
|
|
590
|
-
const
|
|
591
|
-
let
|
|
590
|
+
typeof t == "function" && (t = await t(a, e), u = !0), pt(c, t, "verify");
|
|
591
|
+
const m = Fe(N.encode(e.protected ?? ""), N.encode("."), typeof e.payload == "string" ? N.encode(e.payload) : e.payload);
|
|
592
|
+
let y;
|
|
592
593
|
try {
|
|
593
|
-
|
|
594
|
+
y = M(e.signature);
|
|
594
595
|
} catch {
|
|
595
596
|
throw new h("Failed to base64url decode the signature");
|
|
596
597
|
}
|
|
597
|
-
if (!await
|
|
598
|
+
if (!await Et(c, t, y, m))
|
|
598
599
|
throw new ze();
|
|
599
600
|
let _;
|
|
600
601
|
if (o)
|
|
@@ -604,9 +605,9 @@ async function Et(e, t, r) {
|
|
|
604
605
|
throw new h("Failed to base64url decode the payload");
|
|
605
606
|
}
|
|
606
607
|
else
|
|
607
|
-
typeof e.payload == "string" ? _ =
|
|
608
|
-
const
|
|
609
|
-
return e.protected !== void 0 && (
|
|
608
|
+
typeof e.payload == "string" ? _ = N.encode(e.payload) : _ = e.payload;
|
|
609
|
+
const E = { payload: _ };
|
|
610
|
+
return e.protected !== void 0 && (E.protectedHeader = a), e.header !== void 0 && (E.unprotectedHeader = e.header), u ? { ...E, key: t } : E;
|
|
610
611
|
}
|
|
611
612
|
async function gt(e, t, r) {
|
|
612
613
|
if (e instanceof Uint8Array && (e = q.decode(e)), typeof e != "string")
|
|
@@ -614,8 +615,8 @@ async function gt(e, t, r) {
|
|
|
614
615
|
const { 0: a, 1: n, 2: s, length: o } = e.split(".");
|
|
615
616
|
if (o !== 3)
|
|
616
617
|
throw new h("Invalid Compact JWS");
|
|
617
|
-
const
|
|
618
|
-
return typeof t == "function" ? { ...
|
|
618
|
+
const c = await St({ payload: n, protected: a, signature: s }, t, r), i = { payload: c.payload, protectedHeader: c.protectedHeader };
|
|
619
|
+
return typeof t == "function" ? { ...i, key: c.key } : i;
|
|
619
620
|
}
|
|
620
621
|
const At = (e) => Math.floor(e.getTime() / 1e3), Ce = 60, Pe = Ce * 60, oe = Pe * 24, bt = oe * 7, _t = oe * 365.25, vt = /^(\+|\-)? ?(\d+|\d+\.\d+) ?(seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)(?: (ago|from now))?$/i, de = (e) => {
|
|
621
622
|
const t = vt.exec(e);
|
|
@@ -671,56 +672,56 @@ const At = (e) => Math.floor(e.getTime() / 1e3), Ce = 60, Pe = Ce * 60, oe = Pe
|
|
|
671
672
|
const { typ: n } = r;
|
|
672
673
|
if (n && (typeof e.typ != "string" || le(e.typ) !== le(n)))
|
|
673
674
|
throw new g('unexpected "typ" JWT header value', a, "typ", "check_failed");
|
|
674
|
-
const { requiredClaims: s = [], issuer: o, subject:
|
|
675
|
-
u !== void 0 &&
|
|
676
|
-
for (const
|
|
677
|
-
if (!(
|
|
678
|
-
throw new g(`missing required "${
|
|
675
|
+
const { requiredClaims: s = [], issuer: o, subject: c, audience: i, maxTokenAge: u } = r, m = [...s];
|
|
676
|
+
u !== void 0 && m.push("iat"), i !== void 0 && m.push("aud"), c !== void 0 && m.push("sub"), o !== void 0 && m.push("iss");
|
|
677
|
+
for (const w of new Set(m.reverse()))
|
|
678
|
+
if (!(w in a))
|
|
679
|
+
throw new g(`missing required "${w}" claim`, a, w, "missing");
|
|
679
680
|
if (o && !(Array.isArray(o) ? o : [o]).includes(a.iss))
|
|
680
681
|
throw new g('unexpected "iss" claim value', a, "iss", "check_failed");
|
|
681
|
-
if (
|
|
682
|
+
if (c && a.sub !== c)
|
|
682
683
|
throw new g('unexpected "sub" claim value', a, "sub", "check_failed");
|
|
683
|
-
if (
|
|
684
|
+
if (i && !Tt(a.aud, typeof i == "string" ? [i] : i))
|
|
684
685
|
throw new g('unexpected "aud" claim value', a, "aud", "check_failed");
|
|
685
|
-
let
|
|
686
|
+
let y;
|
|
686
687
|
switch (typeof r.clockTolerance) {
|
|
687
688
|
case "string":
|
|
688
|
-
|
|
689
|
+
y = de(r.clockTolerance);
|
|
689
690
|
break;
|
|
690
691
|
case "number":
|
|
691
|
-
|
|
692
|
+
y = r.clockTolerance;
|
|
692
693
|
break;
|
|
693
694
|
case "undefined":
|
|
694
|
-
|
|
695
|
+
y = 0;
|
|
695
696
|
break;
|
|
696
697
|
default:
|
|
697
698
|
throw new TypeError("Invalid clockTolerance option type");
|
|
698
699
|
}
|
|
699
|
-
const { currentDate: _ } = r,
|
|
700
|
+
const { currentDate: _ } = r, E = At(_ || /* @__PURE__ */ new Date());
|
|
700
701
|
if ((a.iat !== void 0 || u) && typeof a.iat != "number")
|
|
701
702
|
throw new g('"iat" claim must be a number', a, "iat", "invalid");
|
|
702
703
|
if (a.nbf !== void 0) {
|
|
703
704
|
if (typeof a.nbf != "number")
|
|
704
705
|
throw new g('"nbf" claim must be a number', a, "nbf", "invalid");
|
|
705
|
-
if (a.nbf >
|
|
706
|
+
if (a.nbf > E + y)
|
|
706
707
|
throw new g('"nbf" claim timestamp check failed', a, "nbf", "check_failed");
|
|
707
708
|
}
|
|
708
709
|
if (a.exp !== void 0) {
|
|
709
710
|
if (typeof a.exp != "number")
|
|
710
711
|
throw new g('"exp" claim must be a number', a, "exp", "invalid");
|
|
711
|
-
if (a.exp <=
|
|
712
|
-
throw new
|
|
712
|
+
if (a.exp <= E - y)
|
|
713
|
+
throw new ie('"exp" claim timestamp check failed', a, "exp", "check_failed");
|
|
713
714
|
}
|
|
714
715
|
if (u) {
|
|
715
|
-
const
|
|
716
|
-
if (
|
|
717
|
-
throw new
|
|
718
|
-
if (
|
|
716
|
+
const w = E - a.iat, k = typeof u == "number" ? u : de(u);
|
|
717
|
+
if (w - y > k)
|
|
718
|
+
throw new ie('"iat" claim timestamp check failed (too far in the past)', a, "iat", "check_failed");
|
|
719
|
+
if (w < 0 - y)
|
|
719
720
|
throw new g('"iat" claim timestamp check failed (it should be in the past)', a, "iat", "check_failed");
|
|
720
721
|
}
|
|
721
722
|
return a;
|
|
722
723
|
};
|
|
723
|
-
async function
|
|
724
|
+
async function Rt(e, t, r) {
|
|
724
725
|
var a;
|
|
725
726
|
const n = await gt(e, t, r);
|
|
726
727
|
if ((a = n.protectedHeader.crit) != null && a.includes("b64") && n.protectedHeader.b64 === !1)
|
|
@@ -730,9 +731,9 @@ async function It(e, t, r) {
|
|
|
730
731
|
}
|
|
731
732
|
const H = async (e) => {
|
|
732
733
|
try {
|
|
733
|
-
const t =
|
|
734
|
-
return await
|
|
735
|
-
issuer:
|
|
734
|
+
const t = f.ALG, r = await dt(Be, t);
|
|
735
|
+
return await Rt(e, r, {
|
|
736
|
+
issuer: f.ISSUER
|
|
736
737
|
});
|
|
737
738
|
} catch {
|
|
738
739
|
return;
|
|
@@ -741,7 +742,7 @@ const H = async (e) => {
|
|
|
741
742
|
var d = [];
|
|
742
743
|
for (var ee = 0; ee < 256; ++ee)
|
|
743
744
|
d.push((ee + 256).toString(16).slice(1));
|
|
744
|
-
function
|
|
745
|
+
function It(e, t = 0) {
|
|
745
746
|
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();
|
|
746
747
|
}
|
|
747
748
|
var L, Ct = new Uint8Array(16);
|
|
@@ -759,7 +760,7 @@ function pe(e, t, r) {
|
|
|
759
760
|
return he.randomUUID();
|
|
760
761
|
e = e || {};
|
|
761
762
|
var a = e.random || (e.rng || Pt)();
|
|
762
|
-
return a[6] = a[6] & 15 | 64, a[8] = a[8] & 63 | 128,
|
|
763
|
+
return a[6] = a[6] & 15 | 64, a[8] = a[8] & 63 | 128, It(a);
|
|
763
764
|
}
|
|
764
765
|
const ye = globalThis.crypto, Dt = (e) => `${pe()}${pe()}`.slice(0, e), Ut = (e) => btoa(
|
|
765
766
|
[...new Uint8Array(e)].map((t) => String.fromCharCode(t)).join("")
|
|
@@ -772,7 +773,7 @@ async function Ht(e) {
|
|
|
772
773
|
const t = new TextEncoder().encode(e), r = await ye.subtle.digest("SHA-256", t);
|
|
773
774
|
return Ut(r).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
774
775
|
}
|
|
775
|
-
async function
|
|
776
|
+
async function Kt(e) {
|
|
776
777
|
const r = Dt(43), a = await Ht(r);
|
|
777
778
|
return {
|
|
778
779
|
code_verifier: r,
|
|
@@ -787,7 +788,7 @@ const fe = (e, t) => {
|
|
|
787
788
|
typeof t == "function" ? t() : t
|
|
788
789
|
);
|
|
789
790
|
window.localStorage.setItem(e, r), Oe(e, r);
|
|
790
|
-
},
|
|
791
|
+
}, Nt = (e) => {
|
|
791
792
|
window.localStorage.removeItem(e), Oe(e, null);
|
|
792
793
|
}, me = (e) => window.localStorage.getItem(e), $t = (e) => (window.addEventListener("storage", e), () => window.removeEventListener("storage", e));
|
|
793
794
|
function W({
|
|
@@ -798,12 +799,12 @@ function W({
|
|
|
798
799
|
$t,
|
|
799
800
|
r
|
|
800
801
|
), n = D.useCallback(
|
|
801
|
-
(
|
|
802
|
+
(c) => {
|
|
802
803
|
try {
|
|
803
|
-
const
|
|
804
|
-
|
|
805
|
-
} catch (
|
|
806
|
-
console.warn(
|
|
804
|
+
const i = typeof c == "function" ? c(JSON.parse(a)) : c;
|
|
805
|
+
i == null ? Nt(e) : fe(e, i);
|
|
806
|
+
} catch (i) {
|
|
807
|
+
console.warn(i);
|
|
807
808
|
}
|
|
808
809
|
},
|
|
809
810
|
[e, a]
|
|
@@ -815,8 +816,8 @@ function W({
|
|
|
815
816
|
return D.useEffect(() => {
|
|
816
817
|
try {
|
|
817
818
|
me(e) === null && typeof t < "u" && fe(e, t);
|
|
818
|
-
} catch (
|
|
819
|
-
console.warn(
|
|
819
|
+
} catch (c) {
|
|
820
|
+
console.warn(c);
|
|
820
821
|
}
|
|
821
822
|
}, [e, t]), [a ? JSON.parse(a) : null, n, s, o];
|
|
822
823
|
}
|
|
@@ -843,7 +844,7 @@ function jt(e, t, r) {
|
|
|
843
844
|
var a = e.random || (e.rng || Jt)();
|
|
844
845
|
return a[6] = a[6] & 15 | 64, a[8] = a[8] & 63 | 128, Lt(a);
|
|
845
846
|
}
|
|
846
|
-
const re = "Oops! It looks like your session has expired. For your security, please log in again to continue.", Mt = "Your session has been successfully terminated.",
|
|
847
|
+
const re = "Oops! It looks like your session has expired. For your security, please log in again to continue.", Mt = "Your session has been successfully terminated.", Ee = "Login failed. Please try again.", U = "Error getting access token, please re-authenticate.", Vt = "You forgot to wrap your component in <AuthProvider>.", Se = {
|
|
847
848
|
dev: "https://auth.gizmette.local.com:3003",
|
|
848
849
|
prod: "https://mylogin.gizmette.com"
|
|
849
850
|
}, x = "@@auth@@", Yt = process.env.NODE_ENV === "production", Bt = !Yt, z = async ({
|
|
@@ -853,7 +854,7 @@ const re = "Oops! It looks like your session has expired. For your security, ple
|
|
|
853
854
|
}) => {
|
|
854
855
|
try {
|
|
855
856
|
const a = await fetch(
|
|
856
|
-
Bt ? `${
|
|
857
|
+
Bt ? `${Se.dev}/${e}` : `${Se.prod}/${e}`,
|
|
857
858
|
{
|
|
858
859
|
credentials: "include",
|
|
859
860
|
method: "POST",
|
|
@@ -906,10 +907,10 @@ const re = "Oops! It looks like your session has expired. For your security, ple
|
|
|
906
907
|
type: n,
|
|
907
908
|
sessionExpiration: s,
|
|
908
909
|
code: o,
|
|
909
|
-
code_verifier:
|
|
910
|
+
code_verifier: c
|
|
910
911
|
}) => {
|
|
911
912
|
try {
|
|
912
|
-
const
|
|
913
|
+
const i = await z({
|
|
913
914
|
type: F.AUTHENTICATE,
|
|
914
915
|
clientId: r,
|
|
915
916
|
params: {
|
|
@@ -919,14 +920,14 @@ const re = "Oops! It looks like your session has expired. For your security, ple
|
|
|
919
920
|
sessionExpiration: s,
|
|
920
921
|
nonce: a,
|
|
921
922
|
code: o,
|
|
922
|
-
code_verifier:
|
|
923
|
+
code_verifier: c
|
|
923
924
|
}
|
|
924
|
-
}), u = await H(
|
|
925
|
-
return u && u.payload[
|
|
926
|
-
idToken:
|
|
927
|
-
accessToken:
|
|
928
|
-
refreshToken:
|
|
929
|
-
userId: u.payload[
|
|
925
|
+
}), u = await H(i.data.idToken);
|
|
926
|
+
return u && u.payload[f.USER_ID_KEY] !== "" && u.payload[f.NONCE_KEY] === a ? {
|
|
927
|
+
idToken: i.data.idToken,
|
|
928
|
+
accessToken: i.data.accessToken,
|
|
929
|
+
refreshToken: i.data.refreshToken,
|
|
930
|
+
userId: u.payload[f.USER_ID_KEY],
|
|
930
931
|
status: !0
|
|
931
932
|
} : {
|
|
932
933
|
status: !1
|
|
@@ -981,10 +982,10 @@ const re = "Oops! It looks like your session has expired. For your security, ple
|
|
|
981
982
|
accessToken: n
|
|
982
983
|
}
|
|
983
984
|
}), o = await H(s.data.accessToken);
|
|
984
|
-
return o && o.payload[
|
|
985
|
+
return o && o.payload[f.USER_ID_KEY] !== "" && o.payload[f.NONCE_KEY] === r ? {
|
|
985
986
|
accessToken: s.data.accessToken,
|
|
986
987
|
refreshToken: s.data.refreshToken,
|
|
987
|
-
userId: o.payload[
|
|
988
|
+
userId: o.payload[f.USER_ID_KEY],
|
|
988
989
|
status: !0
|
|
989
990
|
} : {
|
|
990
991
|
status: !1
|
|
@@ -1011,38 +1012,41 @@ const re = "Oops! It looks like your session has expired. For your security, ple
|
|
|
1011
1012
|
}) => {
|
|
1012
1013
|
const [a, n, , s] = W({
|
|
1013
1014
|
key: `${x}::${r}::@@user@@`
|
|
1014
|
-
}), [o,
|
|
1015
|
+
}), [o, c, , i] = W({
|
|
1015
1016
|
key: `${x}::${r}::@@access@@`
|
|
1016
|
-
}), [u,
|
|
1017
|
+
}), [u, m, , y] = W(
|
|
1017
1018
|
{
|
|
1018
1019
|
key: `${x}::${r}::@@refresh@@`
|
|
1019
1020
|
}
|
|
1020
|
-
), [_,
|
|
1021
|
+
), [_, E, , w] = W({
|
|
1021
1022
|
key: `${x}::${r}::@@nonce@@`
|
|
1022
|
-
}), [k,
|
|
1023
|
+
}), [k, K] = xe({
|
|
1023
1024
|
isLoading: !0,
|
|
1024
1025
|
isAuthenticated: !1,
|
|
1025
|
-
|
|
1026
|
+
user: void 0,
|
|
1026
1027
|
logoutReason: ""
|
|
1027
1028
|
}), A = je(
|
|
1028
|
-
(
|
|
1029
|
-
|
|
1029
|
+
(p) => {
|
|
1030
|
+
K({
|
|
1030
1031
|
isLoading: !1,
|
|
1031
1032
|
isAuthenticated: !1,
|
|
1032
|
-
|
|
1033
|
-
logoutReason:
|
|
1034
|
-
}), s(),
|
|
1033
|
+
user: void 0,
|
|
1034
|
+
logoutReason: p || re
|
|
1035
|
+
}), s(), i(), y(), w();
|
|
1035
1036
|
},
|
|
1036
|
-
[s,
|
|
1037
|
+
[s, i, w, y]
|
|
1037
1038
|
);
|
|
1038
1039
|
Me(() => {
|
|
1039
1040
|
k.isLoading && a !== null && (async () => {
|
|
1040
1041
|
try {
|
|
1041
|
-
const
|
|
1042
|
-
|
|
1042
|
+
const p = await H(a);
|
|
1043
|
+
p && p.payload[f.USER_ID_KEY] !== "" ? K({
|
|
1043
1044
|
isLoading: !1,
|
|
1044
1045
|
isAuthenticated: !0,
|
|
1045
|
-
|
|
1046
|
+
user: {
|
|
1047
|
+
userId: p.payload[f.USER_ID_KEY],
|
|
1048
|
+
username: p.payload[f.USERNAME_KEY]
|
|
1049
|
+
},
|
|
1046
1050
|
logoutReason: ""
|
|
1047
1051
|
}) : (A(re), await ae({
|
|
1048
1052
|
idToken: a,
|
|
@@ -1067,47 +1071,53 @@ const re = "Oops! It looks like your session has expired. For your security, ple
|
|
|
1067
1071
|
r,
|
|
1068
1072
|
A
|
|
1069
1073
|
]);
|
|
1070
|
-
const Ue = async (
|
|
1071
|
-
const
|
|
1072
|
-
if (
|
|
1073
|
-
const { code_verifier: $e, code_challenge: Le } = await
|
|
1074
|
-
nonce:
|
|
1074
|
+
const Ue = async (p, P, R) => {
|
|
1075
|
+
const I = jt();
|
|
1076
|
+
if (E(I), R === B.CODE) {
|
|
1077
|
+
const { code_verifier: $e, code_challenge: Le } = await Kt(), se = await Ft({
|
|
1078
|
+
nonce: I,
|
|
1075
1079
|
clientId: r,
|
|
1076
1080
|
code_challenge: Le
|
|
1077
1081
|
});
|
|
1078
1082
|
if (se.status) {
|
|
1079
1083
|
const O = await ge({
|
|
1080
|
-
username:
|
|
1084
|
+
username: p,
|
|
1081
1085
|
password: P,
|
|
1082
1086
|
clientId: r,
|
|
1083
1087
|
sessionExpiration: t,
|
|
1084
|
-
nonce:
|
|
1085
|
-
type:
|
|
1088
|
+
nonce: I,
|
|
1089
|
+
type: R,
|
|
1086
1090
|
code: se.code,
|
|
1087
1091
|
code_verifier: $e
|
|
1088
1092
|
});
|
|
1089
|
-
return O.status ? (n(O.idToken),
|
|
1093
|
+
return O.status ? (n(O.idToken), c(O.accessToken), m(O.refreshToken), K({
|
|
1090
1094
|
isLoading: !1,
|
|
1091
1095
|
isAuthenticated: !0,
|
|
1092
|
-
|
|
1096
|
+
user: {
|
|
1097
|
+
userId: O.userId,
|
|
1098
|
+
username: p
|
|
1099
|
+
},
|
|
1093
1100
|
logoutReason: ""
|
|
1094
|
-
}), !0) : (A(
|
|
1101
|
+
}), !0) : (A(Ee), !1);
|
|
1095
1102
|
}
|
|
1096
1103
|
return !1;
|
|
1097
1104
|
}
|
|
1098
|
-
const
|
|
1099
|
-
username:
|
|
1105
|
+
const S = await ge({
|
|
1106
|
+
username: p,
|
|
1100
1107
|
password: P,
|
|
1101
1108
|
clientId: r,
|
|
1102
1109
|
sessionExpiration: t,
|
|
1103
|
-
nonce:
|
|
1104
|
-
type:
|
|
1110
|
+
nonce: I,
|
|
1111
|
+
type: R
|
|
1105
1112
|
});
|
|
1106
|
-
return
|
|
1113
|
+
return S.status ? (n(S.idToken), c(S.accessToken), m(S.refreshToken), K({
|
|
1107
1114
|
isLoading: !1,
|
|
1108
1115
|
isAuthenticated: !0,
|
|
1109
|
-
|
|
1110
|
-
|
|
1116
|
+
user: {
|
|
1117
|
+
userId: S.userId,
|
|
1118
|
+
username: p
|
|
1119
|
+
}
|
|
1120
|
+
}), !0) : (A(Ee), !1);
|
|
1111
1121
|
}, He = async () => {
|
|
1112
1122
|
A(Mt), await ae({
|
|
1113
1123
|
idToken: a,
|
|
@@ -1115,24 +1125,24 @@ const re = "Oops! It looks like your session has expired. For your security, ple
|
|
|
1115
1125
|
refreshToken: u,
|
|
1116
1126
|
clientId: r
|
|
1117
1127
|
});
|
|
1118
|
-
},
|
|
1119
|
-
const { isAuthenticated:
|
|
1128
|
+
}, Ke = async () => {
|
|
1129
|
+
const { isAuthenticated: p, user: P } = k;
|
|
1120
1130
|
try {
|
|
1121
|
-
if (
|
|
1122
|
-
const
|
|
1123
|
-
if (
|
|
1131
|
+
if (p && P && P.userId && o) {
|
|
1132
|
+
const R = await H(o);
|
|
1133
|
+
if (R && R.payload[f.USER_ID_KEY] !== "")
|
|
1124
1134
|
return o;
|
|
1125
|
-
const
|
|
1126
|
-
if (
|
|
1127
|
-
const
|
|
1135
|
+
const I = await H(u);
|
|
1136
|
+
if (I && I.payload[f.USER_ID_KEY] !== "") {
|
|
1137
|
+
const S = await Gt({
|
|
1128
1138
|
clientId: r,
|
|
1129
|
-
userId: P,
|
|
1139
|
+
userId: P.userId,
|
|
1130
1140
|
nonce: _,
|
|
1131
1141
|
refreshToken: u,
|
|
1132
1142
|
accessToken: o
|
|
1133
1143
|
});
|
|
1134
|
-
if (
|
|
1135
|
-
return
|
|
1144
|
+
if (S.status)
|
|
1145
|
+
return c(S.accessToken), m(S.refreshToken), S.accessToken;
|
|
1136
1146
|
A(U);
|
|
1137
1147
|
}
|
|
1138
1148
|
return A(U), console.error(U), "";
|
|
@@ -1140,14 +1150,14 @@ const re = "Oops! It looks like your session has expired. For your security, ple
|
|
|
1140
1150
|
} catch {
|
|
1141
1151
|
return A(U), console.error(U), "";
|
|
1142
1152
|
}
|
|
1143
|
-
},
|
|
1153
|
+
}, Ne = () => {
|
|
1144
1154
|
if (k.isAuthenticated && a)
|
|
1145
1155
|
return a;
|
|
1146
1156
|
};
|
|
1147
1157
|
return /* @__PURE__ */ We(
|
|
1148
1158
|
De.Provider,
|
|
1149
1159
|
{
|
|
1150
|
-
value: { ...k, login: Ue, logout: He, getAccessToken:
|
|
1160
|
+
value: { ...k, login: Ue, logout: He, getAccessToken: Ke, getIdToken: Ne },
|
|
1151
1161
|
children: e
|
|
1152
1162
|
}
|
|
1153
1163
|
);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@versini/auth-provider",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.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.10.
|
|
47
|
+
"@versini/auth-common": "2.10.1",
|
|
48
48
|
"@versini/ui-hooks": "4.0.0",
|
|
49
49
|
"jose": "5.6.2",
|
|
50
50
|
"uuid": "10.0.0"
|
|
51
51
|
},
|
|
52
|
-
"gitHead": "
|
|
52
|
+
"gitHead": "5a4130a33944cf31fe9bd4dd32207119bc27678d"
|
|
53
53
|
}
|