@versini/auth-provider 4.1.0 → 4.3.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 +10 -3
- package/dist/index.js +507 -340
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -1,55 +1,81 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import * as
|
|
3
|
-
import { createContext as
|
|
1
|
+
import { jsx as Ue } from "react/jsx-runtime";
|
|
2
|
+
import * as D from "react";
|
|
3
|
+
import { createContext as Ne, useState as He, useCallback as Le, useEffect as $e, useContext as Ke } from "react";
|
|
4
4
|
/*!
|
|
5
|
-
@versini/auth-provider v4.
|
|
5
|
+
@versini/auth-provider v4.3.0
|
|
6
6
|
© 2024 gizmette.com
|
|
7
7
|
*/
|
|
8
8
|
try {
|
|
9
9
|
window.__VERSINI_AUTH_CLIENT__ || (window.__VERSINI_AUTH_CLIENT__ = {
|
|
10
|
-
version: "4.
|
|
11
|
-
buildTime: "06/
|
|
10
|
+
version: "4.3.0",
|
|
11
|
+
buildTime: "06/28/2024 11:03 AM 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.
|
|
18
|
+
@versini/auth-common v2.9.0
|
|
19
19
|
© 2024 gizmette.com
|
|
20
20
|
*/
|
|
21
21
|
try {
|
|
22
22
|
window.__VERSINI_AUTH_COMMON__ || (window.__VERSINI_AUTH_COMMON__ = {
|
|
23
|
-
version: "2.
|
|
24
|
-
buildTime: "06/
|
|
23
|
+
version: "2.9.0",
|
|
24
|
+
buildTime: "06/28/2024 11:03 AM EDT",
|
|
25
25
|
homepage: "https://github.com/aversini/auth-client",
|
|
26
26
|
license: "MIT"
|
|
27
27
|
});
|
|
28
28
|
} catch {
|
|
29
29
|
}
|
|
30
|
-
const
|
|
31
|
-
|
|
30
|
+
const M = {
|
|
31
|
+
ID_TOKEN: "id_token",
|
|
32
|
+
ACCESS_TOKEN: "token",
|
|
33
|
+
ID_AND_ACCESS_TOKEN: "id_token token",
|
|
34
|
+
CODE: "code",
|
|
35
|
+
REFRESH_TOKEN: "refresh_token"
|
|
36
|
+
}, Je = {
|
|
37
|
+
CLIENT_ID: "X-Auth-ClientId"
|
|
38
|
+
}, f = {
|
|
39
|
+
ALG: "RS256",
|
|
40
|
+
USER_ID_KEY: "sub",
|
|
41
|
+
TOKEN_ID_KEY: "__raw",
|
|
42
|
+
NONCE_KEY: "_nonce",
|
|
43
|
+
ISSUER: "gizmette.com"
|
|
44
|
+
}, We = `-----BEGIN PUBLIC KEY-----
|
|
45
|
+
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAsF6i3Jd9fY/3COqCw/m7
|
|
46
|
+
w5PKyTYLGAI2I6SIIdpe6i6DOCbEkmDz7LdVsBqwNtVi8gvWYIj+8ol6rU3qu1v5
|
|
47
|
+
i1Jd45GSK4kzkVdgCmQZbM5ak0KI99q5wsrAIzUd+LRJ2HRvWtr5IYdsIiXaQjle
|
|
48
|
+
aMwPFOIcJH+rKfFgNcHLcaS5syp7zU1ANwZ+trgR+DifBr8TLVkBynmNeTyhDm2+
|
|
49
|
+
l0haqjMk0UoNPPE8iYBWUHQJJE1Dqstj65d6Eh5g64Pao25y4cmYJbKjiblIGEkE
|
|
50
|
+
sjqybA9mARAqh9k/eiIopecWSiffNQTwVQVd2I9ZH3BalhEXHlqFgrjz51kFqg81
|
|
51
|
+
awIDAQAB
|
|
52
|
+
-----END PUBLIC KEY-----`, V = {
|
|
53
|
+
AUTHENTICATE: "authenticate",
|
|
54
|
+
CODE: "code",
|
|
55
|
+
LOGOUT: "logout"
|
|
56
|
+
}, te = crypto, Ee = (e) => e instanceof CryptoKey, L = new TextEncoder(), Y = new TextDecoder();
|
|
57
|
+
function xe(...e) {
|
|
32
58
|
const t = e.reduce((a, { length: s }) => a + s, 0), o = new Uint8Array(t);
|
|
33
59
|
let r = 0;
|
|
34
60
|
for (const a of e)
|
|
35
61
|
o.set(a, r), r += a.length;
|
|
36
62
|
return o;
|
|
37
63
|
}
|
|
38
|
-
const
|
|
64
|
+
const je = (e) => {
|
|
39
65
|
const t = atob(e), o = new Uint8Array(t.length);
|
|
40
66
|
for (let r = 0; r < t.length; r++)
|
|
41
67
|
o[r] = t.charCodeAt(r);
|
|
42
68
|
return o;
|
|
43
|
-
},
|
|
69
|
+
}, B = (e) => {
|
|
44
70
|
let t = e;
|
|
45
|
-
t instanceof Uint8Array && (t =
|
|
71
|
+
t instanceof Uint8Array && (t = Y.decode(t)), t = t.replace(/-/g, "+").replace(/_/g, "/").replace(/\s/g, "");
|
|
46
72
|
try {
|
|
47
|
-
return
|
|
73
|
+
return je(t);
|
|
48
74
|
} catch {
|
|
49
75
|
throw new TypeError("The input to be decoded is not correctly encoded.");
|
|
50
76
|
}
|
|
51
77
|
};
|
|
52
|
-
|
|
78
|
+
class C extends Error {
|
|
53
79
|
static get code() {
|
|
54
80
|
return "ERR_JOSE_GENERIC";
|
|
55
81
|
}
|
|
@@ -57,8 +83,8 @@ let b = class extends Error {
|
|
|
57
83
|
var o;
|
|
58
84
|
super(t), this.code = "ERR_JOSE_GENERIC", this.name = this.constructor.name, (o = Error.captureStackTrace) == null || o.call(Error, this, this.constructor);
|
|
59
85
|
}
|
|
60
|
-
}
|
|
61
|
-
class
|
|
86
|
+
}
|
|
87
|
+
class g extends C {
|
|
62
88
|
static get code() {
|
|
63
89
|
return "ERR_JWT_CLAIM_VALIDATION_FAILED";
|
|
64
90
|
}
|
|
@@ -66,7 +92,7 @@ class S extends b {
|
|
|
66
92
|
super(t), this.code = "ERR_JWT_CLAIM_VALIDATION_FAILED", this.claim = r, this.reason = a, this.payload = o;
|
|
67
93
|
}
|
|
68
94
|
}
|
|
69
|
-
class
|
|
95
|
+
class ae extends C {
|
|
70
96
|
static get code() {
|
|
71
97
|
return "ERR_JWT_EXPIRED";
|
|
72
98
|
}
|
|
@@ -74,7 +100,7 @@ class V extends b {
|
|
|
74
100
|
super(t), this.code = "ERR_JWT_EXPIRED", this.claim = r, this.reason = a, this.payload = o;
|
|
75
101
|
}
|
|
76
102
|
}
|
|
77
|
-
class
|
|
103
|
+
class Me extends C {
|
|
78
104
|
constructor() {
|
|
79
105
|
super(...arguments), this.code = "ERR_JOSE_ALG_NOT_ALLOWED";
|
|
80
106
|
}
|
|
@@ -82,7 +108,7 @@ class Ae extends b {
|
|
|
82
108
|
return "ERR_JOSE_ALG_NOT_ALLOWED";
|
|
83
109
|
}
|
|
84
110
|
}
|
|
85
|
-
class
|
|
111
|
+
class F extends C {
|
|
86
112
|
constructor() {
|
|
87
113
|
super(...arguments), this.code = "ERR_JOSE_NOT_SUPPORTED";
|
|
88
114
|
}
|
|
@@ -90,7 +116,7 @@ class P extends b {
|
|
|
90
116
|
return "ERR_JOSE_NOT_SUPPORTED";
|
|
91
117
|
}
|
|
92
118
|
}
|
|
93
|
-
let
|
|
119
|
+
let h = class extends C {
|
|
94
120
|
constructor() {
|
|
95
121
|
super(...arguments), this.code = "ERR_JWS_INVALID";
|
|
96
122
|
}
|
|
@@ -98,7 +124,7 @@ let d = class extends b {
|
|
|
98
124
|
return "ERR_JWS_INVALID";
|
|
99
125
|
}
|
|
100
126
|
};
|
|
101
|
-
class
|
|
127
|
+
class Se extends C {
|
|
102
128
|
constructor() {
|
|
103
129
|
super(...arguments), this.code = "ERR_JWT_INVALID";
|
|
104
130
|
}
|
|
@@ -106,7 +132,7 @@ class ee extends b {
|
|
|
106
132
|
return "ERR_JWT_INVALID";
|
|
107
133
|
}
|
|
108
134
|
}
|
|
109
|
-
class
|
|
135
|
+
class Ve extends C {
|
|
110
136
|
constructor() {
|
|
111
137
|
super(...arguments), this.code = "ERR_JWS_SIGNATURE_VERIFICATION_FAILED", this.message = "signature verification failed";
|
|
112
138
|
}
|
|
@@ -114,16 +140,16 @@ class _e extends b {
|
|
|
114
140
|
return "ERR_JWS_SIGNATURE_VERIFICATION_FAILED";
|
|
115
141
|
}
|
|
116
142
|
}
|
|
117
|
-
function
|
|
143
|
+
function _(e, t = "algorithm.name") {
|
|
118
144
|
return new TypeError(`CryptoKey does not support this operation, its ${t} must be ${e}`);
|
|
119
145
|
}
|
|
120
|
-
function
|
|
146
|
+
function $(e, t) {
|
|
121
147
|
return e.name === t;
|
|
122
148
|
}
|
|
123
|
-
function
|
|
149
|
+
function q(e) {
|
|
124
150
|
return parseInt(e.name.slice(4), 10);
|
|
125
151
|
}
|
|
126
|
-
function
|
|
152
|
+
function Ye(e) {
|
|
127
153
|
switch (e) {
|
|
128
154
|
case "ES256":
|
|
129
155
|
return "P-256";
|
|
@@ -135,7 +161,7 @@ function be(e) {
|
|
|
135
161
|
throw new Error("unreachable");
|
|
136
162
|
}
|
|
137
163
|
}
|
|
138
|
-
function
|
|
164
|
+
function Fe(e, t) {
|
|
139
165
|
if (t.length && !t.some((o) => e.usages.includes(o))) {
|
|
140
166
|
let o = "CryptoKey does not support this operation, its usages must include ";
|
|
141
167
|
if (t.length > 2) {
|
|
@@ -146,59 +172,59 @@ function Ie(e, t) {
|
|
|
146
172
|
throw new TypeError(o);
|
|
147
173
|
}
|
|
148
174
|
}
|
|
149
|
-
function
|
|
175
|
+
function Ge(e, t, ...o) {
|
|
150
176
|
switch (t) {
|
|
151
177
|
case "HS256":
|
|
152
178
|
case "HS384":
|
|
153
179
|
case "HS512": {
|
|
154
|
-
if (
|
|
155
|
-
throw
|
|
180
|
+
if (!$(e.algorithm, "HMAC"))
|
|
181
|
+
throw _("HMAC");
|
|
156
182
|
const r = parseInt(t.slice(2), 10);
|
|
157
|
-
if (
|
|
158
|
-
throw
|
|
183
|
+
if (q(e.algorithm.hash) !== r)
|
|
184
|
+
throw _(`SHA-${r}`, "algorithm.hash");
|
|
159
185
|
break;
|
|
160
186
|
}
|
|
161
187
|
case "RS256":
|
|
162
188
|
case "RS384":
|
|
163
189
|
case "RS512": {
|
|
164
|
-
if (
|
|
165
|
-
throw
|
|
190
|
+
if (!$(e.algorithm, "RSASSA-PKCS1-v1_5"))
|
|
191
|
+
throw _("RSASSA-PKCS1-v1_5");
|
|
166
192
|
const r = parseInt(t.slice(2), 10);
|
|
167
|
-
if (
|
|
168
|
-
throw
|
|
193
|
+
if (q(e.algorithm.hash) !== r)
|
|
194
|
+
throw _(`SHA-${r}`, "algorithm.hash");
|
|
169
195
|
break;
|
|
170
196
|
}
|
|
171
197
|
case "PS256":
|
|
172
198
|
case "PS384":
|
|
173
199
|
case "PS512": {
|
|
174
|
-
if (
|
|
175
|
-
throw
|
|
200
|
+
if (!$(e.algorithm, "RSA-PSS"))
|
|
201
|
+
throw _("RSA-PSS");
|
|
176
202
|
const r = parseInt(t.slice(2), 10);
|
|
177
|
-
if (
|
|
178
|
-
throw
|
|
203
|
+
if (q(e.algorithm.hash) !== r)
|
|
204
|
+
throw _(`SHA-${r}`, "algorithm.hash");
|
|
179
205
|
break;
|
|
180
206
|
}
|
|
181
207
|
case "EdDSA": {
|
|
182
208
|
if (e.algorithm.name !== "Ed25519" && e.algorithm.name !== "Ed448")
|
|
183
|
-
throw
|
|
209
|
+
throw _("Ed25519 or Ed448");
|
|
184
210
|
break;
|
|
185
211
|
}
|
|
186
212
|
case "ES256":
|
|
187
213
|
case "ES384":
|
|
188
214
|
case "ES512": {
|
|
189
|
-
if (
|
|
190
|
-
throw
|
|
191
|
-
const r =
|
|
215
|
+
if (!$(e.algorithm, "ECDSA"))
|
|
216
|
+
throw _("ECDSA");
|
|
217
|
+
const r = Ye(t);
|
|
192
218
|
if (e.algorithm.namedCurve !== r)
|
|
193
|
-
throw
|
|
219
|
+
throw _(r, "algorithm.namedCurve");
|
|
194
220
|
break;
|
|
195
221
|
}
|
|
196
222
|
default:
|
|
197
223
|
throw new TypeError("CryptoKey does not support this operation");
|
|
198
224
|
}
|
|
199
|
-
|
|
225
|
+
Fe(e, o);
|
|
200
226
|
}
|
|
201
|
-
function
|
|
227
|
+
function ge(e, t, ...o) {
|
|
202
228
|
var r;
|
|
203
229
|
if (o.length > 2) {
|
|
204
230
|
const a = o.pop();
|
|
@@ -207,11 +233,11 @@ function te(e, t, ...o) {
|
|
|
207
233
|
o.length === 2 ? e += `one of type ${o[0]} or ${o[1]}.` : e += `of type ${o[0]}.`;
|
|
208
234
|
return t == null ? e += ` Received ${t}` : typeof t == "function" && t.name ? e += ` Received function ${t.name}` : typeof t == "object" && t != null && (r = t.constructor) != null && r.name && (e += ` Received an instance of ${t.constructor.name}`), e;
|
|
209
235
|
}
|
|
210
|
-
const
|
|
211
|
-
function
|
|
212
|
-
return
|
|
236
|
+
const ne = (e, ...t) => ge("Key must be ", e, ...t);
|
|
237
|
+
function Ae(e, t, ...o) {
|
|
238
|
+
return ge(`Key for the ${e} algorithm must be `, t, ...o);
|
|
213
239
|
}
|
|
214
|
-
const
|
|
240
|
+
const _e = (e) => Ee(e), I = ["CryptoKey"], Be = (...e) => {
|
|
215
241
|
const t = e.filter(Boolean);
|
|
216
242
|
if (t.length === 0 || t.length === 1)
|
|
217
243
|
return !0;
|
|
@@ -230,11 +256,11 @@ const oe = (e) => Z(e), A = ["CryptoKey"], ve = (...e) => {
|
|
|
230
256
|
}
|
|
231
257
|
return !0;
|
|
232
258
|
};
|
|
233
|
-
function
|
|
259
|
+
function qe(e) {
|
|
234
260
|
return typeof e == "object" && e !== null;
|
|
235
261
|
}
|
|
236
|
-
function
|
|
237
|
-
if (!
|
|
262
|
+
function ee(e) {
|
|
263
|
+
if (!qe(e) || Object.prototype.toString.call(e) !== "[object Object]")
|
|
238
264
|
return !1;
|
|
239
265
|
if (Object.getPrototypeOf(e) === null)
|
|
240
266
|
return !0;
|
|
@@ -243,39 +269,39 @@ function W(e) {
|
|
|
243
269
|
t = Object.getPrototypeOf(t);
|
|
244
270
|
return Object.getPrototypeOf(e) === t;
|
|
245
271
|
}
|
|
246
|
-
const
|
|
272
|
+
const ze = (e, t) => {
|
|
247
273
|
if (e.startsWith("RS") || e.startsWith("PS")) {
|
|
248
274
|
const { modulusLength: o } = t.algorithm;
|
|
249
275
|
if (typeof o != "number" || o < 2048)
|
|
250
276
|
throw new TypeError(`${e} requires key modulusLength to be 2048 bits or larger`);
|
|
251
277
|
}
|
|
252
|
-
},
|
|
278
|
+
}, b = (e, t, o = 0) => {
|
|
253
279
|
o === 0 && (t.unshift(t.length), t.unshift(6));
|
|
254
280
|
const r = e.indexOf(t[0], o);
|
|
255
281
|
if (r === -1)
|
|
256
282
|
return !1;
|
|
257
283
|
const a = e.subarray(r, r + t.length);
|
|
258
|
-
return a.length !== t.length ? !1 : a.every((s, n) => s === t[n]) ||
|
|
259
|
-
},
|
|
284
|
+
return a.length !== t.length ? !1 : a.every((s, n) => s === t[n]) || b(e, t, r + 1);
|
|
285
|
+
}, se = (e) => {
|
|
260
286
|
switch (!0) {
|
|
261
|
-
case
|
|
287
|
+
case b(e, [42, 134, 72, 206, 61, 3, 1, 7]):
|
|
262
288
|
return "P-256";
|
|
263
|
-
case
|
|
289
|
+
case b(e, [43, 129, 4, 0, 34]):
|
|
264
290
|
return "P-384";
|
|
265
|
-
case
|
|
291
|
+
case b(e, [43, 129, 4, 0, 35]):
|
|
266
292
|
return "P-521";
|
|
267
|
-
case
|
|
293
|
+
case b(e, [43, 101, 110]):
|
|
268
294
|
return "X25519";
|
|
269
|
-
case
|
|
295
|
+
case b(e, [43, 101, 111]):
|
|
270
296
|
return "X448";
|
|
271
|
-
case
|
|
297
|
+
case b(e, [43, 101, 112]):
|
|
272
298
|
return "Ed25519";
|
|
273
|
-
case
|
|
299
|
+
case b(e, [43, 101, 113]):
|
|
274
300
|
return "Ed448";
|
|
275
301
|
default:
|
|
276
|
-
throw new
|
|
302
|
+
throw new F("Invalid or unsupported EC Key Curve or OKP Key Sub Type");
|
|
277
303
|
}
|
|
278
|
-
},
|
|
304
|
+
}, Xe = async (e, t, o, r, a) => {
|
|
279
305
|
let s, n;
|
|
280
306
|
const i = new Uint8Array(atob(o.replace(e, "")).split("").map((c) => c.charCodeAt(0)));
|
|
281
307
|
switch (r) {
|
|
@@ -311,43 +337,43 @@ const ke = (e, t) => {
|
|
|
311
337
|
case "ECDH-ES+A128KW":
|
|
312
338
|
case "ECDH-ES+A192KW":
|
|
313
339
|
case "ECDH-ES+A256KW": {
|
|
314
|
-
const c =
|
|
340
|
+
const c = se(i);
|
|
315
341
|
s = c.startsWith("P-") ? { name: "ECDH", namedCurve: c } : { name: c }, n = [];
|
|
316
342
|
break;
|
|
317
343
|
}
|
|
318
344
|
case "EdDSA":
|
|
319
|
-
s = { name:
|
|
345
|
+
s = { name: se(i) }, n = ["verify"];
|
|
320
346
|
break;
|
|
321
347
|
default:
|
|
322
|
-
throw new
|
|
348
|
+
throw new F('Invalid or unsupported "alg" (Algorithm) value');
|
|
323
349
|
}
|
|
324
|
-
return
|
|
325
|
-
},
|
|
326
|
-
async function
|
|
350
|
+
return te.subtle.importKey(t, i, s, !1, n);
|
|
351
|
+
}, Qe = (e, t, o) => Xe(/(?:-----(?:BEGIN|END) PUBLIC KEY-----|\s)/g, "spki", e, t);
|
|
352
|
+
async function Ze(e, t, o) {
|
|
327
353
|
if (e.indexOf("-----BEGIN PUBLIC KEY-----") !== 0)
|
|
328
354
|
throw new TypeError('"spki" must be SPKI formatted string');
|
|
329
|
-
return
|
|
355
|
+
return Qe(e, t);
|
|
330
356
|
}
|
|
331
|
-
const
|
|
357
|
+
const et = (e, t) => {
|
|
332
358
|
if (!(t instanceof Uint8Array)) {
|
|
333
|
-
if (!
|
|
334
|
-
throw new TypeError(
|
|
359
|
+
if (!_e(t))
|
|
360
|
+
throw new TypeError(Ae(e, t, ...I, "Uint8Array"));
|
|
335
361
|
if (t.type !== "secret")
|
|
336
|
-
throw new TypeError(`${
|
|
362
|
+
throw new TypeError(`${I.join(" or ")} instances for symmetric algorithms must be of type "secret"`);
|
|
337
363
|
}
|
|
338
|
-
},
|
|
339
|
-
if (!
|
|
340
|
-
throw new TypeError(
|
|
364
|
+
}, tt = (e, t, o) => {
|
|
365
|
+
if (!_e(t))
|
|
366
|
+
throw new TypeError(Ae(e, t, ...I));
|
|
341
367
|
if (t.type === "secret")
|
|
342
|
-
throw new TypeError(`${
|
|
368
|
+
throw new TypeError(`${I.join(" or ")} instances for asymmetric algorithms must not be of type "secret"`);
|
|
343
369
|
if (t.algorithm && o === "verify" && t.type === "private")
|
|
344
|
-
throw new TypeError(`${
|
|
370
|
+
throw new TypeError(`${I.join(" or ")} instances for asymmetric algorithm verifying must be of type "public"`);
|
|
345
371
|
if (t.algorithm && o === "encrypt" && t.type === "private")
|
|
346
|
-
throw new TypeError(`${
|
|
347
|
-
},
|
|
348
|
-
e.startsWith("HS") || e === "dir" || e.startsWith("PBES2") || /^A\d{3}(?:GCM)?KW$/.test(e) ?
|
|
372
|
+
throw new TypeError(`${I.join(" or ")} instances for asymmetric algorithm encryption must be of type "public"`);
|
|
373
|
+
}, rt = (e, t, o) => {
|
|
374
|
+
e.startsWith("HS") || e === "dir" || e.startsWith("PBES2") || /^A\d{3}(?:GCM)?KW$/.test(e) ? et(e, t) : tt(e, t, o);
|
|
349
375
|
};
|
|
350
|
-
function
|
|
376
|
+
function ot(e, t, o, r, a) {
|
|
351
377
|
if (a.crit !== void 0 && (r == null ? void 0 : r.crit) === void 0)
|
|
352
378
|
throw new e('"crit" (Critical) Header Parameter MUST be integrity protected');
|
|
353
379
|
if (!r || r.crit === void 0)
|
|
@@ -358,7 +384,7 @@ function He(e, t, o, r, a) {
|
|
|
358
384
|
o !== void 0 ? s = new Map([...Object.entries(o), ...t.entries()]) : s = t;
|
|
359
385
|
for (const n of r.crit) {
|
|
360
386
|
if (!s.has(n))
|
|
361
|
-
throw new
|
|
387
|
+
throw new F(`Extension Header Parameter "${n}" is not recognized`);
|
|
362
388
|
if (a[n] === void 0)
|
|
363
389
|
throw new e(`Extension Header Parameter "${n}" is missing`);
|
|
364
390
|
if (s.get(n) && r[n] === void 0)
|
|
@@ -366,13 +392,13 @@ function He(e, t, o, r, a) {
|
|
|
366
392
|
}
|
|
367
393
|
return new Set(r.crit);
|
|
368
394
|
}
|
|
369
|
-
const
|
|
395
|
+
const at = (e, t) => {
|
|
370
396
|
if (t !== void 0 && (!Array.isArray(t) || t.some((o) => typeof o != "string")))
|
|
371
397
|
throw new TypeError(`"${e}" option must be an array of strings`);
|
|
372
398
|
if (t)
|
|
373
399
|
return new Set(t);
|
|
374
400
|
};
|
|
375
|
-
function
|
|
401
|
+
function nt(e, t) {
|
|
376
402
|
const o = `SHA-${e.slice(-3)}`;
|
|
377
403
|
switch (e) {
|
|
378
404
|
case "HS256":
|
|
@@ -394,104 +420,104 @@ function $e(e, t) {
|
|
|
394
420
|
case "EdDSA":
|
|
395
421
|
return { name: t.name };
|
|
396
422
|
default:
|
|
397
|
-
throw new
|
|
423
|
+
throw new F(`alg ${e} is not supported either by JOSE or your javascript runtime`);
|
|
398
424
|
}
|
|
399
425
|
}
|
|
400
|
-
function
|
|
401
|
-
if (
|
|
402
|
-
return
|
|
426
|
+
function st(e, t, o) {
|
|
427
|
+
if (Ee(t))
|
|
428
|
+
return Ge(t, e, o), t;
|
|
403
429
|
if (t instanceof Uint8Array) {
|
|
404
430
|
if (!e.startsWith("HS"))
|
|
405
|
-
throw new TypeError(
|
|
406
|
-
return
|
|
431
|
+
throw new TypeError(ne(t, ...I));
|
|
432
|
+
return te.subtle.importKey("raw", t, { hash: `SHA-${e.slice(-3)}`, name: "HMAC" }, !1, [o]);
|
|
407
433
|
}
|
|
408
|
-
throw new TypeError(
|
|
434
|
+
throw new TypeError(ne(t, ...I, "Uint8Array"));
|
|
409
435
|
}
|
|
410
|
-
const
|
|
411
|
-
const a = await
|
|
412
|
-
|
|
413
|
-
const s =
|
|
436
|
+
const ct = async (e, t, o, r) => {
|
|
437
|
+
const a = await st(e, t, "verify");
|
|
438
|
+
ze(e, a);
|
|
439
|
+
const s = nt(e, a.algorithm);
|
|
414
440
|
try {
|
|
415
|
-
return await
|
|
441
|
+
return await te.subtle.verify(s, a, o, r);
|
|
416
442
|
} catch {
|
|
417
443
|
return !1;
|
|
418
444
|
}
|
|
419
445
|
};
|
|
420
|
-
async function
|
|
421
|
-
if (!
|
|
422
|
-
throw new
|
|
446
|
+
async function it(e, t, o) {
|
|
447
|
+
if (!ee(e))
|
|
448
|
+
throw new h("Flattened JWS must be an object");
|
|
423
449
|
if (e.protected === void 0 && e.header === void 0)
|
|
424
|
-
throw new
|
|
450
|
+
throw new h('Flattened JWS must have either of the "protected" or "header" members');
|
|
425
451
|
if (e.protected !== void 0 && typeof e.protected != "string")
|
|
426
|
-
throw new
|
|
452
|
+
throw new h("JWS Protected Header incorrect type");
|
|
427
453
|
if (e.payload === void 0)
|
|
428
|
-
throw new
|
|
454
|
+
throw new h("JWS Payload missing");
|
|
429
455
|
if (typeof e.signature != "string")
|
|
430
|
-
throw new
|
|
431
|
-
if (e.header !== void 0 && !
|
|
432
|
-
throw new
|
|
456
|
+
throw new h("JWS Signature missing or incorrect type");
|
|
457
|
+
if (e.header !== void 0 && !ee(e.header))
|
|
458
|
+
throw new h("JWS Unprotected Header incorrect type");
|
|
433
459
|
let r = {};
|
|
434
460
|
if (e.protected)
|
|
435
461
|
try {
|
|
436
|
-
const
|
|
437
|
-
r = JSON.parse(
|
|
462
|
+
const m = B(e.protected);
|
|
463
|
+
r = JSON.parse(Y.decode(m));
|
|
438
464
|
} catch {
|
|
439
|
-
throw new
|
|
465
|
+
throw new h("JWS Protected Header is invalid");
|
|
440
466
|
}
|
|
441
|
-
if (!
|
|
442
|
-
throw new
|
|
467
|
+
if (!Be(r, e.header))
|
|
468
|
+
throw new h("JWS Protected and JWS Unprotected Header Parameter names must be disjoint");
|
|
443
469
|
const a = {
|
|
444
470
|
...r,
|
|
445
471
|
...e.header
|
|
446
|
-
}, s =
|
|
472
|
+
}, s = ot(h, /* @__PURE__ */ new Map([["b64", !0]]), o == null ? void 0 : o.crit, r, a);
|
|
447
473
|
let n = !0;
|
|
448
474
|
if (s.has("b64") && (n = r.b64, typeof n != "boolean"))
|
|
449
|
-
throw new
|
|
475
|
+
throw new h('The "b64" (base64url-encode payload) Header Parameter must be a boolean');
|
|
450
476
|
const { alg: i } = a;
|
|
451
477
|
if (typeof i != "string" || !i)
|
|
452
|
-
throw new
|
|
453
|
-
const c = o &&
|
|
478
|
+
throw new h('JWS "alg" (Algorithm) Header Parameter missing or invalid');
|
|
479
|
+
const c = o && at("algorithms", o.algorithms);
|
|
454
480
|
if (c && !c.has(i))
|
|
455
|
-
throw new
|
|
481
|
+
throw new Me('"alg" (Algorithm) Header Parameter value not allowed');
|
|
456
482
|
if (n) {
|
|
457
483
|
if (typeof e.payload != "string")
|
|
458
|
-
throw new
|
|
484
|
+
throw new h("JWS Payload must be a string");
|
|
459
485
|
} else if (typeof e.payload != "string" && !(e.payload instanceof Uint8Array))
|
|
460
|
-
throw new
|
|
461
|
-
let
|
|
462
|
-
typeof t == "function" && (t = await t(r, e),
|
|
463
|
-
const y =
|
|
464
|
-
let
|
|
486
|
+
throw new h("JWS Payload must be a string or an Uint8Array instance");
|
|
487
|
+
let u = !1;
|
|
488
|
+
typeof t == "function" && (t = await t(r, e), u = !0), rt(i, t, "verify");
|
|
489
|
+
const y = xe(L.encode(e.protected ?? ""), L.encode("."), typeof e.payload == "string" ? L.encode(e.payload) : e.payload);
|
|
490
|
+
let p;
|
|
465
491
|
try {
|
|
466
|
-
|
|
492
|
+
p = B(e.signature);
|
|
467
493
|
} catch {
|
|
468
|
-
throw new
|
|
494
|
+
throw new h("Failed to base64url decode the signature");
|
|
469
495
|
}
|
|
470
|
-
if (!await
|
|
471
|
-
throw new
|
|
472
|
-
let
|
|
496
|
+
if (!await ct(i, t, p, y))
|
|
497
|
+
throw new Ve();
|
|
498
|
+
let T;
|
|
473
499
|
if (n)
|
|
474
500
|
try {
|
|
475
|
-
|
|
501
|
+
T = B(e.payload);
|
|
476
502
|
} catch {
|
|
477
|
-
throw new
|
|
503
|
+
throw new h("Failed to base64url decode the payload");
|
|
478
504
|
}
|
|
479
505
|
else
|
|
480
|
-
typeof e.payload == "string" ?
|
|
481
|
-
const
|
|
482
|
-
return e.protected !== void 0 && (
|
|
506
|
+
typeof e.payload == "string" ? T = L.encode(e.payload) : T = e.payload;
|
|
507
|
+
const E = { payload: T };
|
|
508
|
+
return e.protected !== void 0 && (E.protectedHeader = r), e.header !== void 0 && (E.unprotectedHeader = e.header), u ? { ...E, key: t } : E;
|
|
483
509
|
}
|
|
484
|
-
async function
|
|
485
|
-
if (e instanceof Uint8Array && (e =
|
|
486
|
-
throw new
|
|
510
|
+
async function ut(e, t, o) {
|
|
511
|
+
if (e instanceof Uint8Array && (e = Y.decode(e)), typeof e != "string")
|
|
512
|
+
throw new h("Compact JWS must be a string or Uint8Array");
|
|
487
513
|
const { 0: r, 1: a, 2: s, length: n } = e.split(".");
|
|
488
514
|
if (n !== 3)
|
|
489
|
-
throw new
|
|
490
|
-
const i = await
|
|
515
|
+
throw new h("Invalid Compact JWS");
|
|
516
|
+
const i = await it({ payload: a, protected: r, signature: s }, t, o), c = { payload: i.payload, protectedHeader: i.protectedHeader };
|
|
491
517
|
return typeof t == "function" ? { ...c, key: i.key } : c;
|
|
492
518
|
}
|
|
493
|
-
const
|
|
494
|
-
const t =
|
|
519
|
+
const dt = (e) => Math.floor(e.getTime() / 1e3), Te = 60, be = Te * 60, re = be * 24, lt = re * 7, ht = re * 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, ce = (e) => {
|
|
520
|
+
const t = pt.exec(e);
|
|
495
521
|
if (!t || t[4] && t[1])
|
|
496
522
|
throw new TypeError("Invalid time period format");
|
|
497
523
|
const o = parseFloat(t[2]), r = t[3].toLowerCase();
|
|
@@ -509,237 +535,260 @@ const je = (e) => Math.floor(e.getTime() / 1e3), ae = 60, ne = ae * 60, j = ne *
|
|
|
509
535
|
case "min":
|
|
510
536
|
case "mins":
|
|
511
537
|
case "m":
|
|
512
|
-
a = Math.round(o *
|
|
538
|
+
a = Math.round(o * Te);
|
|
513
539
|
break;
|
|
514
540
|
case "hour":
|
|
515
541
|
case "hours":
|
|
516
542
|
case "hr":
|
|
517
543
|
case "hrs":
|
|
518
544
|
case "h":
|
|
519
|
-
a = Math.round(o *
|
|
545
|
+
a = Math.round(o * be);
|
|
520
546
|
break;
|
|
521
547
|
case "day":
|
|
522
548
|
case "days":
|
|
523
549
|
case "d":
|
|
524
|
-
a = Math.round(o *
|
|
550
|
+
a = Math.round(o * re);
|
|
525
551
|
break;
|
|
526
552
|
case "week":
|
|
527
553
|
case "weeks":
|
|
528
554
|
case "w":
|
|
529
|
-
a = Math.round(o *
|
|
555
|
+
a = Math.round(o * lt);
|
|
530
556
|
break;
|
|
531
557
|
default:
|
|
532
|
-
a = Math.round(o *
|
|
558
|
+
a = Math.round(o * ht);
|
|
533
559
|
break;
|
|
534
560
|
}
|
|
535
561
|
return t[1] === "-" || t[4] === "ago" ? -a : a;
|
|
536
|
-
},
|
|
562
|
+
}, ie = (e) => e.toLowerCase().replace(/^application\//, ""), ft = (e, t) => typeof e == "string" ? t.includes(e) : Array.isArray(e) ? t.some(Set.prototype.has.bind(new Set(e))) : !1, yt = (e, t, o = {}) => {
|
|
537
563
|
let r;
|
|
538
564
|
try {
|
|
539
|
-
r = JSON.parse(
|
|
565
|
+
r = JSON.parse(Y.decode(t));
|
|
540
566
|
} catch {
|
|
541
567
|
}
|
|
542
|
-
if (!
|
|
543
|
-
throw new
|
|
568
|
+
if (!ee(r))
|
|
569
|
+
throw new Se("JWT Claims Set must be a top-level JSON object");
|
|
544
570
|
const { typ: a } = o;
|
|
545
|
-
if (a && (typeof e.typ != "string" ||
|
|
546
|
-
throw new
|
|
547
|
-
const { requiredClaims: s = [], issuer: n, subject: i, audience: c, maxTokenAge:
|
|
548
|
-
|
|
549
|
-
for (const
|
|
550
|
-
if (!(
|
|
551
|
-
throw new
|
|
571
|
+
if (a && (typeof e.typ != "string" || ie(e.typ) !== ie(a)))
|
|
572
|
+
throw new g('unexpected "typ" JWT header value', r, "typ", "check_failed");
|
|
573
|
+
const { requiredClaims: s = [], issuer: n, subject: i, audience: c, maxTokenAge: u } = o, y = [...s];
|
|
574
|
+
u !== void 0 && y.push("iat"), c !== void 0 && y.push("aud"), i !== void 0 && y.push("sub"), n !== void 0 && y.push("iss");
|
|
575
|
+
for (const m of new Set(y.reverse()))
|
|
576
|
+
if (!(m in r))
|
|
577
|
+
throw new g(`missing required "${m}" claim`, r, m, "missing");
|
|
552
578
|
if (n && !(Array.isArray(n) ? n : [n]).includes(r.iss))
|
|
553
|
-
throw new
|
|
579
|
+
throw new g('unexpected "iss" claim value', r, "iss", "check_failed");
|
|
554
580
|
if (i && r.sub !== i)
|
|
555
|
-
throw new
|
|
556
|
-
if (c && !
|
|
557
|
-
throw new
|
|
558
|
-
let
|
|
581
|
+
throw new g('unexpected "sub" claim value', r, "sub", "check_failed");
|
|
582
|
+
if (c && !ft(r.aud, typeof c == "string" ? [c] : c))
|
|
583
|
+
throw new g('unexpected "aud" claim value', r, "aud", "check_failed");
|
|
584
|
+
let p;
|
|
559
585
|
switch (typeof o.clockTolerance) {
|
|
560
586
|
case "string":
|
|
561
|
-
|
|
587
|
+
p = ce(o.clockTolerance);
|
|
562
588
|
break;
|
|
563
589
|
case "number":
|
|
564
|
-
|
|
590
|
+
p = o.clockTolerance;
|
|
565
591
|
break;
|
|
566
592
|
case "undefined":
|
|
567
|
-
|
|
593
|
+
p = 0;
|
|
568
594
|
break;
|
|
569
595
|
default:
|
|
570
596
|
throw new TypeError("Invalid clockTolerance option type");
|
|
571
597
|
}
|
|
572
|
-
const { currentDate:
|
|
573
|
-
if ((r.iat !== void 0 ||
|
|
574
|
-
throw new
|
|
598
|
+
const { currentDate: T } = o, E = dt(T || /* @__PURE__ */ new Date());
|
|
599
|
+
if ((r.iat !== void 0 || u) && typeof r.iat != "number")
|
|
600
|
+
throw new g('"iat" claim must be a number', r, "iat", "invalid");
|
|
575
601
|
if (r.nbf !== void 0) {
|
|
576
602
|
if (typeof r.nbf != "number")
|
|
577
|
-
throw new
|
|
578
|
-
if (r.nbf >
|
|
579
|
-
throw new
|
|
603
|
+
throw new g('"nbf" claim must be a number', r, "nbf", "invalid");
|
|
604
|
+
if (r.nbf > E + p)
|
|
605
|
+
throw new g('"nbf" claim timestamp check failed', r, "nbf", "check_failed");
|
|
580
606
|
}
|
|
581
607
|
if (r.exp !== void 0) {
|
|
582
608
|
if (typeof r.exp != "number")
|
|
583
|
-
throw new
|
|
584
|
-
if (r.exp <=
|
|
585
|
-
throw new
|
|
609
|
+
throw new g('"exp" claim must be a number', r, "exp", "invalid");
|
|
610
|
+
if (r.exp <= E - p)
|
|
611
|
+
throw new ae('"exp" claim timestamp check failed', r, "exp", "check_failed");
|
|
586
612
|
}
|
|
587
|
-
if (
|
|
588
|
-
const
|
|
589
|
-
if (
|
|
590
|
-
throw new
|
|
591
|
-
if (
|
|
592
|
-
throw new
|
|
613
|
+
if (u) {
|
|
614
|
+
const m = E - r.iat, v = typeof u == "number" ? u : ce(u);
|
|
615
|
+
if (m - p > v)
|
|
616
|
+
throw new ae('"iat" claim timestamp check failed (too far in the past)', r, "iat", "check_failed");
|
|
617
|
+
if (m < 0 - p)
|
|
618
|
+
throw new g('"iat" claim timestamp check failed (it should be in the past)', r, "iat", "check_failed");
|
|
593
619
|
}
|
|
594
620
|
return r;
|
|
595
621
|
};
|
|
596
|
-
async function
|
|
622
|
+
async function mt(e, t, o) {
|
|
597
623
|
var r;
|
|
598
|
-
const a = await
|
|
624
|
+
const a = await ut(e, t, o);
|
|
599
625
|
if ((r = a.protectedHeader.crit) != null && r.includes("b64") && a.protectedHeader.b64 === !1)
|
|
600
|
-
throw new
|
|
601
|
-
const s = { payload:
|
|
626
|
+
throw new Se("JWTs MUST NOT use unencoded payload");
|
|
627
|
+
const s = { payload: yt(a.protectedHeader, a.payload, o), protectedHeader: a.protectedHeader };
|
|
602
628
|
return typeof t == "function" ? { ...s, key: a.key } : s;
|
|
603
629
|
}
|
|
604
|
-
const
|
|
605
|
-
ID_TOKEN: "id_token",
|
|
606
|
-
ACCESS_TOKEN: "token",
|
|
607
|
-
ID_AND_ACCESS_TOKEN: "id_token token"
|
|
608
|
-
}, ze = {
|
|
609
|
-
CLIENT_ID: "X-Auth-ClientId"
|
|
610
|
-
}, _ = {
|
|
611
|
-
ALG: "RS256",
|
|
612
|
-
USER_ID_KEY: "_id",
|
|
613
|
-
TOKEN_ID_KEY: "__raw",
|
|
614
|
-
NONCE_KEY: "_nonce",
|
|
615
|
-
ISSUER: "gizmette.com"
|
|
616
|
-
}, Xe = `-----BEGIN PUBLIC KEY-----
|
|
617
|
-
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAsF6i3Jd9fY/3COqCw/m7
|
|
618
|
-
w5PKyTYLGAI2I6SIIdpe6i6DOCbEkmDz7LdVsBqwNtVi8gvWYIj+8ol6rU3qu1v5
|
|
619
|
-
i1Jd45GSK4kzkVdgCmQZbM5ak0KI99q5wsrAIzUd+LRJ2HRvWtr5IYdsIiXaQjle
|
|
620
|
-
aMwPFOIcJH+rKfFgNcHLcaS5syp7zU1ANwZ+trgR+DifBr8TLVkBynmNeTyhDm2+
|
|
621
|
-
l0haqjMk0UoNPPE8iYBWUHQJJE1Dqstj65d6Eh5g64Pao25y4cmYJbKjiblIGEkE
|
|
622
|
-
sjqybA9mARAqh9k/eiIopecWSiffNQTwVQVd2I9ZH3BalhEXHlqFgrjz51kFqg81
|
|
623
|
-
awIDAQAB
|
|
624
|
-
-----END PUBLIC KEY-----`, se = async (e, t) => {
|
|
630
|
+
const N = async (e) => {
|
|
625
631
|
try {
|
|
626
|
-
const
|
|
627
|
-
return await
|
|
628
|
-
issuer:
|
|
629
|
-
audience: t
|
|
632
|
+
const t = f.ALG, o = await Ze(We, t);
|
|
633
|
+
return await mt(e, o, {
|
|
634
|
+
issuer: f.ISSUER
|
|
630
635
|
});
|
|
631
636
|
} catch {
|
|
632
637
|
return;
|
|
633
638
|
}
|
|
634
639
|
};
|
|
635
|
-
|
|
640
|
+
var d = [];
|
|
641
|
+
for (var z = 0; z < 256; ++z)
|
|
642
|
+
d.push((z + 256).toString(16).slice(1));
|
|
643
|
+
function wt(e, t = 0) {
|
|
644
|
+
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();
|
|
645
|
+
}
|
|
646
|
+
var K, Et = new Uint8Array(16);
|
|
647
|
+
function St() {
|
|
648
|
+
if (!K && (K = typeof crypto < "u" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto), !K))
|
|
649
|
+
throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
|
|
650
|
+
return K(Et);
|
|
651
|
+
}
|
|
652
|
+
var gt = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto);
|
|
653
|
+
const ue = {
|
|
654
|
+
randomUUID: gt
|
|
655
|
+
};
|
|
656
|
+
function de(e, t, o) {
|
|
657
|
+
if (ue.randomUUID && !t && !e)
|
|
658
|
+
return ue.randomUUID();
|
|
659
|
+
e = e || {};
|
|
660
|
+
var r = e.random || (e.rng || St)();
|
|
661
|
+
return r[6] = r[6] & 15 | 64, r[8] = r[8] & 63 | 128, wt(r);
|
|
662
|
+
}
|
|
663
|
+
const le = globalThis.crypto, At = (e) => `${de()}${de()}`.slice(0, e), _t = (e) => btoa(
|
|
664
|
+
[...new Uint8Array(e)].map((t) => String.fromCharCode(t)).join("")
|
|
665
|
+
);
|
|
666
|
+
async function Tt(e) {
|
|
667
|
+
if (!le.subtle)
|
|
668
|
+
throw new Error(
|
|
669
|
+
"crypto.subtle is available only in secure contexts (HTTPS)."
|
|
670
|
+
);
|
|
671
|
+
const t = new TextEncoder().encode(e), o = await le.subtle.digest("SHA-256", t);
|
|
672
|
+
return _t(o).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
673
|
+
}
|
|
674
|
+
async function bt(e) {
|
|
675
|
+
const o = At(43), r = await Tt(o);
|
|
676
|
+
return {
|
|
677
|
+
code_verifier: o,
|
|
678
|
+
code_challenge: r
|
|
679
|
+
};
|
|
680
|
+
}
|
|
681
|
+
function Ie(e, t) {
|
|
636
682
|
window.dispatchEvent(new StorageEvent("storage", { key: e, newValue: t }));
|
|
637
683
|
}
|
|
638
|
-
const
|
|
684
|
+
const he = (e, t) => {
|
|
639
685
|
const o = JSON.stringify(
|
|
640
686
|
typeof t == "function" ? t() : t
|
|
641
687
|
);
|
|
642
|
-
window.localStorage.setItem(e, o),
|
|
643
|
-
},
|
|
644
|
-
window.localStorage.removeItem(e),
|
|
645
|
-
},
|
|
646
|
-
function
|
|
688
|
+
window.localStorage.setItem(e, o), Ie(e, o);
|
|
689
|
+
}, It = (e) => {
|
|
690
|
+
window.localStorage.removeItem(e), Ie(e, null);
|
|
691
|
+
}, pe = (e) => window.localStorage.getItem(e), vt = (e) => (window.addEventListener("storage", e), () => window.removeEventListener("storage", e));
|
|
692
|
+
function J({
|
|
647
693
|
key: e,
|
|
648
694
|
initialValue: t
|
|
649
695
|
}) {
|
|
650
|
-
const o = () =>
|
|
651
|
-
|
|
696
|
+
const o = () => pe(e), r = D.useSyncExternalStore(
|
|
697
|
+
vt,
|
|
652
698
|
o
|
|
653
|
-
), a =
|
|
699
|
+
), a = D.useCallback(
|
|
654
700
|
(i) => {
|
|
655
701
|
try {
|
|
656
702
|
const c = typeof i == "function" ? i(JSON.parse(r)) : i;
|
|
657
|
-
c == null ?
|
|
703
|
+
c == null ? It(e) : he(e, c);
|
|
658
704
|
} catch (c) {
|
|
659
705
|
console.warn(c);
|
|
660
706
|
}
|
|
661
707
|
},
|
|
662
708
|
[e, r]
|
|
663
|
-
), s =
|
|
709
|
+
), s = D.useCallback(() => {
|
|
664
710
|
a(t);
|
|
665
|
-
}, [t, a]), n =
|
|
711
|
+
}, [t, a]), n = D.useCallback(() => {
|
|
666
712
|
a(null);
|
|
667
713
|
}, [a]);
|
|
668
|
-
return
|
|
714
|
+
return D.useEffect(() => {
|
|
669
715
|
try {
|
|
670
|
-
|
|
716
|
+
pe(e) === null && typeof t < "u" && he(e, t);
|
|
671
717
|
} catch (i) {
|
|
672
718
|
console.warn(i);
|
|
673
719
|
}
|
|
674
720
|
}, [e, t]), [r ? JSON.parse(r) : null, a, s, n];
|
|
675
721
|
}
|
|
676
|
-
var
|
|
677
|
-
for (var
|
|
678
|
-
|
|
679
|
-
function
|
|
680
|
-
return (
|
|
722
|
+
var l = [];
|
|
723
|
+
for (var X = 0; X < 256; ++X)
|
|
724
|
+
l.push((X + 256).toString(16).slice(1));
|
|
725
|
+
function Rt(e, t = 0) {
|
|
726
|
+
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();
|
|
681
727
|
}
|
|
682
|
-
var
|
|
683
|
-
function
|
|
684
|
-
if (!
|
|
728
|
+
var W, kt = new Uint8Array(16);
|
|
729
|
+
function Ct() {
|
|
730
|
+
if (!W && (W = typeof crypto < "u" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto), !W))
|
|
685
731
|
throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
|
|
686
|
-
return
|
|
732
|
+
return W(kt);
|
|
687
733
|
}
|
|
688
|
-
var
|
|
689
|
-
const
|
|
690
|
-
randomUUID:
|
|
734
|
+
var Ot = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto);
|
|
735
|
+
const fe = {
|
|
736
|
+
randomUUID: Ot
|
|
691
737
|
};
|
|
692
|
-
function
|
|
693
|
-
if (
|
|
694
|
-
return
|
|
738
|
+
function Pt(e, t, o) {
|
|
739
|
+
if (fe.randomUUID && !t && !e)
|
|
740
|
+
return fe.randomUUID();
|
|
695
741
|
e = e || {};
|
|
696
|
-
var r = e.random || (e.rng ||
|
|
697
|
-
return r[6] = r[6] & 15 | 64, r[8] = r[8] & 63 | 128,
|
|
742
|
+
var r = e.random || (e.rng || Ct)();
|
|
743
|
+
return r[6] = r[6] & 15 | 64, r[8] = r[8] & 63 | 128, Rt(r);
|
|
698
744
|
}
|
|
699
|
-
const
|
|
745
|
+
const Q = "Oops! It looks like your session has expired. For your security, please log in again to continue.", Dt = "Your session has been successfully terminated.", ye = "Login failed. Please try again.", U = "Error getting access token, please re-authenticate.", Ut = "You forgot to wrap your component in <AuthProvider>.", me = {
|
|
700
746
|
dev: "https://auth.gizmette.local.com:3003",
|
|
701
747
|
prod: "https://mylogin.gizmette.com"
|
|
702
|
-
},
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
748
|
+
}, x = "@@auth@@", Nt = process.env.NODE_ENV === "production", Ht = !Nt, G = async ({
|
|
749
|
+
type: e,
|
|
750
|
+
clientId: t,
|
|
751
|
+
params: o = {}
|
|
752
|
+
}) => {
|
|
706
753
|
try {
|
|
707
|
-
const
|
|
708
|
-
|
|
754
|
+
const r = await fetch(
|
|
755
|
+
Ht ? `${me.dev}/${e}` : `${me.prod}/${e}`,
|
|
709
756
|
{
|
|
710
757
|
credentials: "include",
|
|
711
758
|
method: "POST",
|
|
712
759
|
headers: {
|
|
713
760
|
"Content-Type": "application/json",
|
|
714
|
-
[
|
|
761
|
+
[Je.CLIENT_ID]: `${t}`
|
|
715
762
|
},
|
|
716
|
-
body: JSON.stringify(
|
|
763
|
+
body: JSON.stringify(o)
|
|
717
764
|
}
|
|
718
765
|
);
|
|
719
|
-
if (
|
|
720
|
-
return { status:
|
|
721
|
-
const { data:
|
|
766
|
+
if (r.status !== 200)
|
|
767
|
+
return { status: r.status, data: [] };
|
|
768
|
+
const { data: a, errors: s } = await r.json();
|
|
722
769
|
return {
|
|
723
|
-
status:
|
|
724
|
-
data:
|
|
725
|
-
errors:
|
|
770
|
+
status: r.status,
|
|
771
|
+
data: a,
|
|
772
|
+
errors: s
|
|
726
773
|
};
|
|
727
|
-
} catch (
|
|
728
|
-
return console.error(
|
|
774
|
+
} catch (r) {
|
|
775
|
+
return console.error(r), { status: 500, data: [] };
|
|
729
776
|
}
|
|
730
|
-
},
|
|
777
|
+
}, Z = async ({
|
|
731
778
|
idToken: e,
|
|
732
779
|
accessToken: t,
|
|
733
|
-
|
|
780
|
+
refreshToken: o,
|
|
781
|
+
clientId: r
|
|
734
782
|
}) => {
|
|
735
783
|
try {
|
|
736
784
|
return {
|
|
737
|
-
status: (await
|
|
738
|
-
type:
|
|
785
|
+
status: (await G({
|
|
786
|
+
type: V.LOGOUT,
|
|
787
|
+
clientId: r,
|
|
739
788
|
params: {
|
|
740
789
|
idToken: e,
|
|
741
790
|
accessToken: t,
|
|
742
|
-
|
|
791
|
+
refreshToken: o
|
|
743
792
|
}
|
|
744
793
|
})).status === 200
|
|
745
794
|
};
|
|
@@ -748,29 +797,93 @@ const L = "Oops! It looks like your session has expired. For your security, plea
|
|
|
748
797
|
status: !1
|
|
749
798
|
};
|
|
750
799
|
}
|
|
751
|
-
},
|
|
800
|
+
}, we = async ({
|
|
752
801
|
username: e,
|
|
753
802
|
password: t,
|
|
754
803
|
clientId: o,
|
|
755
804
|
nonce: r,
|
|
756
|
-
|
|
805
|
+
type: a,
|
|
806
|
+
sessionExpiration: s,
|
|
807
|
+
code: n,
|
|
808
|
+
code_verifier: i
|
|
757
809
|
}) => {
|
|
758
810
|
try {
|
|
759
|
-
const
|
|
760
|
-
type:
|
|
811
|
+
const c = await G({
|
|
812
|
+
type: V.AUTHENTICATE,
|
|
813
|
+
clientId: o,
|
|
761
814
|
params: {
|
|
762
|
-
type:
|
|
815
|
+
type: a || M.ID_AND_ACCESS_TOKEN,
|
|
763
816
|
username: e,
|
|
764
817
|
password: t,
|
|
765
|
-
sessionExpiration:
|
|
766
|
-
|
|
767
|
-
|
|
818
|
+
sessionExpiration: s,
|
|
819
|
+
nonce: r,
|
|
820
|
+
code: n,
|
|
821
|
+
code_verifier: i
|
|
768
822
|
}
|
|
769
|
-
}),
|
|
770
|
-
return
|
|
771
|
-
idToken:
|
|
823
|
+
}), u = await N(c.data.idToken);
|
|
824
|
+
return u && u.payload[f.USER_ID_KEY] !== "" && u.payload[f.NONCE_KEY] === r ? {
|
|
825
|
+
idToken: c.data.idToken,
|
|
826
|
+
accessToken: c.data.accessToken,
|
|
827
|
+
refreshToken: c.data.refreshToken,
|
|
828
|
+
userId: u.payload[f.USER_ID_KEY],
|
|
829
|
+
status: !0
|
|
830
|
+
} : {
|
|
831
|
+
status: !1
|
|
832
|
+
};
|
|
833
|
+
} catch {
|
|
834
|
+
return {
|
|
835
|
+
status: !1
|
|
836
|
+
};
|
|
837
|
+
}
|
|
838
|
+
}, Lt = async ({
|
|
839
|
+
nonce: e,
|
|
840
|
+
clientId: t,
|
|
841
|
+
code_challenge: o
|
|
842
|
+
}) => {
|
|
843
|
+
try {
|
|
844
|
+
const r = await G({
|
|
845
|
+
type: V.CODE,
|
|
846
|
+
clientId: t,
|
|
847
|
+
params: {
|
|
848
|
+
type: M.CODE,
|
|
849
|
+
nonce: e,
|
|
850
|
+
code_challenge: o
|
|
851
|
+
}
|
|
852
|
+
});
|
|
853
|
+
return r.data.code ? {
|
|
854
|
+
status: !0,
|
|
855
|
+
code: r.data.code
|
|
856
|
+
} : {
|
|
857
|
+
status: !1
|
|
858
|
+
};
|
|
859
|
+
} catch {
|
|
860
|
+
return {
|
|
861
|
+
status: !1
|
|
862
|
+
};
|
|
863
|
+
}
|
|
864
|
+
}, $t = async ({
|
|
865
|
+
clientId: e,
|
|
866
|
+
userId: t,
|
|
867
|
+
nonce: o,
|
|
868
|
+
refreshToken: r,
|
|
869
|
+
accessToken: a
|
|
870
|
+
}) => {
|
|
871
|
+
try {
|
|
872
|
+
const s = await G({
|
|
873
|
+
type: V.AUTHENTICATE,
|
|
874
|
+
clientId: e,
|
|
875
|
+
params: {
|
|
876
|
+
type: M.REFRESH_TOKEN,
|
|
877
|
+
userId: t,
|
|
878
|
+
nonce: o,
|
|
879
|
+
refreshToken: r,
|
|
880
|
+
accessToken: a
|
|
881
|
+
}
|
|
882
|
+
}), n = await N(s.data.accessToken);
|
|
883
|
+
return n && n.payload[f.USER_ID_KEY] !== "" && n.payload[f.NONCE_KEY] === o ? {
|
|
772
884
|
accessToken: s.data.accessToken,
|
|
773
|
-
|
|
885
|
+
refreshToken: s.data.refreshToken,
|
|
886
|
+
userId: n.payload[f.USER_ID_KEY],
|
|
774
887
|
status: !0
|
|
775
888
|
} : {
|
|
776
889
|
status: !1
|
|
@@ -780,112 +893,166 @@ const L = "Oops! It looks like your session has expired. For your security, plea
|
|
|
780
893
|
status: !1
|
|
781
894
|
};
|
|
782
895
|
}
|
|
783
|
-
},
|
|
784
|
-
throw new Error(
|
|
785
|
-
},
|
|
896
|
+
}, j = () => {
|
|
897
|
+
throw new Error(Ut);
|
|
898
|
+
}, ve = Ne({
|
|
786
899
|
isAuthenticated: !1,
|
|
787
900
|
isLoading: !1,
|
|
788
|
-
login:
|
|
789
|
-
logout:
|
|
790
|
-
getAccessToken:
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
}),
|
|
901
|
+
login: j,
|
|
902
|
+
logout: j,
|
|
903
|
+
getAccessToken: j,
|
|
904
|
+
getIdToken: j,
|
|
905
|
+
logoutReason: ""
|
|
906
|
+
}), xt = ({
|
|
794
907
|
children: e,
|
|
795
908
|
sessionExpiration: t,
|
|
796
909
|
clientId: o
|
|
797
910
|
}) => {
|
|
798
|
-
const [r, a, , s] =
|
|
799
|
-
key: `${
|
|
800
|
-
}), [n, i, , c] =
|
|
801
|
-
key: `${
|
|
802
|
-
}), [,
|
|
803
|
-
|
|
804
|
-
|
|
911
|
+
const [r, a, , s] = J({
|
|
912
|
+
key: `${x}::${o}::@@user@@`
|
|
913
|
+
}), [n, i, , c] = J({
|
|
914
|
+
key: `${x}::${o}::@@access@@`
|
|
915
|
+
}), [u, y, , p] = J(
|
|
916
|
+
{
|
|
917
|
+
key: `${x}::${o}::@@refresh@@`
|
|
918
|
+
}
|
|
919
|
+
), [T, E, , m] = J({
|
|
920
|
+
key: `${x}::${o}::@@nonce@@`
|
|
921
|
+
}), [v, H] = He({
|
|
805
922
|
isLoading: !0,
|
|
806
923
|
isAuthenticated: !1,
|
|
807
|
-
logoutReason: "",
|
|
808
924
|
userId: "",
|
|
809
|
-
|
|
810
|
-
}),
|
|
811
|
-
(
|
|
812
|
-
|
|
925
|
+
logoutReason: ""
|
|
926
|
+
}), A = Le(
|
|
927
|
+
(w) => {
|
|
928
|
+
H({
|
|
813
929
|
isLoading: !1,
|
|
814
930
|
isAuthenticated: !1,
|
|
815
|
-
logoutReason: f || L,
|
|
816
931
|
userId: "",
|
|
817
|
-
|
|
818
|
-
}), s(), c(),
|
|
932
|
+
logoutReason: w || Q
|
|
933
|
+
}), s(), c(), p(), m();
|
|
819
934
|
},
|
|
820
|
-
[s, c,
|
|
935
|
+
[s, c, m, p]
|
|
821
936
|
);
|
|
822
|
-
|
|
823
|
-
|
|
937
|
+
$e(() => {
|
|
938
|
+
v.isLoading && r !== null && (async () => {
|
|
824
939
|
try {
|
|
825
|
-
const
|
|
826
|
-
|
|
940
|
+
const w = await N(r);
|
|
941
|
+
w && w.payload[f.USER_ID_KEY] !== "" ? H({
|
|
827
942
|
isLoading: !1,
|
|
828
943
|
isAuthenticated: !0,
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
...f == null ? void 0 : f.payload,
|
|
833
|
-
[_.TOKEN_ID_KEY]: r
|
|
834
|
-
}
|
|
835
|
-
}) : (h(L), await J({
|
|
944
|
+
userId: w.payload[f.USER_ID_KEY],
|
|
945
|
+
logoutReason: ""
|
|
946
|
+
}) : (A(Q), await Z({
|
|
836
947
|
idToken: r,
|
|
837
948
|
accessToken: n,
|
|
949
|
+
refreshToken: u,
|
|
838
950
|
clientId: o
|
|
839
951
|
}));
|
|
840
952
|
} catch {
|
|
841
|
-
|
|
953
|
+
A(Q), await Z({
|
|
842
954
|
idToken: r,
|
|
843
955
|
accessToken: n,
|
|
956
|
+
refreshToken: u,
|
|
844
957
|
clientId: o
|
|
845
958
|
});
|
|
846
959
|
}
|
|
847
960
|
})();
|
|
848
961
|
}, [
|
|
849
|
-
|
|
962
|
+
v.isLoading,
|
|
850
963
|
n,
|
|
851
964
|
r,
|
|
965
|
+
u,
|
|
852
966
|
o,
|
|
853
|
-
|
|
967
|
+
A
|
|
854
968
|
]);
|
|
855
|
-
const
|
|
856
|
-
const
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
969
|
+
const Re = async (w, O, R) => {
|
|
970
|
+
const k = Pt();
|
|
971
|
+
if (E(k), R === M.CODE) {
|
|
972
|
+
const { code_verifier: Pe, code_challenge: De } = await bt(), oe = await Lt({
|
|
973
|
+
nonce: k,
|
|
974
|
+
clientId: o,
|
|
975
|
+
code_challenge: De
|
|
976
|
+
});
|
|
977
|
+
if (oe.status) {
|
|
978
|
+
const P = await we({
|
|
979
|
+
username: w,
|
|
980
|
+
password: O,
|
|
981
|
+
clientId: o,
|
|
982
|
+
sessionExpiration: t,
|
|
983
|
+
nonce: k,
|
|
984
|
+
type: R,
|
|
985
|
+
code: oe.code,
|
|
986
|
+
code_verifier: Pe
|
|
987
|
+
});
|
|
988
|
+
return P.status ? (a(P.idToken), i(P.accessToken), y(P.refreshToken), H({
|
|
989
|
+
isLoading: !1,
|
|
990
|
+
isAuthenticated: !0,
|
|
991
|
+
userId: P.userId,
|
|
992
|
+
logoutReason: ""
|
|
993
|
+
}), !0) : (A(ye), !1);
|
|
994
|
+
}
|
|
995
|
+
return !1;
|
|
996
|
+
}
|
|
997
|
+
const S = await we({
|
|
998
|
+
username: w,
|
|
999
|
+
password: O,
|
|
861
1000
|
clientId: o,
|
|
862
1001
|
sessionExpiration: t,
|
|
863
|
-
nonce:
|
|
1002
|
+
nonce: k,
|
|
1003
|
+
type: R
|
|
864
1004
|
});
|
|
865
|
-
return
|
|
1005
|
+
return S.status ? (a(S.idToken), i(S.accessToken), y(S.refreshToken), H({
|
|
866
1006
|
isLoading: !1,
|
|
867
1007
|
isAuthenticated: !0,
|
|
868
|
-
userId:
|
|
869
|
-
}), !0) : (
|
|
870
|
-
},
|
|
871
|
-
|
|
1008
|
+
userId: S.userId
|
|
1009
|
+
}), !0) : (A(ye), !1);
|
|
1010
|
+
}, ke = async () => {
|
|
1011
|
+
A(Dt), await Z({
|
|
872
1012
|
idToken: r,
|
|
873
1013
|
accessToken: n,
|
|
1014
|
+
refreshToken: u,
|
|
874
1015
|
clientId: o
|
|
875
1016
|
});
|
|
876
|
-
},
|
|
877
|
-
|
|
878
|
-
|
|
1017
|
+
}, Ce = async () => {
|
|
1018
|
+
const { isAuthenticated: w, userId: O } = v;
|
|
1019
|
+
try {
|
|
1020
|
+
if (w && O && n) {
|
|
1021
|
+
const R = await N(n);
|
|
1022
|
+
if (R && R.payload[f.USER_ID_KEY] !== "")
|
|
1023
|
+
return n;
|
|
1024
|
+
const k = await N(u);
|
|
1025
|
+
if (k && k.payload[f.USER_ID_KEY] !== "") {
|
|
1026
|
+
const S = await $t({
|
|
1027
|
+
clientId: o,
|
|
1028
|
+
userId: O,
|
|
1029
|
+
nonce: T,
|
|
1030
|
+
refreshToken: u,
|
|
1031
|
+
accessToken: n
|
|
1032
|
+
});
|
|
1033
|
+
if (S.status)
|
|
1034
|
+
return i(S.accessToken), y(S.refreshToken), S.accessToken;
|
|
1035
|
+
A(U);
|
|
1036
|
+
}
|
|
1037
|
+
return A(U), console.error(U), "";
|
|
1038
|
+
}
|
|
1039
|
+
} catch {
|
|
1040
|
+
return A(U), console.error(U), "";
|
|
1041
|
+
}
|
|
1042
|
+
}, Oe = () => {
|
|
1043
|
+
if (v.isAuthenticated && r)
|
|
1044
|
+
return r;
|
|
879
1045
|
};
|
|
880
|
-
return /* @__PURE__ */
|
|
881
|
-
|
|
1046
|
+
return /* @__PURE__ */ Ue(
|
|
1047
|
+
ve.Provider,
|
|
882
1048
|
{
|
|
883
|
-
value: { ...
|
|
1049
|
+
value: { ...v, login: Re, logout: ke, getAccessToken: Ce, getIdToken: Oe },
|
|
884
1050
|
children: e
|
|
885
1051
|
}
|
|
886
1052
|
);
|
|
887
|
-
},
|
|
1053
|
+
}, jt = (e = ve) => Ke(e);
|
|
888
1054
|
export {
|
|
889
|
-
|
|
890
|
-
|
|
1055
|
+
M as AUTH_TYPES,
|
|
1056
|
+
xt as AuthProvider,
|
|
1057
|
+
jt as useAuth
|
|
891
1058
|
};
|