@versini/auth-provider 5.0.2 → 5.0.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.d.ts +1 -1
- package/dist/index.js +446 -428
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
import { jsx as
|
|
5
|
-
import * as
|
|
6
|
-
import { createContext as
|
|
1
|
+
var je = Object.defineProperty;
|
|
2
|
+
var Me = (e, t, r) => t in e ? je(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
|
|
3
|
+
var N = (e, t, r) => (Me(e, typeof t != "symbol" ? t + "" : t, r), r);
|
|
4
|
+
import { jsx as Ve } from "react/jsx-runtime";
|
|
5
|
+
import * as U from "react";
|
|
6
|
+
import { createContext as Ye, useRef as Be, useState as Fe, useCallback as Ge, useEffect as qe, useContext as ze } from "react";
|
|
7
7
|
/*!
|
|
8
|
-
@versini/auth-provider v5.0.
|
|
8
|
+
@versini/auth-provider v5.0.3
|
|
9
9
|
© 2024 gizmette.com
|
|
10
10
|
*/
|
|
11
11
|
try {
|
|
12
12
|
window.__VERSINI_AUTH_CLIENT__ || (window.__VERSINI_AUTH_CLIENT__ = {
|
|
13
|
-
version: "5.0.
|
|
14
|
-
buildTime: "07/
|
|
13
|
+
version: "5.0.3",
|
|
14
|
+
buildTime: "07/05/2024 10:27 AM EDT",
|
|
15
15
|
homepage: "https://github.com/aversini/auth-client",
|
|
16
16
|
license: "MIT"
|
|
17
17
|
});
|
|
@@ -24,28 +24,28 @@ try {
|
|
|
24
24
|
try {
|
|
25
25
|
window.__VERSINI_AUTH_COMMON__ || (window.__VERSINI_AUTH_COMMON__ = {
|
|
26
26
|
version: "2.10.1",
|
|
27
|
-
buildTime: "07/
|
|
27
|
+
buildTime: "07/05/2024 10:27 AM EDT",
|
|
28
28
|
homepage: "https://github.com/aversini/auth-client",
|
|
29
29
|
license: "MIT"
|
|
30
30
|
});
|
|
31
31
|
} catch {
|
|
32
32
|
}
|
|
33
|
-
const
|
|
33
|
+
const F = {
|
|
34
34
|
ID_TOKEN: "id_token",
|
|
35
35
|
ACCESS_TOKEN: "token",
|
|
36
36
|
ID_AND_ACCESS_TOKEN: "id_token token",
|
|
37
37
|
CODE: "code",
|
|
38
38
|
REFRESH_TOKEN: "refresh_token"
|
|
39
|
-
},
|
|
39
|
+
}, Xe = {
|
|
40
40
|
CLIENT_ID: "X-Auth-ClientId"
|
|
41
|
-
},
|
|
41
|
+
}, m = {
|
|
42
42
|
ALG: "RS256",
|
|
43
43
|
USER_ID_KEY: "sub",
|
|
44
44
|
TOKEN_ID_KEY: "__raw",
|
|
45
45
|
NONCE_KEY: "_nonce",
|
|
46
46
|
USERNAME_KEY: "username",
|
|
47
47
|
ISSUER: "gizmette.com"
|
|
48
|
-
},
|
|
48
|
+
}, Qe = `-----BEGIN PUBLIC KEY-----
|
|
49
49
|
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAsF6i3Jd9fY/3COqCw/m7
|
|
50
50
|
w5PKyTYLGAI2I6SIIdpe6i6DOCbEkmDz7LdVsBqwNtVi8gvWYIj+8ol6rU3qu1v5
|
|
51
51
|
i1Jd45GSK4kzkVdgCmQZbM5ak0KI99q5wsrAIzUd+LRJ2HRvWtr5IYdsIiXaQjle
|
|
@@ -53,33 +53,33 @@ aMwPFOIcJH+rKfFgNcHLcaS5syp7zU1ANwZ+trgR+DifBr8TLVkBynmNeTyhDm2+
|
|
|
53
53
|
l0haqjMk0UoNPPE8iYBWUHQJJE1Dqstj65d6Eh5g64Pao25y4cmYJbKjiblIGEkE
|
|
54
54
|
sjqybA9mARAqh9k/eiIopecWSiffNQTwVQVd2I9ZH3BalhEXHlqFgrjz51kFqg81
|
|
55
55
|
awIDAQAB
|
|
56
|
-
-----END PUBLIC KEY-----`,
|
|
56
|
+
-----END PUBLIC KEY-----`, G = {
|
|
57
57
|
AUTHENTICATE: "authenticate",
|
|
58
58
|
CODE: "code",
|
|
59
59
|
LOGOUT: "logout"
|
|
60
|
-
},
|
|
61
|
-
function
|
|
60
|
+
}, q = crypto, be = (e) => e instanceof CryptoKey, L = new TextEncoder(), z = new TextDecoder();
|
|
61
|
+
function Ze(...e) {
|
|
62
62
|
const t = e.reduce((n, { length: s }) => n + s, 0), r = new Uint8Array(t);
|
|
63
63
|
let a = 0;
|
|
64
64
|
for (const n of e)
|
|
65
65
|
r.set(n, a), a += n.length;
|
|
66
66
|
return r;
|
|
67
67
|
}
|
|
68
|
-
const
|
|
68
|
+
const et = (e) => {
|
|
69
69
|
const t = atob(e), r = new Uint8Array(t.length);
|
|
70
70
|
for (let a = 0; a < t.length; a++)
|
|
71
71
|
r[a] = t.charCodeAt(a);
|
|
72
72
|
return r;
|
|
73
|
-
},
|
|
73
|
+
}, V = (e) => {
|
|
74
74
|
let t = e;
|
|
75
|
-
t instanceof Uint8Array && (t =
|
|
75
|
+
t instanceof Uint8Array && (t = z.decode(t)), t = t.replace(/-/g, "+").replace(/_/g, "/").replace(/\s/g, "");
|
|
76
76
|
try {
|
|
77
|
-
return
|
|
77
|
+
return et(t);
|
|
78
78
|
} catch {
|
|
79
79
|
throw new TypeError("The input to be decoded is not correctly encoded.");
|
|
80
80
|
}
|
|
81
81
|
};
|
|
82
|
-
class
|
|
82
|
+
class C extends Error {
|
|
83
83
|
static get code() {
|
|
84
84
|
return "ERR_JOSE_GENERIC";
|
|
85
85
|
}
|
|
@@ -88,7 +88,7 @@ class R extends Error {
|
|
|
88
88
|
super(t), this.code = "ERR_JOSE_GENERIC", this.name = this.constructor.name, (r = Error.captureStackTrace) == null || r.call(Error, this, this.constructor);
|
|
89
89
|
}
|
|
90
90
|
}
|
|
91
|
-
class
|
|
91
|
+
class g extends C {
|
|
92
92
|
static get code() {
|
|
93
93
|
return "ERR_JWT_CLAIM_VALIDATION_FAILED";
|
|
94
94
|
}
|
|
@@ -96,7 +96,7 @@ class S extends R {
|
|
|
96
96
|
super(t), this.code = "ERR_JWT_CLAIM_VALIDATION_FAILED", this.claim = a, this.reason = n, this.payload = r;
|
|
97
97
|
}
|
|
98
98
|
}
|
|
99
|
-
class
|
|
99
|
+
class de extends C {
|
|
100
100
|
static get code() {
|
|
101
101
|
return "ERR_JWT_EXPIRED";
|
|
102
102
|
}
|
|
@@ -104,7 +104,7 @@ class ue extends R {
|
|
|
104
104
|
super(t), this.code = "ERR_JWT_EXPIRED", this.claim = a, this.reason = n, this.payload = r;
|
|
105
105
|
}
|
|
106
106
|
}
|
|
107
|
-
class
|
|
107
|
+
class tt extends C {
|
|
108
108
|
constructor() {
|
|
109
109
|
super(...arguments), this.code = "ERR_JOSE_ALG_NOT_ALLOWED";
|
|
110
110
|
}
|
|
@@ -112,14 +112,14 @@ class Ze extends R {
|
|
|
112
112
|
return "ERR_JOSE_ALG_NOT_ALLOWED";
|
|
113
113
|
}
|
|
114
114
|
}
|
|
115
|
-
let
|
|
115
|
+
let R = class extends C {
|
|
116
116
|
constructor() {
|
|
117
117
|
super(...arguments), this.code = "ERR_JOSE_NOT_SUPPORTED";
|
|
118
118
|
}
|
|
119
119
|
static get code() {
|
|
120
120
|
return "ERR_JOSE_NOT_SUPPORTED";
|
|
121
121
|
}
|
|
122
|
-
},
|
|
122
|
+
}, f = class extends C {
|
|
123
123
|
constructor() {
|
|
124
124
|
super(...arguments), this.code = "ERR_JWS_INVALID";
|
|
125
125
|
}
|
|
@@ -127,7 +127,7 @@ let _ = class extends R {
|
|
|
127
127
|
return "ERR_JWS_INVALID";
|
|
128
128
|
}
|
|
129
129
|
};
|
|
130
|
-
class
|
|
130
|
+
class _e extends C {
|
|
131
131
|
constructor() {
|
|
132
132
|
super(...arguments), this.code = "ERR_JWT_INVALID";
|
|
133
133
|
}
|
|
@@ -135,7 +135,7 @@ class be extends R {
|
|
|
135
135
|
return "ERR_JWT_INVALID";
|
|
136
136
|
}
|
|
137
137
|
}
|
|
138
|
-
class
|
|
138
|
+
class rt extends C {
|
|
139
139
|
constructor() {
|
|
140
140
|
super(...arguments), this.code = "ERR_JWS_SIGNATURE_VERIFICATION_FAILED", this.message = "signature verification failed";
|
|
141
141
|
}
|
|
@@ -143,16 +143,16 @@ class et extends R {
|
|
|
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 $(e, t) {
|
|
150
150
|
return e.name === t;
|
|
151
151
|
}
|
|
152
|
-
function
|
|
152
|
+
function Z(e) {
|
|
153
153
|
return parseInt(e.name.slice(4), 10);
|
|
154
154
|
}
|
|
155
|
-
function
|
|
155
|
+
function at(e) {
|
|
156
156
|
switch (e) {
|
|
157
157
|
case "ES256":
|
|
158
158
|
return "P-256";
|
|
@@ -164,7 +164,7 @@ function tt(e) {
|
|
|
164
164
|
throw new Error("unreachable");
|
|
165
165
|
}
|
|
166
166
|
}
|
|
167
|
-
function
|
|
167
|
+
function nt(e, t) {
|
|
168
168
|
if (t.length && !t.some((r) => e.usages.includes(r))) {
|
|
169
169
|
let r = "CryptoKey does not support this operation, its usages must include ";
|
|
170
170
|
if (t.length > 2) {
|
|
@@ -175,59 +175,59 @@ function rt(e, t) {
|
|
|
175
175
|
throw new TypeError(r);
|
|
176
176
|
}
|
|
177
177
|
}
|
|
178
|
-
function
|
|
178
|
+
function st(e, t, ...r) {
|
|
179
179
|
switch (t) {
|
|
180
180
|
case "HS256":
|
|
181
181
|
case "HS384":
|
|
182
182
|
case "HS512": {
|
|
183
183
|
if (!$(e.algorithm, "HMAC"))
|
|
184
|
-
throw
|
|
184
|
+
throw _("HMAC");
|
|
185
185
|
const a = parseInt(t.slice(2), 10);
|
|
186
|
-
if (
|
|
187
|
-
throw
|
|
186
|
+
if (Z(e.algorithm.hash) !== a)
|
|
187
|
+
throw _(`SHA-${a}`, "algorithm.hash");
|
|
188
188
|
break;
|
|
189
189
|
}
|
|
190
190
|
case "RS256":
|
|
191
191
|
case "RS384":
|
|
192
192
|
case "RS512": {
|
|
193
193
|
if (!$(e.algorithm, "RSASSA-PKCS1-v1_5"))
|
|
194
|
-
throw
|
|
194
|
+
throw _("RSASSA-PKCS1-v1_5");
|
|
195
195
|
const a = parseInt(t.slice(2), 10);
|
|
196
|
-
if (
|
|
197
|
-
throw
|
|
196
|
+
if (Z(e.algorithm.hash) !== a)
|
|
197
|
+
throw _(`SHA-${a}`, "algorithm.hash");
|
|
198
198
|
break;
|
|
199
199
|
}
|
|
200
200
|
case "PS256":
|
|
201
201
|
case "PS384":
|
|
202
202
|
case "PS512": {
|
|
203
203
|
if (!$(e.algorithm, "RSA-PSS"))
|
|
204
|
-
throw
|
|
204
|
+
throw _("RSA-PSS");
|
|
205
205
|
const a = parseInt(t.slice(2), 10);
|
|
206
|
-
if (
|
|
207
|
-
throw
|
|
206
|
+
if (Z(e.algorithm.hash) !== a)
|
|
207
|
+
throw _(`SHA-${a}`, "algorithm.hash");
|
|
208
208
|
break;
|
|
209
209
|
}
|
|
210
210
|
case "EdDSA": {
|
|
211
211
|
if (e.algorithm.name !== "Ed25519" && e.algorithm.name !== "Ed448")
|
|
212
|
-
throw
|
|
212
|
+
throw _("Ed25519 or Ed448");
|
|
213
213
|
break;
|
|
214
214
|
}
|
|
215
215
|
case "ES256":
|
|
216
216
|
case "ES384":
|
|
217
217
|
case "ES512": {
|
|
218
218
|
if (!$(e.algorithm, "ECDSA"))
|
|
219
|
-
throw
|
|
220
|
-
const a =
|
|
219
|
+
throw _("ECDSA");
|
|
220
|
+
const a = at(t);
|
|
221
221
|
if (e.algorithm.namedCurve !== a)
|
|
222
|
-
throw
|
|
222
|
+
throw _(a, "algorithm.namedCurve");
|
|
223
223
|
break;
|
|
224
224
|
}
|
|
225
225
|
default:
|
|
226
226
|
throw new TypeError("CryptoKey does not support this operation");
|
|
227
227
|
}
|
|
228
|
-
|
|
228
|
+
nt(e, r);
|
|
229
229
|
}
|
|
230
|
-
function
|
|
230
|
+
function ve(e, t, ...r) {
|
|
231
231
|
var a;
|
|
232
232
|
if (r.length > 2) {
|
|
233
233
|
const n = r.pop();
|
|
@@ -236,11 +236,11 @@ function _e(e, t, ...r) {
|
|
|
236
236
|
r.length === 2 ? e += `one of type ${r[0]} or ${r[1]}.` : e += `of type ${r[0]}.`;
|
|
237
237
|
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;
|
|
238
238
|
}
|
|
239
|
-
const
|
|
240
|
-
function
|
|
241
|
-
return
|
|
239
|
+
const le = (e, ...t) => ve("Key must be ", e, ...t);
|
|
240
|
+
function Re(e, t, ...r) {
|
|
241
|
+
return ve(`Key for the ${e} algorithm must be `, t, ...r);
|
|
242
242
|
}
|
|
243
|
-
const
|
|
243
|
+
const Ie = (e) => be(e) ? !0 : (e == null ? void 0 : e[Symbol.toStringTag]) === "KeyObject", B = ["CryptoKey"], ot = (...e) => {
|
|
244
244
|
const t = e.filter(Boolean);
|
|
245
245
|
if (t.length === 0 || t.length === 1)
|
|
246
246
|
return !0;
|
|
@@ -259,11 +259,11 @@ const Re = (e) => ke(e) ? !0 : (e == null ? void 0 : e[Symbol.toStringTag]) ===
|
|
|
259
259
|
}
|
|
260
260
|
return !0;
|
|
261
261
|
};
|
|
262
|
-
function
|
|
262
|
+
function it(e) {
|
|
263
263
|
return typeof e == "object" && e !== null;
|
|
264
264
|
}
|
|
265
|
-
function
|
|
266
|
-
if (!
|
|
265
|
+
function ie(e) {
|
|
266
|
+
if (!it(e) || Object.prototype.toString.call(e) !== "[object Object]")
|
|
267
267
|
return !1;
|
|
268
268
|
if (Object.getPrototypeOf(e) === null)
|
|
269
269
|
return !0;
|
|
@@ -272,14 +272,14 @@ function oe(e) {
|
|
|
272
272
|
t = Object.getPrototypeOf(t);
|
|
273
273
|
return Object.getPrototypeOf(e) === t;
|
|
274
274
|
}
|
|
275
|
-
const
|
|
275
|
+
const ct = (e, t) => {
|
|
276
276
|
if (e.startsWith("RS") || e.startsWith("PS")) {
|
|
277
277
|
const { modulusLength: r } = t.algorithm;
|
|
278
278
|
if (typeof r != "number" || r < 2048)
|
|
279
279
|
throw new TypeError(`${e} requires key modulusLength to be 2048 bits or larger`);
|
|
280
280
|
}
|
|
281
281
|
};
|
|
282
|
-
function
|
|
282
|
+
function ut(e) {
|
|
283
283
|
let t, r;
|
|
284
284
|
switch (e.kty) {
|
|
285
285
|
case "RSA": {
|
|
@@ -304,7 +304,7 @@ function it(e) {
|
|
|
304
304
|
}, r = e.d ? ["decrypt", "unwrapKey"] : ["encrypt", "wrapKey"];
|
|
305
305
|
break;
|
|
306
306
|
default:
|
|
307
|
-
throw new
|
|
307
|
+
throw new R('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
|
|
308
308
|
}
|
|
309
309
|
break;
|
|
310
310
|
}
|
|
@@ -326,7 +326,7 @@ function it(e) {
|
|
|
326
326
|
t = { name: "ECDH", namedCurve: e.crv }, r = e.d ? ["deriveBits"] : [];
|
|
327
327
|
break;
|
|
328
328
|
default:
|
|
329
|
-
throw new
|
|
329
|
+
throw new R('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
|
|
330
330
|
}
|
|
331
331
|
break;
|
|
332
332
|
}
|
|
@@ -342,73 +342,73 @@ function it(e) {
|
|
|
342
342
|
t = { name: e.crv }, r = e.d ? ["deriveBits"] : [];
|
|
343
343
|
break;
|
|
344
344
|
default:
|
|
345
|
-
throw new
|
|
345
|
+
throw new R('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
|
|
346
346
|
}
|
|
347
347
|
break;
|
|
348
348
|
}
|
|
349
349
|
default:
|
|
350
|
-
throw new
|
|
350
|
+
throw new R('Invalid or unsupported JWK "kty" (Key Type) Parameter value');
|
|
351
351
|
}
|
|
352
352
|
return { algorithm: t, keyUsages: r };
|
|
353
353
|
}
|
|
354
|
-
const
|
|
354
|
+
const dt = async (e) => {
|
|
355
355
|
if (!e.alg)
|
|
356
356
|
throw new TypeError('"alg" argument is required when "jwk.alg" is not present');
|
|
357
|
-
const { algorithm: t, keyUsages: r } =
|
|
357
|
+
const { algorithm: t, keyUsages: r } = ut(e), a = [
|
|
358
358
|
t,
|
|
359
359
|
e.ext ?? !1,
|
|
360
360
|
e.key_ops ?? r
|
|
361
361
|
], n = { ...e };
|
|
362
|
-
return delete n.alg, delete n.use,
|
|
363
|
-
},
|
|
364
|
-
let
|
|
365
|
-
const
|
|
362
|
+
return delete n.alg, delete n.use, q.subtle.importKey("jwk", n, ...a);
|
|
363
|
+
}, Ce = (e) => V(e);
|
|
364
|
+
let ee, te;
|
|
365
|
+
const Pe = (e) => (e == null ? void 0 : e[Symbol.toStringTag]) === "KeyObject", Oe = async (e, t, r, a) => {
|
|
366
366
|
let n = e.get(t);
|
|
367
367
|
if (n != null && n[a])
|
|
368
368
|
return n[a];
|
|
369
|
-
const s = await
|
|
369
|
+
const s = await dt({ ...r, alg: a });
|
|
370
370
|
return n ? n[a] = s : e.set(t, { [a]: s }), s;
|
|
371
|
-
},
|
|
372
|
-
if (
|
|
371
|
+
}, lt = (e, t) => {
|
|
372
|
+
if (Pe(e)) {
|
|
373
373
|
let r = e.export({ format: "jwk" });
|
|
374
|
-
return delete r.d, delete r.dp, delete r.dq, delete r.p, delete r.q, delete r.qi, r.k ?
|
|
374
|
+
return delete r.d, delete r.dp, delete r.dq, delete r.p, delete r.q, delete r.qi, r.k ? Ce(r.k) : (te || (te = /* @__PURE__ */ new WeakMap()), Oe(te, e, r, t));
|
|
375
375
|
}
|
|
376
376
|
return e;
|
|
377
|
-
},
|
|
378
|
-
if (
|
|
377
|
+
}, ht = (e, t) => {
|
|
378
|
+
if (Pe(e)) {
|
|
379
379
|
let r = e.export({ format: "jwk" });
|
|
380
|
-
return r.k ?
|
|
380
|
+
return r.k ? Ce(r.k) : (ee || (ee = /* @__PURE__ */ new WeakMap()), Oe(ee, e, r, t));
|
|
381
381
|
}
|
|
382
382
|
return e;
|
|
383
|
-
},
|
|
383
|
+
}, ft = { normalizePublicKey: lt, normalizePrivateKey: ht }, v = (e, t, r = 0) => {
|
|
384
384
|
r === 0 && (t.unshift(t.length), t.unshift(6));
|
|
385
385
|
const a = e.indexOf(t[0], r);
|
|
386
386
|
if (a === -1)
|
|
387
387
|
return !1;
|
|
388
388
|
const n = e.subarray(a, a + t.length);
|
|
389
|
-
return n.length !== t.length ? !1 : n.every((s, o) => s === t[o]) ||
|
|
390
|
-
},
|
|
389
|
+
return n.length !== t.length ? !1 : n.every((s, o) => s === t[o]) || v(e, t, a + 1);
|
|
390
|
+
}, he = (e) => {
|
|
391
391
|
switch (!0) {
|
|
392
|
-
case
|
|
392
|
+
case v(e, [42, 134, 72, 206, 61, 3, 1, 7]):
|
|
393
393
|
return "P-256";
|
|
394
|
-
case
|
|
394
|
+
case v(e, [43, 129, 4, 0, 34]):
|
|
395
395
|
return "P-384";
|
|
396
|
-
case
|
|
396
|
+
case v(e, [43, 129, 4, 0, 35]):
|
|
397
397
|
return "P-521";
|
|
398
|
-
case
|
|
398
|
+
case v(e, [43, 101, 110]):
|
|
399
399
|
return "X25519";
|
|
400
|
-
case
|
|
400
|
+
case v(e, [43, 101, 111]):
|
|
401
401
|
return "X448";
|
|
402
|
-
case
|
|
402
|
+
case v(e, [43, 101, 112]):
|
|
403
403
|
return "Ed25519";
|
|
404
|
-
case
|
|
404
|
+
case v(e, [43, 101, 113]):
|
|
405
405
|
return "Ed448";
|
|
406
406
|
default:
|
|
407
|
-
throw new
|
|
407
|
+
throw new R("Invalid or unsupported EC Key Curve or OKP Key Sub Type");
|
|
408
408
|
}
|
|
409
|
-
},
|
|
409
|
+
}, pt = async (e, t, r, a, n) => {
|
|
410
410
|
let s, o;
|
|
411
|
-
const
|
|
411
|
+
const i = new Uint8Array(atob(r.replace(e, "")).split("").map((c) => c.charCodeAt(0)));
|
|
412
412
|
switch (a) {
|
|
413
413
|
case "PS256":
|
|
414
414
|
case "PS384":
|
|
@@ -442,43 +442,43 @@ const Ce = (e) => (e == null ? void 0 : e[Symbol.toStringTag]) === "KeyObject",
|
|
|
442
442
|
case "ECDH-ES+A128KW":
|
|
443
443
|
case "ECDH-ES+A192KW":
|
|
444
444
|
case "ECDH-ES+A256KW": {
|
|
445
|
-
const
|
|
446
|
-
s =
|
|
445
|
+
const c = he(i);
|
|
446
|
+
s = c.startsWith("P-") ? { name: "ECDH", namedCurve: c } : { name: c }, o = [];
|
|
447
447
|
break;
|
|
448
448
|
}
|
|
449
449
|
case "EdDSA":
|
|
450
|
-
s = { name:
|
|
450
|
+
s = { name: he(i) }, o = ["verify"];
|
|
451
451
|
break;
|
|
452
452
|
default:
|
|
453
|
-
throw new
|
|
453
|
+
throw new R('Invalid or unsupported "alg" (Algorithm) value');
|
|
454
454
|
}
|
|
455
|
-
return
|
|
456
|
-
},
|
|
457
|
-
async function
|
|
455
|
+
return q.subtle.importKey(t, i, s, !1, o);
|
|
456
|
+
}, yt = (e, t, r) => pt(/(?:-----(?:BEGIN|END) PUBLIC KEY-----|\s)/g, "spki", e, t);
|
|
457
|
+
async function mt(e, t, r) {
|
|
458
458
|
if (e.indexOf("-----BEGIN PUBLIC KEY-----") !== 0)
|
|
459
459
|
throw new TypeError('"spki" must be SPKI formatted string');
|
|
460
|
-
return
|
|
460
|
+
return yt(e, t);
|
|
461
461
|
}
|
|
462
|
-
const
|
|
462
|
+
const Y = (e) => e == null ? void 0 : e[Symbol.toStringTag], wt = (e, t) => {
|
|
463
463
|
if (!(t instanceof Uint8Array)) {
|
|
464
|
-
if (!
|
|
465
|
-
throw new TypeError(
|
|
464
|
+
if (!Ie(t))
|
|
465
|
+
throw new TypeError(Re(e, t, ...B, "Uint8Array"));
|
|
466
466
|
if (t.type !== "secret")
|
|
467
|
-
throw new TypeError(`${
|
|
467
|
+
throw new TypeError(`${Y(t)} instances for symmetric algorithms must be of type "secret"`);
|
|
468
468
|
}
|
|
469
|
-
},
|
|
470
|
-
if (!
|
|
471
|
-
throw new TypeError(
|
|
469
|
+
}, Et = (e, t, r) => {
|
|
470
|
+
if (!Ie(t))
|
|
471
|
+
throw new TypeError(Re(e, t, ...B));
|
|
472
472
|
if (t.type === "secret")
|
|
473
|
-
throw new TypeError(`${
|
|
473
|
+
throw new TypeError(`${Y(t)} instances for asymmetric algorithms must not be of type "secret"`);
|
|
474
474
|
if (t.algorithm && r === "verify" && t.type === "private")
|
|
475
|
-
throw new TypeError(`${
|
|
475
|
+
throw new TypeError(`${Y(t)} instances for asymmetric algorithm verifying must be of type "public"`);
|
|
476
476
|
if (t.algorithm && r === "encrypt" && t.type === "private")
|
|
477
|
-
throw new TypeError(`${
|
|
478
|
-
},
|
|
479
|
-
e.startsWith("HS") || e === "dir" || e.startsWith("PBES2") || /^A\d{3}(?:GCM)?KW$/.test(e) ?
|
|
477
|
+
throw new TypeError(`${Y(t)} instances for asymmetric algorithm encryption must be of type "public"`);
|
|
478
|
+
}, St = (e, t, r) => {
|
|
479
|
+
e.startsWith("HS") || e === "dir" || e.startsWith("PBES2") || /^A\d{3}(?:GCM)?KW$/.test(e) ? wt(e, t) : Et(e, t, r);
|
|
480
480
|
};
|
|
481
|
-
function
|
|
481
|
+
function gt(e, t, r, a, n) {
|
|
482
482
|
if (n.crit !== void 0 && (a == null ? void 0 : a.crit) === void 0)
|
|
483
483
|
throw new e('"crit" (Critical) Header Parameter MUST be integrity protected');
|
|
484
484
|
if (!a || a.crit === void 0)
|
|
@@ -489,7 +489,7 @@ function Et(e, t, r, a, n) {
|
|
|
489
489
|
r !== void 0 ? s = new Map([...Object.entries(r), ...t.entries()]) : s = t;
|
|
490
490
|
for (const o of a.crit) {
|
|
491
491
|
if (!s.has(o))
|
|
492
|
-
throw new
|
|
492
|
+
throw new R(`Extension Header Parameter "${o}" is not recognized`);
|
|
493
493
|
if (n[o] === void 0)
|
|
494
494
|
throw new e(`Extension Header Parameter "${o}" is missing`);
|
|
495
495
|
if (s.get(o) && a[o] === void 0)
|
|
@@ -497,13 +497,13 @@ function Et(e, t, r, a, n) {
|
|
|
497
497
|
}
|
|
498
498
|
return new Set(a.crit);
|
|
499
499
|
}
|
|
500
|
-
const
|
|
500
|
+
const At = (e, t) => {
|
|
501
501
|
if (t !== void 0 && (!Array.isArray(t) || t.some((r) => typeof r != "string")))
|
|
502
502
|
throw new TypeError(`"${e}" option must be an array of strings`);
|
|
503
503
|
if (t)
|
|
504
504
|
return new Set(t);
|
|
505
505
|
};
|
|
506
|
-
function
|
|
506
|
+
function Tt(e, t) {
|
|
507
507
|
const r = `SHA-${e.slice(-3)}`;
|
|
508
508
|
switch (e) {
|
|
509
509
|
case "HS256":
|
|
@@ -525,104 +525,104 @@ function gt(e, t) {
|
|
|
525
525
|
case "EdDSA":
|
|
526
526
|
return { name: t.name };
|
|
527
527
|
default:
|
|
528
|
-
throw new
|
|
528
|
+
throw new R(`alg ${e} is not supported either by JOSE or your javascript runtime`);
|
|
529
529
|
}
|
|
530
530
|
}
|
|
531
|
-
async function
|
|
532
|
-
if (t = await
|
|
533
|
-
return
|
|
531
|
+
async function kt(e, t, r) {
|
|
532
|
+
if (t = await ft.normalizePublicKey(t, e), be(t))
|
|
533
|
+
return st(t, e, r), t;
|
|
534
534
|
if (t instanceof Uint8Array) {
|
|
535
535
|
if (!e.startsWith("HS"))
|
|
536
|
-
throw new TypeError(
|
|
537
|
-
return
|
|
536
|
+
throw new TypeError(le(t, ...B));
|
|
537
|
+
return q.subtle.importKey("raw", t, { hash: `SHA-${e.slice(-3)}`, name: "HMAC" }, !1, [r]);
|
|
538
538
|
}
|
|
539
|
-
throw new TypeError(
|
|
539
|
+
throw new TypeError(le(t, ...B, "Uint8Array"));
|
|
540
540
|
}
|
|
541
|
-
const
|
|
542
|
-
const n = await
|
|
543
|
-
|
|
544
|
-
const s =
|
|
541
|
+
const bt = async (e, t, r, a) => {
|
|
542
|
+
const n = await kt(e, t, "verify");
|
|
543
|
+
ct(e, n);
|
|
544
|
+
const s = Tt(e, n.algorithm);
|
|
545
545
|
try {
|
|
546
|
-
return await
|
|
546
|
+
return await q.subtle.verify(s, n, r, a);
|
|
547
547
|
} catch {
|
|
548
548
|
return !1;
|
|
549
549
|
}
|
|
550
550
|
};
|
|
551
|
-
async function
|
|
552
|
-
if (!
|
|
553
|
-
throw new
|
|
551
|
+
async function _t(e, t, r) {
|
|
552
|
+
if (!ie(e))
|
|
553
|
+
throw new f("Flattened JWS must be an object");
|
|
554
554
|
if (e.protected === void 0 && e.header === void 0)
|
|
555
|
-
throw new
|
|
555
|
+
throw new f('Flattened JWS must have either of the "protected" or "header" members');
|
|
556
556
|
if (e.protected !== void 0 && typeof e.protected != "string")
|
|
557
|
-
throw new
|
|
557
|
+
throw new f("JWS Protected Header incorrect type");
|
|
558
558
|
if (e.payload === void 0)
|
|
559
|
-
throw new
|
|
559
|
+
throw new f("JWS Payload missing");
|
|
560
560
|
if (typeof e.signature != "string")
|
|
561
|
-
throw new
|
|
562
|
-
if (e.header !== void 0 && !
|
|
563
|
-
throw new
|
|
561
|
+
throw new f("JWS Signature missing or incorrect type");
|
|
562
|
+
if (e.header !== void 0 && !ie(e.header))
|
|
563
|
+
throw new f("JWS Unprotected Header incorrect type");
|
|
564
564
|
let a = {};
|
|
565
565
|
if (e.protected)
|
|
566
566
|
try {
|
|
567
|
-
const
|
|
568
|
-
a = JSON.parse(
|
|
567
|
+
const S = V(e.protected);
|
|
568
|
+
a = JSON.parse(z.decode(S));
|
|
569
569
|
} catch {
|
|
570
|
-
throw new
|
|
570
|
+
throw new f("JWS Protected Header is invalid");
|
|
571
571
|
}
|
|
572
|
-
if (!
|
|
573
|
-
throw new
|
|
572
|
+
if (!ot(a, e.header))
|
|
573
|
+
throw new f("JWS Protected and JWS Unprotected Header Parameter names must be disjoint");
|
|
574
574
|
const n = {
|
|
575
575
|
...a,
|
|
576
576
|
...e.header
|
|
577
|
-
}, s =
|
|
577
|
+
}, s = gt(f, /* @__PURE__ */ new Map([["b64", !0]]), r == null ? void 0 : r.crit, a, n);
|
|
578
578
|
let o = !0;
|
|
579
579
|
if (s.has("b64") && (o = a.b64, typeof o != "boolean"))
|
|
580
|
-
throw new
|
|
581
|
-
const { alg:
|
|
582
|
-
if (typeof
|
|
583
|
-
throw new
|
|
584
|
-
const
|
|
585
|
-
if (
|
|
586
|
-
throw new
|
|
580
|
+
throw new f('The "b64" (base64url-encode payload) Header Parameter must be a boolean');
|
|
581
|
+
const { alg: i } = n;
|
|
582
|
+
if (typeof i != "string" || !i)
|
|
583
|
+
throw new f('JWS "alg" (Algorithm) Header Parameter missing or invalid');
|
|
584
|
+
const c = r && At("algorithms", r.algorithms);
|
|
585
|
+
if (c && !c.has(i))
|
|
586
|
+
throw new tt('"alg" (Algorithm) Header Parameter value not allowed');
|
|
587
587
|
if (o) {
|
|
588
588
|
if (typeof e.payload != "string")
|
|
589
|
-
throw new
|
|
589
|
+
throw new f("JWS Payload must be a string");
|
|
590
590
|
} else if (typeof e.payload != "string" && !(e.payload instanceof Uint8Array))
|
|
591
|
-
throw new
|
|
592
|
-
let
|
|
593
|
-
typeof t == "function" && (t = await t(a, e),
|
|
594
|
-
const
|
|
595
|
-
let
|
|
591
|
+
throw new f("JWS Payload must be a string or an Uint8Array instance");
|
|
592
|
+
let d = !1;
|
|
593
|
+
typeof t == "function" && (t = await t(a, e), d = !0), St(i, t, "verify");
|
|
594
|
+
const y = Ze(L.encode(e.protected ?? ""), L.encode("."), typeof e.payload == "string" ? L.encode(e.payload) : e.payload);
|
|
595
|
+
let p;
|
|
596
596
|
try {
|
|
597
|
-
|
|
597
|
+
p = V(e.signature);
|
|
598
598
|
} catch {
|
|
599
|
-
throw new
|
|
599
|
+
throw new f("Failed to base64url decode the signature");
|
|
600
600
|
}
|
|
601
|
-
if (!await
|
|
602
|
-
throw new
|
|
603
|
-
let
|
|
601
|
+
if (!await bt(i, t, p, y))
|
|
602
|
+
throw new rt();
|
|
603
|
+
let A;
|
|
604
604
|
if (o)
|
|
605
605
|
try {
|
|
606
|
-
|
|
606
|
+
A = V(e.payload);
|
|
607
607
|
} catch {
|
|
608
|
-
throw new
|
|
608
|
+
throw new f("Failed to base64url decode the payload");
|
|
609
609
|
}
|
|
610
610
|
else
|
|
611
|
-
typeof e.payload == "string" ?
|
|
612
|
-
const E = { payload:
|
|
613
|
-
return e.protected !== void 0 && (E.protectedHeader = a), e.header !== void 0 && (E.unprotectedHeader = e.header),
|
|
611
|
+
typeof e.payload == "string" ? A = L.encode(e.payload) : A = e.payload;
|
|
612
|
+
const E = { payload: A };
|
|
613
|
+
return e.protected !== void 0 && (E.protectedHeader = a), e.header !== void 0 && (E.unprotectedHeader = e.header), d ? { ...E, key: t } : E;
|
|
614
614
|
}
|
|
615
|
-
async function
|
|
616
|
-
if (e instanceof Uint8Array && (e =
|
|
617
|
-
throw new
|
|
615
|
+
async function vt(e, t, r) {
|
|
616
|
+
if (e instanceof Uint8Array && (e = z.decode(e)), typeof e != "string")
|
|
617
|
+
throw new f("Compact JWS must be a string or Uint8Array");
|
|
618
618
|
const { 0: a, 1: n, 2: s, length: o } = e.split(".");
|
|
619
619
|
if (o !== 3)
|
|
620
|
-
throw new
|
|
621
|
-
const
|
|
622
|
-
return typeof t == "function" ? { ...
|
|
620
|
+
throw new f("Invalid Compact JWS");
|
|
621
|
+
const i = await _t({ payload: n, protected: a, signature: s }, t, r), c = { payload: i.payload, protectedHeader: i.protectedHeader };
|
|
622
|
+
return typeof t == "function" ? { ...c, key: i.key } : c;
|
|
623
623
|
}
|
|
624
|
-
const
|
|
625
|
-
const t =
|
|
624
|
+
const Rt = (e) => Math.floor(e.getTime() / 1e3), De = 60, Ue = De * 60, ce = Ue * 24, It = ce * 7, Ct = ce * 365.25, Pt = /^(\+|\-)? ?(\d+|\d+\.\d+) ?(seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)(?: (ago|from now))?$/i, fe = (e) => {
|
|
625
|
+
const t = Pt.exec(e);
|
|
626
626
|
if (!t || t[4] && t[1])
|
|
627
627
|
throw new TypeError("Invalid time period format");
|
|
628
628
|
const r = parseFloat(t[2]), a = t[3].toLowerCase();
|
|
@@ -640,230 +640,230 @@ const _t = (e) => Math.floor(e.getTime() / 1e3), Oe = 60, De = Oe * 60, ie = De
|
|
|
640
640
|
case "min":
|
|
641
641
|
case "mins":
|
|
642
642
|
case "m":
|
|
643
|
-
n = Math.round(r *
|
|
643
|
+
n = Math.round(r * De);
|
|
644
644
|
break;
|
|
645
645
|
case "hour":
|
|
646
646
|
case "hours":
|
|
647
647
|
case "hr":
|
|
648
648
|
case "hrs":
|
|
649
649
|
case "h":
|
|
650
|
-
n = Math.round(r *
|
|
650
|
+
n = Math.round(r * Ue);
|
|
651
651
|
break;
|
|
652
652
|
case "day":
|
|
653
653
|
case "days":
|
|
654
654
|
case "d":
|
|
655
|
-
n = Math.round(r *
|
|
655
|
+
n = Math.round(r * ce);
|
|
656
656
|
break;
|
|
657
657
|
case "week":
|
|
658
658
|
case "weeks":
|
|
659
659
|
case "w":
|
|
660
|
-
n = Math.round(r *
|
|
660
|
+
n = Math.round(r * It);
|
|
661
661
|
break;
|
|
662
662
|
default:
|
|
663
|
-
n = Math.round(r *
|
|
663
|
+
n = Math.round(r * Ct);
|
|
664
664
|
break;
|
|
665
665
|
}
|
|
666
666
|
return t[1] === "-" || t[4] === "ago" ? -n : n;
|
|
667
|
-
}, pe = (e) => e.toLowerCase().replace(/^application\//, ""),
|
|
667
|
+
}, pe = (e) => e.toLowerCase().replace(/^application\//, ""), Ot = (e, t) => typeof e == "string" ? t.includes(e) : Array.isArray(e) ? t.some(Set.prototype.has.bind(new Set(e))) : !1, Dt = (e, t, r = {}) => {
|
|
668
668
|
let a;
|
|
669
669
|
try {
|
|
670
|
-
a = JSON.parse(
|
|
670
|
+
a = JSON.parse(z.decode(t));
|
|
671
671
|
} catch {
|
|
672
672
|
}
|
|
673
|
-
if (!
|
|
674
|
-
throw new
|
|
673
|
+
if (!ie(a))
|
|
674
|
+
throw new _e("JWT Claims Set must be a top-level JSON object");
|
|
675
675
|
const { typ: n } = r;
|
|
676
676
|
if (n && (typeof e.typ != "string" || pe(e.typ) !== pe(n)))
|
|
677
|
-
throw new
|
|
678
|
-
const { requiredClaims: s = [], issuer: o, subject:
|
|
679
|
-
|
|
680
|
-
for (const
|
|
681
|
-
if (!(
|
|
682
|
-
throw new
|
|
677
|
+
throw new g('unexpected "typ" JWT header value', a, "typ", "check_failed");
|
|
678
|
+
const { requiredClaims: s = [], issuer: o, subject: i, audience: c, maxTokenAge: d } = r, y = [...s];
|
|
679
|
+
d !== void 0 && y.push("iat"), c !== void 0 && y.push("aud"), i !== void 0 && y.push("sub"), o !== void 0 && y.push("iss");
|
|
680
|
+
for (const S of new Set(y.reverse()))
|
|
681
|
+
if (!(S in a))
|
|
682
|
+
throw new g(`missing required "${S}" claim`, a, S, "missing");
|
|
683
683
|
if (o && !(Array.isArray(o) ? o : [o]).includes(a.iss))
|
|
684
|
-
throw new
|
|
685
|
-
if (
|
|
686
|
-
throw new
|
|
687
|
-
if (
|
|
688
|
-
throw new
|
|
689
|
-
let
|
|
684
|
+
throw new g('unexpected "iss" claim value', a, "iss", "check_failed");
|
|
685
|
+
if (i && a.sub !== i)
|
|
686
|
+
throw new g('unexpected "sub" claim value', a, "sub", "check_failed");
|
|
687
|
+
if (c && !Ot(a.aud, typeof c == "string" ? [c] : c))
|
|
688
|
+
throw new g('unexpected "aud" claim value', a, "aud", "check_failed");
|
|
689
|
+
let p;
|
|
690
690
|
switch (typeof r.clockTolerance) {
|
|
691
691
|
case "string":
|
|
692
|
-
|
|
692
|
+
p = fe(r.clockTolerance);
|
|
693
693
|
break;
|
|
694
694
|
case "number":
|
|
695
|
-
|
|
695
|
+
p = r.clockTolerance;
|
|
696
696
|
break;
|
|
697
697
|
case "undefined":
|
|
698
|
-
|
|
698
|
+
p = 0;
|
|
699
699
|
break;
|
|
700
700
|
default:
|
|
701
701
|
throw new TypeError("Invalid clockTolerance option type");
|
|
702
702
|
}
|
|
703
|
-
const { currentDate:
|
|
704
|
-
if ((a.iat !== void 0 ||
|
|
705
|
-
throw new
|
|
703
|
+
const { currentDate: A } = r, E = Rt(A || /* @__PURE__ */ new Date());
|
|
704
|
+
if ((a.iat !== void 0 || d) && typeof a.iat != "number")
|
|
705
|
+
throw new g('"iat" claim must be a number', a, "iat", "invalid");
|
|
706
706
|
if (a.nbf !== void 0) {
|
|
707
707
|
if (typeof a.nbf != "number")
|
|
708
|
-
throw new
|
|
709
|
-
if (a.nbf > E +
|
|
710
|
-
throw new
|
|
708
|
+
throw new g('"nbf" claim must be a number', a, "nbf", "invalid");
|
|
709
|
+
if (a.nbf > E + p)
|
|
710
|
+
throw new g('"nbf" claim timestamp check failed', a, "nbf", "check_failed");
|
|
711
711
|
}
|
|
712
712
|
if (a.exp !== void 0) {
|
|
713
713
|
if (typeof a.exp != "number")
|
|
714
|
-
throw new
|
|
715
|
-
if (a.exp <= E -
|
|
716
|
-
throw new
|
|
714
|
+
throw new g('"exp" claim must be a number', a, "exp", "invalid");
|
|
715
|
+
if (a.exp <= E - p)
|
|
716
|
+
throw new de('"exp" claim timestamp check failed', a, "exp", "check_failed");
|
|
717
717
|
}
|
|
718
|
-
if (
|
|
719
|
-
const
|
|
720
|
-
if (
|
|
721
|
-
throw new
|
|
722
|
-
if (
|
|
723
|
-
throw new
|
|
718
|
+
if (d) {
|
|
719
|
+
const S = E - a.iat, K = typeof d == "number" ? d : fe(d);
|
|
720
|
+
if (S - p > K)
|
|
721
|
+
throw new de('"iat" claim timestamp check failed (too far in the past)', a, "iat", "check_failed");
|
|
722
|
+
if (S < 0 - p)
|
|
723
|
+
throw new g('"iat" claim timestamp check failed (it should be in the past)', a, "iat", "check_failed");
|
|
724
724
|
}
|
|
725
725
|
return a;
|
|
726
726
|
};
|
|
727
|
-
async function
|
|
727
|
+
async function Ut(e, t, r) {
|
|
728
728
|
var a;
|
|
729
|
-
const n = await
|
|
729
|
+
const n = await vt(e, t, r);
|
|
730
730
|
if ((a = n.protectedHeader.crit) != null && a.includes("b64") && n.protectedHeader.b64 === !1)
|
|
731
|
-
throw new
|
|
732
|
-
const s = { payload:
|
|
731
|
+
throw new _e("JWTs MUST NOT use unencoded payload");
|
|
732
|
+
const s = { payload: Dt(n.protectedHeader, n.payload, r), protectedHeader: n.protectedHeader };
|
|
733
733
|
return typeof t == "function" ? { ...s, key: n.key } : s;
|
|
734
734
|
}
|
|
735
|
-
const
|
|
735
|
+
const H = async (e) => {
|
|
736
736
|
try {
|
|
737
|
-
const t =
|
|
738
|
-
return await
|
|
739
|
-
issuer:
|
|
737
|
+
const t = m.ALG, r = await mt(Qe, t);
|
|
738
|
+
return await Ut(e, r, {
|
|
739
|
+
issuer: m.ISSUER
|
|
740
740
|
});
|
|
741
741
|
} catch {
|
|
742
742
|
return;
|
|
743
743
|
}
|
|
744
744
|
};
|
|
745
|
-
var
|
|
746
|
-
for (var
|
|
747
|
-
|
|
748
|
-
function
|
|
749
|
-
return (
|
|
745
|
+
var l = [];
|
|
746
|
+
for (var re = 0; re < 256; ++re)
|
|
747
|
+
l.push((re + 256).toString(16).slice(1));
|
|
748
|
+
function Ht(e, t = 0) {
|
|
749
|
+
return (l[e[t + 0]] + l[e[t + 1]] + l[e[t + 2]] + l[e[t + 3]] + "-" + l[e[t + 4]] + l[e[t + 5]] + "-" + l[e[t + 6]] + l[e[t + 7]] + "-" + l[e[t + 8]] + l[e[t + 9]] + "-" + l[e[t + 10]] + l[e[t + 11]] + l[e[t + 12]] + l[e[t + 13]] + l[e[t + 14]] + l[e[t + 15]]).toLowerCase();
|
|
750
750
|
}
|
|
751
|
-
var
|
|
752
|
-
function
|
|
753
|
-
if (!
|
|
751
|
+
var W, Kt = new Uint8Array(16);
|
|
752
|
+
function Nt() {
|
|
753
|
+
if (!W && (W = typeof crypto < "u" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto), !W))
|
|
754
754
|
throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
|
|
755
|
-
return
|
|
755
|
+
return W(Kt);
|
|
756
756
|
}
|
|
757
|
-
var
|
|
758
|
-
const
|
|
759
|
-
randomUUID:
|
|
757
|
+
var Lt = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto);
|
|
758
|
+
const ye = {
|
|
759
|
+
randomUUID: Lt
|
|
760
760
|
};
|
|
761
|
-
function
|
|
762
|
-
if (
|
|
763
|
-
return
|
|
761
|
+
function me(e, t, r) {
|
|
762
|
+
if (ye.randomUUID && !t && !e)
|
|
763
|
+
return ye.randomUUID();
|
|
764
764
|
e = e || {};
|
|
765
|
-
var a = e.random || (e.rng ||
|
|
766
|
-
return a[6] = a[6] & 15 | 64, a[8] = a[8] & 63 | 128,
|
|
765
|
+
var a = e.random || (e.rng || Nt)();
|
|
766
|
+
return a[6] = a[6] & 15 | 64, a[8] = a[8] & 63 | 128, Ht(a);
|
|
767
767
|
}
|
|
768
|
-
const
|
|
768
|
+
const we = globalThis.crypto, $t = (e) => `${me()}${me()}`.slice(0, e), Wt = (e) => btoa(
|
|
769
769
|
[...new Uint8Array(e)].map((t) => String.fromCharCode(t)).join("")
|
|
770
770
|
);
|
|
771
|
-
async function
|
|
772
|
-
if (!
|
|
771
|
+
async function Jt(e) {
|
|
772
|
+
if (!we.subtle)
|
|
773
773
|
throw new Error(
|
|
774
774
|
"crypto.subtle is available only in secure contexts (HTTPS)."
|
|
775
775
|
);
|
|
776
|
-
const t = new TextEncoder().encode(e), r = await
|
|
777
|
-
return
|
|
776
|
+
const t = new TextEncoder().encode(e), r = await we.subtle.digest("SHA-256", t);
|
|
777
|
+
return Wt(r).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
778
778
|
}
|
|
779
|
-
async function
|
|
780
|
-
const r =
|
|
779
|
+
async function xt(e) {
|
|
780
|
+
const r = $t(43), a = await Jt(r);
|
|
781
781
|
return {
|
|
782
782
|
code_verifier: r,
|
|
783
783
|
code_challenge: a
|
|
784
784
|
};
|
|
785
785
|
}
|
|
786
|
-
function
|
|
786
|
+
function He(e, t) {
|
|
787
787
|
window.dispatchEvent(new StorageEvent("storage", { key: e, newValue: t }));
|
|
788
788
|
}
|
|
789
|
-
const
|
|
789
|
+
const Ee = (e, t) => {
|
|
790
790
|
const r = JSON.stringify(
|
|
791
791
|
typeof t == "function" ? t() : t
|
|
792
792
|
);
|
|
793
|
-
window.localStorage.setItem(e, r),
|
|
794
|
-
},
|
|
795
|
-
window.localStorage.removeItem(e),
|
|
796
|
-
},
|
|
797
|
-
function
|
|
793
|
+
window.localStorage.setItem(e, r), He(e, r);
|
|
794
|
+
}, jt = (e) => {
|
|
795
|
+
window.localStorage.removeItem(e), He(e, null);
|
|
796
|
+
}, Se = (e) => window.localStorage.getItem(e), Mt = (e) => (window.addEventListener("storage", e), () => window.removeEventListener("storage", e));
|
|
797
|
+
function J({
|
|
798
798
|
key: e,
|
|
799
799
|
initialValue: t
|
|
800
800
|
}) {
|
|
801
|
-
const r = () =>
|
|
802
|
-
|
|
801
|
+
const r = () => Se(e), a = U.useSyncExternalStore(
|
|
802
|
+
Mt,
|
|
803
803
|
r
|
|
804
|
-
), n =
|
|
805
|
-
(
|
|
804
|
+
), n = U.useCallback(
|
|
805
|
+
(i) => {
|
|
806
806
|
try {
|
|
807
|
-
const
|
|
808
|
-
|
|
809
|
-
} catch (
|
|
810
|
-
console.warn(
|
|
807
|
+
const c = typeof i == "function" ? i(JSON.parse(a)) : i;
|
|
808
|
+
c == null ? jt(e) : Ee(e, c);
|
|
809
|
+
} catch (c) {
|
|
810
|
+
console.warn(c);
|
|
811
811
|
}
|
|
812
812
|
},
|
|
813
813
|
[e, a]
|
|
814
|
-
), s =
|
|
814
|
+
), s = U.useCallback(() => {
|
|
815
815
|
n(t);
|
|
816
|
-
}, [t, n]), o =
|
|
816
|
+
}, [t, n]), o = U.useCallback(() => {
|
|
817
817
|
n(null);
|
|
818
818
|
}, [n]);
|
|
819
|
-
return
|
|
819
|
+
return U.useEffect(() => {
|
|
820
820
|
try {
|
|
821
|
-
|
|
822
|
-
} catch (
|
|
823
|
-
console.warn(
|
|
821
|
+
Se(e) === null && typeof t < "u" && Ee(e, t);
|
|
822
|
+
} catch (i) {
|
|
823
|
+
console.warn(i);
|
|
824
824
|
}
|
|
825
825
|
}, [e, t]), [a ? JSON.parse(a) : null, n, s, o];
|
|
826
826
|
}
|
|
827
|
-
var
|
|
828
|
-
for (var
|
|
829
|
-
|
|
830
|
-
function
|
|
831
|
-
return (
|
|
827
|
+
var h = [];
|
|
828
|
+
for (var ae = 0; ae < 256; ++ae)
|
|
829
|
+
h.push((ae + 256).toString(16).slice(1));
|
|
830
|
+
function Vt(e, t = 0) {
|
|
831
|
+
return (h[e[t + 0]] + h[e[t + 1]] + h[e[t + 2]] + h[e[t + 3]] + "-" + h[e[t + 4]] + h[e[t + 5]] + "-" + h[e[t + 6]] + h[e[t + 7]] + "-" + h[e[t + 8]] + h[e[t + 9]] + "-" + h[e[t + 10]] + h[e[t + 11]] + h[e[t + 12]] + h[e[t + 13]] + h[e[t + 14]] + h[e[t + 15]]).toLowerCase();
|
|
832
832
|
}
|
|
833
|
-
var
|
|
834
|
-
function
|
|
835
|
-
if (!
|
|
833
|
+
var x, Yt = new Uint8Array(16);
|
|
834
|
+
function Bt() {
|
|
835
|
+
if (!x && (x = typeof crypto < "u" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto), !x))
|
|
836
836
|
throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
|
|
837
|
-
return
|
|
837
|
+
return x(Yt);
|
|
838
838
|
}
|
|
839
|
-
var
|
|
840
|
-
const
|
|
841
|
-
randomUUID:
|
|
839
|
+
var Ft = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto);
|
|
840
|
+
const ge = {
|
|
841
|
+
randomUUID: Ft
|
|
842
842
|
};
|
|
843
|
-
function
|
|
844
|
-
if (
|
|
845
|
-
return
|
|
843
|
+
function Gt(e, t, r) {
|
|
844
|
+
if (ge.randomUUID && !t && !e)
|
|
845
|
+
return ge.randomUUID();
|
|
846
846
|
e = e || {};
|
|
847
|
-
var a = e.random || (e.rng ||
|
|
848
|
-
return a[6] = a[6] & 15 | 64, a[8] = a[8] & 63 | 128,
|
|
847
|
+
var a = e.random || (e.rng || Bt)();
|
|
848
|
+
return a[6] = a[6] & 15 | 64, a[8] = a[8] & 63 | 128, Vt(a);
|
|
849
849
|
}
|
|
850
|
-
const
|
|
850
|
+
const ne = "Oops! It looks like your session has expired. For your security, please log in again to continue.", qt = "Your session has been successfully terminated.", Ae = "Login failed. Please try again.", se = "Error getting access token, please re-authenticate.", zt = "You forgot to wrap your component in <AuthProvider>.", Te = {
|
|
851
851
|
dev: "https://auth.gizmette.local.com:3003",
|
|
852
852
|
prod: "https://mylogin.gizmette.com"
|
|
853
|
-
},
|
|
853
|
+
}, j = "@@auth@@", Xt = process.env.NODE_ENV === "production", Qt = !Xt, X = async ({
|
|
854
854
|
type: e,
|
|
855
855
|
clientId: t,
|
|
856
856
|
params: r = {}
|
|
857
857
|
}) => {
|
|
858
858
|
try {
|
|
859
859
|
const a = await fetch(
|
|
860
|
-
|
|
860
|
+
Qt ? `${Te.dev}/${e}` : `${Te.prod}/${e}`,
|
|
861
861
|
{
|
|
862
862
|
credentials: "include",
|
|
863
863
|
method: "POST",
|
|
864
864
|
headers: {
|
|
865
865
|
"Content-Type": "application/json",
|
|
866
|
-
[
|
|
866
|
+
[Xe.CLIENT_ID]: `${t}`
|
|
867
867
|
},
|
|
868
868
|
body: JSON.stringify(r)
|
|
869
869
|
}
|
|
@@ -879,7 +879,7 @@ const ae = "Oops! It looks like your session has expired. For your security, ple
|
|
|
879
879
|
} catch (a) {
|
|
880
880
|
return console.error(a), { status: 500, data: [] };
|
|
881
881
|
}
|
|
882
|
-
},
|
|
882
|
+
}, oe = async ({
|
|
883
883
|
idToken: e,
|
|
884
884
|
accessToken: t,
|
|
885
885
|
refreshToken: r,
|
|
@@ -887,8 +887,8 @@ const ae = "Oops! It looks like your session has expired. For your security, ple
|
|
|
887
887
|
}) => {
|
|
888
888
|
try {
|
|
889
889
|
return {
|
|
890
|
-
status: (await
|
|
891
|
-
type:
|
|
890
|
+
status: (await X({
|
|
891
|
+
type: G.LOGOUT,
|
|
892
892
|
clientId: a,
|
|
893
893
|
params: {
|
|
894
894
|
idToken: e,
|
|
@@ -902,7 +902,7 @@ const ae = "Oops! It looks like your session has expired. For your security, ple
|
|
|
902
902
|
status: !1
|
|
903
903
|
};
|
|
904
904
|
}
|
|
905
|
-
},
|
|
905
|
+
}, ke = async ({
|
|
906
906
|
username: e,
|
|
907
907
|
password: t,
|
|
908
908
|
clientId: r,
|
|
@@ -910,27 +910,27 @@ const ae = "Oops! It looks like your session has expired. For your security, ple
|
|
|
910
910
|
type: n,
|
|
911
911
|
sessionExpiration: s,
|
|
912
912
|
code: o,
|
|
913
|
-
code_verifier:
|
|
913
|
+
code_verifier: i
|
|
914
914
|
}) => {
|
|
915
915
|
try {
|
|
916
|
-
const
|
|
917
|
-
type:
|
|
916
|
+
const c = await X({
|
|
917
|
+
type: G.AUTHENTICATE,
|
|
918
918
|
clientId: r,
|
|
919
919
|
params: {
|
|
920
|
-
type: n ||
|
|
920
|
+
type: n || F.ID_AND_ACCESS_TOKEN,
|
|
921
921
|
username: e,
|
|
922
922
|
password: t,
|
|
923
923
|
sessionExpiration: s,
|
|
924
924
|
nonce: a,
|
|
925
925
|
code: o,
|
|
926
|
-
code_verifier:
|
|
926
|
+
code_verifier: i
|
|
927
927
|
}
|
|
928
|
-
}),
|
|
929
|
-
return
|
|
930
|
-
idToken:
|
|
931
|
-
accessToken:
|
|
932
|
-
refreshToken:
|
|
933
|
-
userId:
|
|
928
|
+
}), d = await H(c.data.idToken);
|
|
929
|
+
return d && d.payload[m.USER_ID_KEY] !== "" && d.payload[m.NONCE_KEY] === a ? {
|
|
930
|
+
idToken: c.data.idToken,
|
|
931
|
+
accessToken: c.data.accessToken,
|
|
932
|
+
refreshToken: c.data.refreshToken,
|
|
933
|
+
userId: d.payload[m.USER_ID_KEY],
|
|
934
934
|
status: !0
|
|
935
935
|
} : {
|
|
936
936
|
status: !1
|
|
@@ -940,17 +940,17 @@ const ae = "Oops! It looks like your session has expired. For your security, ple
|
|
|
940
940
|
status: !1
|
|
941
941
|
};
|
|
942
942
|
}
|
|
943
|
-
},
|
|
943
|
+
}, Zt = async ({
|
|
944
944
|
nonce: e,
|
|
945
945
|
clientId: t,
|
|
946
946
|
code_challenge: r
|
|
947
947
|
}) => {
|
|
948
948
|
try {
|
|
949
|
-
const a = await
|
|
950
|
-
type:
|
|
949
|
+
const a = await X({
|
|
950
|
+
type: G.CODE,
|
|
951
951
|
clientId: t,
|
|
952
952
|
params: {
|
|
953
|
-
type:
|
|
953
|
+
type: F.CODE,
|
|
954
954
|
nonce: e,
|
|
955
955
|
code_challenge: r
|
|
956
956
|
}
|
|
@@ -966,7 +966,7 @@ const ae = "Oops! It looks like your session has expired. For your security, ple
|
|
|
966
966
|
status: !1
|
|
967
967
|
};
|
|
968
968
|
}
|
|
969
|
-
},
|
|
969
|
+
}, er = async ({
|
|
970
970
|
clientId: e,
|
|
971
971
|
userId: t,
|
|
972
972
|
nonce: r,
|
|
@@ -974,21 +974,21 @@ const ae = "Oops! It looks like your session has expired. For your security, ple
|
|
|
974
974
|
accessToken: n
|
|
975
975
|
}) => {
|
|
976
976
|
try {
|
|
977
|
-
const s = await
|
|
978
|
-
type:
|
|
977
|
+
const s = await X({
|
|
978
|
+
type: G.AUTHENTICATE,
|
|
979
979
|
clientId: e,
|
|
980
980
|
params: {
|
|
981
|
-
type:
|
|
981
|
+
type: F.REFRESH_TOKEN,
|
|
982
982
|
userId: t,
|
|
983
983
|
nonce: r,
|
|
984
984
|
refreshToken: a,
|
|
985
985
|
accessToken: n
|
|
986
986
|
}
|
|
987
|
-
}), o = await
|
|
988
|
-
return o && o.payload[
|
|
987
|
+
}), o = await H(s.data.accessToken);
|
|
988
|
+
return o && o.payload[m.USER_ID_KEY] !== "" && o.payload[m.NONCE_KEY] === r ? {
|
|
989
989
|
accessToken: s.data.accessToken,
|
|
990
990
|
refreshToken: s.data.refreshToken,
|
|
991
|
-
userId: o.payload[
|
|
991
|
+
userId: o.payload[m.USER_ID_KEY],
|
|
992
992
|
status: !0
|
|
993
993
|
} : {
|
|
994
994
|
status: !1
|
|
@@ -999,11 +999,11 @@ const ae = "Oops! It looks like your session has expired. For your security, ple
|
|
|
999
999
|
};
|
|
1000
1000
|
}
|
|
1001
1001
|
};
|
|
1002
|
-
class
|
|
1002
|
+
class tr {
|
|
1003
1003
|
constructor(t = null, r = null) {
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1004
|
+
N(this, "refreshTokenPromise", null);
|
|
1005
|
+
N(this, "accessToken");
|
|
1006
|
+
N(this, "refreshToken");
|
|
1007
1007
|
this.accessToken = t || "", this.refreshToken = r || "";
|
|
1008
1008
|
}
|
|
1009
1009
|
async refreshtoken({
|
|
@@ -1027,9 +1027,9 @@ class Zt {
|
|
|
1027
1027
|
userId: r,
|
|
1028
1028
|
nonce: a
|
|
1029
1029
|
}) {
|
|
1030
|
-
const n = await
|
|
1031
|
-
if (n && n.payload[
|
|
1032
|
-
const s = await
|
|
1030
|
+
const n = await H(this.refreshToken);
|
|
1031
|
+
if (n && n.payload[m.USER_ID_KEY] !== "") {
|
|
1032
|
+
const s = await er({
|
|
1033
1033
|
clientId: t,
|
|
1034
1034
|
userId: r,
|
|
1035
1035
|
nonce: a,
|
|
@@ -1049,170 +1049,188 @@ class Zt {
|
|
|
1049
1049
|
};
|
|
1050
1050
|
}
|
|
1051
1051
|
}
|
|
1052
|
-
const
|
|
1053
|
-
throw new Error(
|
|
1054
|
-
},
|
|
1052
|
+
const M = () => {
|
|
1053
|
+
throw new Error(zt);
|
|
1054
|
+
}, Ke = Ye({
|
|
1055
1055
|
isAuthenticated: !1,
|
|
1056
1056
|
isLoading: !1,
|
|
1057
|
-
login:
|
|
1058
|
-
logout:
|
|
1059
|
-
getAccessToken:
|
|
1060
|
-
getIdToken:
|
|
1057
|
+
login: M,
|
|
1058
|
+
logout: M,
|
|
1059
|
+
getAccessToken: M,
|
|
1060
|
+
getIdToken: M,
|
|
1061
1061
|
logoutReason: ""
|
|
1062
|
-
}),
|
|
1062
|
+
}), ir = ({
|
|
1063
1063
|
children: e,
|
|
1064
1064
|
sessionExpiration: t,
|
|
1065
1065
|
clientId: r
|
|
1066
1066
|
}) => {
|
|
1067
|
-
const
|
|
1068
|
-
key: `${
|
|
1069
|
-
}), [
|
|
1070
|
-
key: `${
|
|
1071
|
-
}), [
|
|
1067
|
+
const a = Be(!1), [n, s, , o] = J({
|
|
1068
|
+
key: `${j}::${r}::@@user@@`
|
|
1069
|
+
}), [i, c, , d] = J({
|
|
1070
|
+
key: `${j}::${r}::@@access@@`
|
|
1071
|
+
}), [y, p, , A] = J(
|
|
1072
1072
|
{
|
|
1073
|
-
key: `${
|
|
1073
|
+
key: `${j}::${r}::@@refresh@@`
|
|
1074
1074
|
}
|
|
1075
|
-
), [
|
|
1076
|
-
key: `${
|
|
1077
|
-
}),
|
|
1075
|
+
), [E, S, , K] = J({
|
|
1076
|
+
key: `${j}::${r}::@@nonce@@`
|
|
1077
|
+
}), Ne = new tr(i, y), [P, T] = Fe({
|
|
1078
1078
|
isLoading: !0,
|
|
1079
1079
|
isAuthenticated: !1,
|
|
1080
1080
|
user: void 0,
|
|
1081
1081
|
logoutReason: ""
|
|
1082
|
-
}),
|
|
1083
|
-
(
|
|
1084
|
-
console.warn(
|
|
1085
|
-
isLoading: !
|
|
1082
|
+
}), k = Ge(
|
|
1083
|
+
(u) => {
|
|
1084
|
+
console.warn(u), T({
|
|
1085
|
+
isLoading: !0,
|
|
1086
1086
|
isAuthenticated: !1,
|
|
1087
1087
|
user: void 0,
|
|
1088
|
-
logoutReason:
|
|
1089
|
-
}),
|
|
1088
|
+
logoutReason: u || ne
|
|
1089
|
+
}), o(), d(), A(), K();
|
|
1090
1090
|
},
|
|
1091
|
-
[
|
|
1091
|
+
[o, d, K, A]
|
|
1092
1092
|
);
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1093
|
+
qe(() => {
|
|
1094
|
+
if (!a.current)
|
|
1095
|
+
return P.isLoading && n !== null ? (async () => {
|
|
1096
|
+
try {
|
|
1097
|
+
const u = await H(n);
|
|
1098
|
+
u && u.payload[m.USER_ID_KEY] !== "" ? T({
|
|
1099
|
+
isLoading: !1,
|
|
1100
|
+
isAuthenticated: !0,
|
|
1101
|
+
user: {
|
|
1102
|
+
userId: u.payload[m.USER_ID_KEY],
|
|
1103
|
+
username: u.payload[m.USERNAME_KEY]
|
|
1104
|
+
},
|
|
1105
|
+
logoutReason: ""
|
|
1106
|
+
}) : (k(ne), await oe({
|
|
1107
|
+
idToken: n,
|
|
1108
|
+
accessToken: i,
|
|
1109
|
+
refreshToken: y,
|
|
1110
|
+
clientId: r
|
|
1111
|
+
}), T((w) => ({
|
|
1112
|
+
...w,
|
|
1113
|
+
isLoading: !1
|
|
1114
|
+
})));
|
|
1115
|
+
} catch {
|
|
1116
|
+
k(ne), await oe({
|
|
1117
|
+
idToken: n,
|
|
1118
|
+
accessToken: i,
|
|
1119
|
+
refreshToken: y,
|
|
1120
|
+
clientId: r
|
|
1121
|
+
}), T((w) => ({
|
|
1122
|
+
...w,
|
|
1123
|
+
isLoading: !1
|
|
1124
|
+
}));
|
|
1125
|
+
}
|
|
1126
|
+
})() : T((u) => ({
|
|
1127
|
+
...u,
|
|
1128
|
+
isLoading: !1
|
|
1129
|
+
})), () => {
|
|
1130
|
+
a.current = !0;
|
|
1131
|
+
};
|
|
1120
1132
|
}, [
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1133
|
+
P,
|
|
1134
|
+
i,
|
|
1135
|
+
n,
|
|
1136
|
+
y,
|
|
1125
1137
|
r,
|
|
1126
|
-
|
|
1138
|
+
k
|
|
1127
1139
|
]);
|
|
1128
|
-
const
|
|
1129
|
-
const
|
|
1130
|
-
if (
|
|
1131
|
-
|
|
1132
|
-
|
|
1140
|
+
const Le = async (u, w, b) => {
|
|
1141
|
+
const I = Gt();
|
|
1142
|
+
if (S(I), T((Q) => ({
|
|
1143
|
+
...Q,
|
|
1144
|
+
isLoading: !0
|
|
1145
|
+
})), b === F.CODE) {
|
|
1146
|
+
const { code_verifier: Q, code_challenge: xe } = await xt(), ue = await Zt({
|
|
1147
|
+
nonce: I,
|
|
1133
1148
|
clientId: r,
|
|
1134
|
-
code_challenge:
|
|
1149
|
+
code_challenge: xe
|
|
1135
1150
|
});
|
|
1136
|
-
if (
|
|
1137
|
-
const
|
|
1138
|
-
username:
|
|
1139
|
-
password:
|
|
1151
|
+
if (ue.status) {
|
|
1152
|
+
const D = await ke({
|
|
1153
|
+
username: u,
|
|
1154
|
+
password: w,
|
|
1140
1155
|
clientId: r,
|
|
1141
1156
|
sessionExpiration: t,
|
|
1142
|
-
nonce:
|
|
1143
|
-
type:
|
|
1144
|
-
code:
|
|
1145
|
-
code_verifier:
|
|
1157
|
+
nonce: I,
|
|
1158
|
+
type: b,
|
|
1159
|
+
code: ue.code,
|
|
1160
|
+
code_verifier: Q
|
|
1146
1161
|
});
|
|
1147
|
-
return
|
|
1162
|
+
return D.status ? (s(D.idToken), c(D.accessToken), p(D.refreshToken), T({
|
|
1148
1163
|
isLoading: !1,
|
|
1149
1164
|
isAuthenticated: !0,
|
|
1150
1165
|
user: {
|
|
1151
|
-
userId:
|
|
1152
|
-
username:
|
|
1166
|
+
userId: D.userId,
|
|
1167
|
+
username: u
|
|
1153
1168
|
},
|
|
1154
1169
|
logoutReason: ""
|
|
1155
|
-
}), !0) : (
|
|
1170
|
+
}), !0) : (k(Ae), !1);
|
|
1156
1171
|
}
|
|
1157
1172
|
return !1;
|
|
1158
1173
|
}
|
|
1159
|
-
const
|
|
1160
|
-
username:
|
|
1161
|
-
password:
|
|
1174
|
+
const O = await ke({
|
|
1175
|
+
username: u,
|
|
1176
|
+
password: w,
|
|
1162
1177
|
clientId: r,
|
|
1163
1178
|
sessionExpiration: t,
|
|
1164
|
-
nonce:
|
|
1165
|
-
type:
|
|
1179
|
+
nonce: I,
|
|
1180
|
+
type: b
|
|
1166
1181
|
});
|
|
1167
|
-
return
|
|
1182
|
+
return O.status ? (s(O.idToken), c(O.accessToken), p(O.refreshToken), T({
|
|
1168
1183
|
isLoading: !1,
|
|
1169
1184
|
isAuthenticated: !0,
|
|
1170
1185
|
user: {
|
|
1171
|
-
userId:
|
|
1172
|
-
username:
|
|
1186
|
+
userId: O.userId,
|
|
1187
|
+
username: u
|
|
1173
1188
|
}
|
|
1174
|
-
}), !0) : (
|
|
1175
|
-
},
|
|
1176
|
-
|
|
1177
|
-
idToken:
|
|
1178
|
-
accessToken:
|
|
1179
|
-
refreshToken:
|
|
1189
|
+
}), !0) : (k(Ae), !1);
|
|
1190
|
+
}, $e = async (u) => {
|
|
1191
|
+
u == null || u.preventDefault(), k(qt), await oe({
|
|
1192
|
+
idToken: n,
|
|
1193
|
+
accessToken: i,
|
|
1194
|
+
refreshToken: y,
|
|
1180
1195
|
clientId: r
|
|
1181
|
-
})
|
|
1182
|
-
|
|
1183
|
-
|
|
1196
|
+
}), T((w) => ({
|
|
1197
|
+
...w,
|
|
1198
|
+
isLoading: !1
|
|
1199
|
+
}));
|
|
1200
|
+
}, We = async () => {
|
|
1201
|
+
const { isAuthenticated: u, user: w } = P;
|
|
1184
1202
|
try {
|
|
1185
|
-
if (
|
|
1186
|
-
if (
|
|
1187
|
-
const
|
|
1188
|
-
if (
|
|
1189
|
-
return
|
|
1203
|
+
if (u && w && w.userId) {
|
|
1204
|
+
if (i) {
|
|
1205
|
+
const I = await H(i);
|
|
1206
|
+
if (I && I.payload[m.USER_ID_KEY] !== "")
|
|
1207
|
+
return i;
|
|
1190
1208
|
}
|
|
1191
|
-
const
|
|
1209
|
+
const b = await Ne.refreshtoken({
|
|
1192
1210
|
clientId: r,
|
|
1193
|
-
userId:
|
|
1194
|
-
nonce:
|
|
1211
|
+
userId: w.userId,
|
|
1212
|
+
nonce: E
|
|
1195
1213
|
});
|
|
1196
|
-
return
|
|
1214
|
+
return b.status ? (c(b.newAccessToken), p(b.newRefreshToken), b.newAccessToken) : (k(se), "");
|
|
1197
1215
|
}
|
|
1198
|
-
return
|
|
1216
|
+
return k(se), "";
|
|
1199
1217
|
} catch {
|
|
1200
|
-
return
|
|
1218
|
+
return k(se), "";
|
|
1201
1219
|
}
|
|
1202
|
-
},
|
|
1203
|
-
if (
|
|
1204
|
-
return
|
|
1220
|
+
}, Je = () => {
|
|
1221
|
+
if (P.isAuthenticated && n)
|
|
1222
|
+
return n;
|
|
1205
1223
|
};
|
|
1206
|
-
return /* @__PURE__ */
|
|
1207
|
-
|
|
1224
|
+
return /* @__PURE__ */ Ve(
|
|
1225
|
+
Ke.Provider,
|
|
1208
1226
|
{
|
|
1209
|
-
value: { ...
|
|
1227
|
+
value: { ...P, login: Le, logout: $e, getAccessToken: We, getIdToken: Je },
|
|
1210
1228
|
children: e
|
|
1211
1229
|
}
|
|
1212
1230
|
);
|
|
1213
|
-
},
|
|
1231
|
+
}, cr = (e = Ke) => ze(e);
|
|
1214
1232
|
export {
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1233
|
+
F as AUTH_TYPES,
|
|
1234
|
+
ir as AuthProvider,
|
|
1235
|
+
cr as useAuth
|
|
1218
1236
|
};
|