@versini/auth-provider 7.3.1 → 7.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +574 -512
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -1,46 +1,46 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
import { jsx as
|
|
5
|
-
import
|
|
1
|
+
var At = Object.defineProperty;
|
|
2
|
+
var Tt = (e, t, r) => t in e ? At(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
|
|
3
|
+
var X = (e, t, r) => Tt(e, typeof t != "symbol" ? t + "" : t, r);
|
|
4
|
+
import { jsx as Oe } from "react/jsx-runtime";
|
|
5
|
+
import Rt, { useSyncExternalStore as bt, useCallback as D, useEffect as xe, createContext as _t, useReducer as It, useRef as kt, useContext as vt } from "react";
|
|
6
6
|
/*!
|
|
7
|
-
@versini/auth-provider v7.3.
|
|
7
|
+
@versini/auth-provider v7.3.2
|
|
8
8
|
© 2024 gizmette.com
|
|
9
9
|
*/
|
|
10
10
|
try {
|
|
11
11
|
window.__VERSINI_AUTH_CLIENT__ || (window.__VERSINI_AUTH_CLIENT__ = {
|
|
12
|
-
version: "7.3.
|
|
13
|
-
buildTime: "09/
|
|
12
|
+
version: "7.3.2",
|
|
13
|
+
buildTime: "09/19/2024 02:34 PM EDT",
|
|
14
14
|
homepage: "https://github.com/aversini/auth-client",
|
|
15
15
|
license: "MIT"
|
|
16
16
|
});
|
|
17
17
|
} catch {
|
|
18
18
|
}
|
|
19
|
-
function
|
|
19
|
+
function b(e) {
|
|
20
20
|
const t = new Uint8Array(e);
|
|
21
21
|
let r = "";
|
|
22
22
|
for (const a of t)
|
|
23
23
|
r += String.fromCharCode(a);
|
|
24
24
|
return btoa(r).replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
|
|
25
25
|
}
|
|
26
|
-
function
|
|
27
|
-
const t = e.replace(/-/g, "+").replace(/_/g, "/"), r = (4 - t.length % 4) % 4, n = t.padEnd(t.length + r, "="), a = atob(n),
|
|
26
|
+
function ie(e) {
|
|
27
|
+
const t = e.replace(/-/g, "+").replace(/_/g, "/"), r = (4 - t.length % 4) % 4, n = t.padEnd(t.length + r, "="), a = atob(n), s = new ArrayBuffer(a.length), o = new Uint8Array(s);
|
|
28
28
|
for (let i = 0; i < a.length; i++)
|
|
29
|
-
|
|
30
|
-
return
|
|
29
|
+
o[i] = a.charCodeAt(i);
|
|
30
|
+
return s;
|
|
31
31
|
}
|
|
32
|
-
function
|
|
32
|
+
function Re() {
|
|
33
33
|
return window?.PublicKeyCredential !== void 0 && typeof window.PublicKeyCredential == "function";
|
|
34
34
|
}
|
|
35
|
-
function
|
|
35
|
+
function Ge(e) {
|
|
36
36
|
const { id: t } = e;
|
|
37
37
|
return {
|
|
38
38
|
...e,
|
|
39
|
-
id:
|
|
39
|
+
id: ie(t),
|
|
40
40
|
transports: e.transports
|
|
41
41
|
};
|
|
42
42
|
}
|
|
43
|
-
function
|
|
43
|
+
function Me(e) {
|
|
44
44
|
return e === "localhost" || /^([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,}$/i.test(e);
|
|
45
45
|
}
|
|
46
46
|
class S extends Error {
|
|
@@ -48,7 +48,7 @@ class S extends Error {
|
|
|
48
48
|
super(t, { cause: n }), this.name = a ?? n.name, this.code = r;
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
|
-
function
|
|
51
|
+
function Ot({ error: e, options: t }) {
|
|
52
52
|
const { publicKey: r } = t;
|
|
53
53
|
if (!r)
|
|
54
54
|
throw Error("options was missing required publicKey property");
|
|
@@ -97,7 +97,7 @@ function _t({ error: e, options: t }) {
|
|
|
97
97
|
});
|
|
98
98
|
if (e.name === "SecurityError") {
|
|
99
99
|
const n = window.location.hostname;
|
|
100
|
-
if (
|
|
100
|
+
if (Me(n)) {
|
|
101
101
|
if (r.rp.id !== n)
|
|
102
102
|
return new S({
|
|
103
103
|
message: `The RP ID "${r.rp.id}" is invalid for this domain`,
|
|
@@ -125,7 +125,7 @@ function _t({ error: e, options: t }) {
|
|
|
125
125
|
}
|
|
126
126
|
return e;
|
|
127
127
|
}
|
|
128
|
-
class
|
|
128
|
+
class Pt {
|
|
129
129
|
createNewAbortSignal() {
|
|
130
130
|
if (this.controller) {
|
|
131
131
|
const r = new Error("Cancelling existing WebAuthn API call for new one");
|
|
@@ -141,63 +141,63 @@ class It {
|
|
|
141
141
|
}
|
|
142
142
|
}
|
|
143
143
|
}
|
|
144
|
-
const
|
|
145
|
-
function
|
|
146
|
-
if (e && !(
|
|
144
|
+
const Ve = new Pt(), Ct = ["cross-platform", "platform"];
|
|
145
|
+
function je(e) {
|
|
146
|
+
if (e && !(Ct.indexOf(e) < 0))
|
|
147
147
|
return e;
|
|
148
148
|
}
|
|
149
|
-
async function
|
|
150
|
-
if (!
|
|
149
|
+
async function Nt(e) {
|
|
150
|
+
if (!Re())
|
|
151
151
|
throw new Error("WebAuthn is not supported in this browser");
|
|
152
152
|
const r = { publicKey: {
|
|
153
153
|
...e,
|
|
154
|
-
challenge:
|
|
154
|
+
challenge: ie(e.challenge),
|
|
155
155
|
user: {
|
|
156
156
|
...e.user,
|
|
157
|
-
id:
|
|
157
|
+
id: ie(e.user.id)
|
|
158
158
|
},
|
|
159
|
-
excludeCredentials: e.excludeCredentials?.map(
|
|
159
|
+
excludeCredentials: e.excludeCredentials?.map(Ge)
|
|
160
160
|
} };
|
|
161
|
-
r.signal =
|
|
161
|
+
r.signal = Ve.createNewAbortSignal();
|
|
162
162
|
let n;
|
|
163
163
|
try {
|
|
164
164
|
n = await navigator.credentials.create(r);
|
|
165
165
|
} catch (l) {
|
|
166
|
-
throw
|
|
166
|
+
throw Ot({ error: l, options: r });
|
|
167
167
|
}
|
|
168
168
|
if (!n)
|
|
169
169
|
throw new Error("Registration was not completed");
|
|
170
|
-
const { id: a, rawId:
|
|
170
|
+
const { id: a, rawId: s, response: o, type: i } = n;
|
|
171
171
|
let c;
|
|
172
|
-
typeof
|
|
172
|
+
typeof o.getTransports == "function" && (c = o.getTransports());
|
|
173
173
|
let h;
|
|
174
|
-
if (typeof
|
|
174
|
+
if (typeof o.getPublicKeyAlgorithm == "function")
|
|
175
175
|
try {
|
|
176
|
-
h =
|
|
176
|
+
h = o.getPublicKeyAlgorithm();
|
|
177
177
|
} catch (l) {
|
|
178
|
-
|
|
178
|
+
ge("getPublicKeyAlgorithm()", l);
|
|
179
179
|
}
|
|
180
180
|
let y;
|
|
181
|
-
if (typeof
|
|
181
|
+
if (typeof o.getPublicKey == "function")
|
|
182
182
|
try {
|
|
183
|
-
const l =
|
|
184
|
-
l !== null && (y =
|
|
183
|
+
const l = o.getPublicKey();
|
|
184
|
+
l !== null && (y = b(l));
|
|
185
185
|
} catch (l) {
|
|
186
|
-
|
|
186
|
+
ge("getPublicKey()", l);
|
|
187
187
|
}
|
|
188
188
|
let p;
|
|
189
|
-
if (typeof
|
|
189
|
+
if (typeof o.getAuthenticatorData == "function")
|
|
190
190
|
try {
|
|
191
|
-
p =
|
|
191
|
+
p = b(o.getAuthenticatorData());
|
|
192
192
|
} catch (l) {
|
|
193
|
-
|
|
193
|
+
ge("getAuthenticatorData()", l);
|
|
194
194
|
}
|
|
195
195
|
return {
|
|
196
196
|
id: a,
|
|
197
|
-
rawId:
|
|
197
|
+
rawId: b(s),
|
|
198
198
|
response: {
|
|
199
|
-
attestationObject:
|
|
200
|
-
clientDataJSON:
|
|
199
|
+
attestationObject: b(o.attestationObject),
|
|
200
|
+
clientDataJSON: b(o.clientDataJSON),
|
|
201
201
|
transports: c,
|
|
202
202
|
publicKeyAlgorithm: h,
|
|
203
203
|
publicKey: y,
|
|
@@ -205,20 +205,20 @@ async function vt(e) {
|
|
|
205
205
|
},
|
|
206
206
|
type: i,
|
|
207
207
|
clientExtensionResults: n.getClientExtensionResults(),
|
|
208
|
-
authenticatorAttachment:
|
|
208
|
+
authenticatorAttachment: je(n.authenticatorAttachment)
|
|
209
209
|
};
|
|
210
210
|
}
|
|
211
|
-
function
|
|
211
|
+
function ge(e, t) {
|
|
212
212
|
console.warn(`The browser extension that intercepted this WebAuthn API call incorrectly implemented ${e}. You should report this error to them.
|
|
213
213
|
`, t);
|
|
214
214
|
}
|
|
215
|
-
function
|
|
216
|
-
if (!
|
|
215
|
+
function Dt() {
|
|
216
|
+
if (!Re())
|
|
217
217
|
return new Promise((t) => t(!1));
|
|
218
218
|
const e = window.PublicKeyCredential;
|
|
219
219
|
return e.isConditionalMediationAvailable === void 0 ? new Promise((t) => t(!1)) : e.isConditionalMediationAvailable();
|
|
220
220
|
}
|
|
221
|
-
function
|
|
221
|
+
function Kt({ error: e, options: t }) {
|
|
222
222
|
const { publicKey: r } = t;
|
|
223
223
|
if (!r)
|
|
224
224
|
throw Error("options was missing required publicKey property");
|
|
@@ -238,7 +238,7 @@ function kt({ error: e, options: t }) {
|
|
|
238
238
|
});
|
|
239
239
|
if (e.name === "SecurityError") {
|
|
240
240
|
const n = window.location.hostname;
|
|
241
|
-
if (
|
|
241
|
+
if (Me(n)) {
|
|
242
242
|
if (r.rpId !== n)
|
|
243
243
|
return new S({
|
|
244
244
|
message: `The RP ID "${r.rpId}" is invalid for this domain`,
|
|
@@ -259,69 +259,69 @@ function kt({ error: e, options: t }) {
|
|
|
259
259
|
}
|
|
260
260
|
return e;
|
|
261
261
|
}
|
|
262
|
-
async function
|
|
263
|
-
if (!
|
|
262
|
+
async function Ut(e, t = !1) {
|
|
263
|
+
if (!Re())
|
|
264
264
|
throw new Error("WebAuthn is not supported in this browser");
|
|
265
265
|
let r;
|
|
266
|
-
e.allowCredentials?.length !== 0 && (r = e.allowCredentials?.map(
|
|
266
|
+
e.allowCredentials?.length !== 0 && (r = e.allowCredentials?.map(Ge));
|
|
267
267
|
const n = {
|
|
268
268
|
...e,
|
|
269
|
-
challenge:
|
|
269
|
+
challenge: ie(e.challenge),
|
|
270
270
|
allowCredentials: r
|
|
271
271
|
}, a = {};
|
|
272
272
|
if (t) {
|
|
273
|
-
if (!await
|
|
273
|
+
if (!await Dt())
|
|
274
274
|
throw Error("Browser does not support WebAuthn autofill");
|
|
275
275
|
if (document.querySelectorAll("input[autocomplete$='webauthn']").length < 1)
|
|
276
276
|
throw Error('No <input> with "webauthn" as the only or last value in its `autocomplete` attribute was detected');
|
|
277
277
|
a.mediation = "conditional", n.allowCredentials = [];
|
|
278
278
|
}
|
|
279
|
-
a.publicKey = n, a.signal =
|
|
280
|
-
let
|
|
279
|
+
a.publicKey = n, a.signal = Ve.createNewAbortSignal();
|
|
280
|
+
let s;
|
|
281
281
|
try {
|
|
282
|
-
|
|
282
|
+
s = await navigator.credentials.get(a);
|
|
283
283
|
} catch (p) {
|
|
284
|
-
throw
|
|
284
|
+
throw Kt({ error: p, options: a });
|
|
285
285
|
}
|
|
286
|
-
if (!
|
|
286
|
+
if (!s)
|
|
287
287
|
throw new Error("Authentication was not completed");
|
|
288
|
-
const { id:
|
|
288
|
+
const { id: o, rawId: i, response: c, type: h } = s;
|
|
289
289
|
let y;
|
|
290
|
-
return c.userHandle && (y =
|
|
291
|
-
id:
|
|
292
|
-
rawId:
|
|
290
|
+
return c.userHandle && (y = b(c.userHandle)), {
|
|
291
|
+
id: o,
|
|
292
|
+
rawId: b(i),
|
|
293
293
|
response: {
|
|
294
|
-
authenticatorData:
|
|
295
|
-
clientDataJSON:
|
|
296
|
-
signature:
|
|
294
|
+
authenticatorData: b(c.authenticatorData),
|
|
295
|
+
clientDataJSON: b(c.clientDataJSON),
|
|
296
|
+
signature: b(c.signature),
|
|
297
297
|
userHandle: y
|
|
298
298
|
},
|
|
299
299
|
type: h,
|
|
300
|
-
clientExtensionResults:
|
|
301
|
-
authenticatorAttachment:
|
|
300
|
+
clientExtensionResults: s.getClientExtensionResults(),
|
|
301
|
+
authenticatorAttachment: je(s.authenticatorAttachment)
|
|
302
302
|
};
|
|
303
303
|
}
|
|
304
304
|
/*!
|
|
305
|
-
@versini/auth-common v4.1.
|
|
305
|
+
@versini/auth-common v4.1.2
|
|
306
306
|
© 2024 gizmette.com
|
|
307
307
|
*/
|
|
308
308
|
try {
|
|
309
309
|
window.__VERSINI_AUTH_COMMON__ || (window.__VERSINI_AUTH_COMMON__ = {
|
|
310
|
-
version: "4.1.
|
|
311
|
-
buildTime: "09/
|
|
310
|
+
version: "4.1.2",
|
|
311
|
+
buildTime: "09/19/2024 02:34 PM EDT",
|
|
312
312
|
homepage: "https://github.com/aversini/auth-client",
|
|
313
313
|
license: "MIT"
|
|
314
314
|
});
|
|
315
315
|
} catch {
|
|
316
316
|
}
|
|
317
|
-
const
|
|
317
|
+
const G = {
|
|
318
318
|
ID_TOKEN: "id_token",
|
|
319
319
|
ACCESS_TOKEN: "token",
|
|
320
320
|
ID_AND_ACCESS_TOKEN: "id_token token",
|
|
321
321
|
CODE: "code",
|
|
322
322
|
REFRESH_TOKEN: "refresh_token",
|
|
323
323
|
PASSKEY: "passkey"
|
|
324
|
-
},
|
|
324
|
+
}, Fe = {
|
|
325
325
|
CLIENT_ID: "X-Auth-ClientId"
|
|
326
326
|
}, f = {
|
|
327
327
|
ALG: "RS256",
|
|
@@ -336,7 +336,7 @@ const W = {
|
|
|
336
336
|
SCOPES_KEY: "scopes",
|
|
337
337
|
CLIENT_ID_KEY: "aud",
|
|
338
338
|
ISSUER: "gizmette.com"
|
|
339
|
-
},
|
|
339
|
+
}, $t = `-----BEGIN PUBLIC KEY-----
|
|
340
340
|
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAsF6i3Jd9fY/3COqCw/m7
|
|
341
341
|
w5PKyTYLGAI2I6SIIdpe6i6DOCbEkmDz7LdVsBqwNtVi8gvWYIj+8ol6rU3qu1v5
|
|
342
342
|
i1Jd45GSK4kzkVdgCmQZbM5ak0KI99q5wsrAIzUd+LRJ2HRvWtr5IYdsIiXaQjle
|
|
@@ -344,34 +344,34 @@ aMwPFOIcJH+rKfFgNcHLcaS5syp7zU1ANwZ+trgR+DifBr8TLVkBynmNeTyhDm2+
|
|
|
344
344
|
l0haqjMk0UoNPPE8iYBWUHQJJE1Dqstj65d6Eh5g64Pao25y4cmYJbKjiblIGEkE
|
|
345
345
|
sjqybA9mARAqh9k/eiIopecWSiffNQTwVQVd2I9ZH3BalhEXHlqFgrjz51kFqg81
|
|
346
346
|
awIDAQAB
|
|
347
|
-
-----END PUBLIC KEY-----`,
|
|
347
|
+
-----END PUBLIC KEY-----`, de = {
|
|
348
348
|
CODE: "code",
|
|
349
349
|
LOGOUT: "logout",
|
|
350
350
|
LOGIN: "login",
|
|
351
351
|
REFRESH: "refresh"
|
|
352
|
-
},
|
|
353
|
-
function
|
|
354
|
-
const t = e.reduce((a, { length:
|
|
352
|
+
}, he = crypto, Be = (e) => e instanceof CryptoKey, Z = new TextEncoder(), q = new TextDecoder();
|
|
353
|
+
function Ht(...e) {
|
|
354
|
+
const t = e.reduce((a, { length: s }) => a + s, 0), r = new Uint8Array(t);
|
|
355
355
|
let n = 0;
|
|
356
356
|
for (const a of e)
|
|
357
357
|
r.set(a, n), n += a.length;
|
|
358
358
|
return r;
|
|
359
359
|
}
|
|
360
|
-
const
|
|
360
|
+
const Lt = (e) => {
|
|
361
361
|
const t = atob(e), r = new Uint8Array(t.length);
|
|
362
362
|
for (let n = 0; n < t.length; n++)
|
|
363
363
|
r[n] = t.charCodeAt(n);
|
|
364
364
|
return r;
|
|
365
|
-
},
|
|
365
|
+
}, P = (e) => {
|
|
366
366
|
let t = e;
|
|
367
|
-
t instanceof Uint8Array && (t =
|
|
367
|
+
t instanceof Uint8Array && (t = q.decode(t)), t = t.replace(/-/g, "+").replace(/_/g, "/").replace(/\s/g, "");
|
|
368
368
|
try {
|
|
369
|
-
return
|
|
369
|
+
return Lt(t);
|
|
370
370
|
} catch {
|
|
371
371
|
throw new TypeError("The input to be decoded is not correctly encoded.");
|
|
372
372
|
}
|
|
373
373
|
};
|
|
374
|
-
class
|
|
374
|
+
class K extends Error {
|
|
375
375
|
static get code() {
|
|
376
376
|
return "ERR_JOSE_GENERIC";
|
|
377
377
|
}
|
|
@@ -380,7 +380,7 @@ class D extends Error {
|
|
|
380
380
|
super(t), this.code = "ERR_JOSE_GENERIC", this.name = this.constructor.name, (r = Error.captureStackTrace) == null || r.call(Error, this, this.constructor);
|
|
381
381
|
}
|
|
382
382
|
}
|
|
383
|
-
class R extends
|
|
383
|
+
class R extends K {
|
|
384
384
|
static get code() {
|
|
385
385
|
return "ERR_JWT_CLAIM_VALIDATION_FAILED";
|
|
386
386
|
}
|
|
@@ -388,7 +388,7 @@ class R extends D {
|
|
|
388
388
|
super(t), this.code = "ERR_JWT_CLAIM_VALIDATION_FAILED", this.claim = n, this.reason = a, this.payload = r;
|
|
389
389
|
}
|
|
390
390
|
}
|
|
391
|
-
class
|
|
391
|
+
class Pe extends K {
|
|
392
392
|
static get code() {
|
|
393
393
|
return "ERR_JWT_EXPIRED";
|
|
394
394
|
}
|
|
@@ -396,7 +396,7 @@ class ve extends D {
|
|
|
396
396
|
super(t), this.code = "ERR_JWT_EXPIRED", this.claim = n, this.reason = a, this.payload = r;
|
|
397
397
|
}
|
|
398
398
|
}
|
|
399
|
-
class
|
|
399
|
+
class Wt extends K {
|
|
400
400
|
constructor() {
|
|
401
401
|
super(...arguments), this.code = "ERR_JOSE_ALG_NOT_ALLOWED";
|
|
402
402
|
}
|
|
@@ -404,7 +404,7 @@ class Ut extends D {
|
|
|
404
404
|
return "ERR_JOSE_ALG_NOT_ALLOWED";
|
|
405
405
|
}
|
|
406
406
|
}
|
|
407
|
-
class
|
|
407
|
+
class _ extends K {
|
|
408
408
|
constructor() {
|
|
409
409
|
super(...arguments), this.code = "ERR_JOSE_NOT_SUPPORTED";
|
|
410
410
|
}
|
|
@@ -412,7 +412,7 @@ class k extends D {
|
|
|
412
412
|
return "ERR_JOSE_NOT_SUPPORTED";
|
|
413
413
|
}
|
|
414
414
|
}
|
|
415
|
-
class w extends
|
|
415
|
+
class w extends K {
|
|
416
416
|
constructor() {
|
|
417
417
|
super(...arguments), this.code = "ERR_JWS_INVALID";
|
|
418
418
|
}
|
|
@@ -420,7 +420,7 @@ class w extends D {
|
|
|
420
420
|
return "ERR_JWS_INVALID";
|
|
421
421
|
}
|
|
422
422
|
}
|
|
423
|
-
let v = class extends
|
|
423
|
+
let v = class extends K {
|
|
424
424
|
constructor() {
|
|
425
425
|
super(...arguments), this.code = "ERR_JWT_INVALID";
|
|
426
426
|
}
|
|
@@ -428,7 +428,7 @@ let v = class extends D {
|
|
|
428
428
|
return "ERR_JWT_INVALID";
|
|
429
429
|
}
|
|
430
430
|
};
|
|
431
|
-
class
|
|
431
|
+
class Jt extends K {
|
|
432
432
|
constructor() {
|
|
433
433
|
super(...arguments), this.code = "ERR_JWS_SIGNATURE_VERIFICATION_FAILED", this.message = "signature verification failed";
|
|
434
434
|
}
|
|
@@ -436,16 +436,16 @@ class Kt extends D {
|
|
|
436
436
|
return "ERR_JWS_SIGNATURE_VERIFICATION_FAILED";
|
|
437
437
|
}
|
|
438
438
|
}
|
|
439
|
-
function
|
|
439
|
+
function k(e, t = "algorithm.name") {
|
|
440
440
|
return new TypeError(`CryptoKey does not support this operation, its ${t} must be ${e}`);
|
|
441
441
|
}
|
|
442
|
-
function
|
|
442
|
+
function ee(e, t) {
|
|
443
443
|
return e.name === t;
|
|
444
444
|
}
|
|
445
|
-
function
|
|
445
|
+
function Ee(e) {
|
|
446
446
|
return parseInt(e.name.slice(4), 10);
|
|
447
447
|
}
|
|
448
|
-
function
|
|
448
|
+
function Yt(e) {
|
|
449
449
|
switch (e) {
|
|
450
450
|
case "ES256":
|
|
451
451
|
return "P-256";
|
|
@@ -457,7 +457,7 @@ function Lt(e) {
|
|
|
457
457
|
throw new Error("unreachable");
|
|
458
458
|
}
|
|
459
459
|
}
|
|
460
|
-
function
|
|
460
|
+
function xt(e, t) {
|
|
461
461
|
if (t.length && !t.some((r) => e.usages.includes(r))) {
|
|
462
462
|
let r = "CryptoKey does not support this operation, its usages must include ";
|
|
463
463
|
if (t.length > 2) {
|
|
@@ -467,71 +467,71 @@ function $t(e, t) {
|
|
|
467
467
|
throw new TypeError(r);
|
|
468
468
|
}
|
|
469
469
|
}
|
|
470
|
-
function
|
|
470
|
+
function Gt(e, t, ...r) {
|
|
471
471
|
switch (t) {
|
|
472
472
|
case "HS256":
|
|
473
473
|
case "HS384":
|
|
474
474
|
case "HS512": {
|
|
475
|
-
if (!
|
|
476
|
-
throw
|
|
475
|
+
if (!ee(e.algorithm, "HMAC"))
|
|
476
|
+
throw k("HMAC");
|
|
477
477
|
const n = parseInt(t.slice(2), 10);
|
|
478
|
-
if (
|
|
479
|
-
throw
|
|
478
|
+
if (Ee(e.algorithm.hash) !== n)
|
|
479
|
+
throw k(`SHA-${n}`, "algorithm.hash");
|
|
480
480
|
break;
|
|
481
481
|
}
|
|
482
482
|
case "RS256":
|
|
483
483
|
case "RS384":
|
|
484
484
|
case "RS512": {
|
|
485
|
-
if (!
|
|
486
|
-
throw
|
|
485
|
+
if (!ee(e.algorithm, "RSASSA-PKCS1-v1_5"))
|
|
486
|
+
throw k("RSASSA-PKCS1-v1_5");
|
|
487
487
|
const n = parseInt(t.slice(2), 10);
|
|
488
|
-
if (
|
|
489
|
-
throw
|
|
488
|
+
if (Ee(e.algorithm.hash) !== n)
|
|
489
|
+
throw k(`SHA-${n}`, "algorithm.hash");
|
|
490
490
|
break;
|
|
491
491
|
}
|
|
492
492
|
case "PS256":
|
|
493
493
|
case "PS384":
|
|
494
494
|
case "PS512": {
|
|
495
|
-
if (!
|
|
496
|
-
throw
|
|
495
|
+
if (!ee(e.algorithm, "RSA-PSS"))
|
|
496
|
+
throw k("RSA-PSS");
|
|
497
497
|
const n = parseInt(t.slice(2), 10);
|
|
498
|
-
if (
|
|
499
|
-
throw
|
|
498
|
+
if (Ee(e.algorithm.hash) !== n)
|
|
499
|
+
throw k(`SHA-${n}`, "algorithm.hash");
|
|
500
500
|
break;
|
|
501
501
|
}
|
|
502
502
|
case "EdDSA": {
|
|
503
503
|
if (e.algorithm.name !== "Ed25519" && e.algorithm.name !== "Ed448")
|
|
504
|
-
throw
|
|
504
|
+
throw k("Ed25519 or Ed448");
|
|
505
505
|
break;
|
|
506
506
|
}
|
|
507
507
|
case "ES256":
|
|
508
508
|
case "ES384":
|
|
509
509
|
case "ES512": {
|
|
510
|
-
if (!
|
|
511
|
-
throw
|
|
512
|
-
const n =
|
|
510
|
+
if (!ee(e.algorithm, "ECDSA"))
|
|
511
|
+
throw k("ECDSA");
|
|
512
|
+
const n = Yt(t);
|
|
513
513
|
if (e.algorithm.namedCurve !== n)
|
|
514
|
-
throw
|
|
514
|
+
throw k(n, "algorithm.namedCurve");
|
|
515
515
|
break;
|
|
516
516
|
}
|
|
517
517
|
default:
|
|
518
518
|
throw new TypeError("CryptoKey does not support this operation");
|
|
519
519
|
}
|
|
520
|
-
|
|
520
|
+
xt(e, r);
|
|
521
521
|
}
|
|
522
|
-
function
|
|
522
|
+
function qe(e, t, ...r) {
|
|
523
523
|
var n;
|
|
524
|
-
if (r.length > 2) {
|
|
524
|
+
if (r = r.filter(Boolean), r.length > 2) {
|
|
525
525
|
const a = r.pop();
|
|
526
526
|
e += `one of type ${r.join(", ")}, or ${a}.`;
|
|
527
527
|
} else r.length === 2 ? e += `one of type ${r[0]} or ${r[1]}.` : e += `of type ${r[0]}.`;
|
|
528
528
|
return t == null ? e += ` Received ${t}` : typeof t == "function" && t.name ? e += ` Received function ${t.name}` : typeof t == "object" && t != null && (n = t.constructor) != null && n.name && (e += ` Received an instance of ${t.constructor.name}`), e;
|
|
529
529
|
}
|
|
530
|
-
const
|
|
531
|
-
function
|
|
532
|
-
return
|
|
530
|
+
const Ce = (e, ...t) => qe("Key must be ", e, ...t);
|
|
531
|
+
function ze(e, t, ...r) {
|
|
532
|
+
return qe(`Key for the ${e} algorithm must be `, t, ...r);
|
|
533
533
|
}
|
|
534
|
-
const
|
|
534
|
+
const Qe = (e) => Be(e) ? !0 : e?.[Symbol.toStringTag] === "KeyObject", ce = ["CryptoKey"], Mt = (...e) => {
|
|
535
535
|
const t = e.filter(Boolean);
|
|
536
536
|
if (t.length === 0 || t.length === 1)
|
|
537
537
|
return !0;
|
|
@@ -542,19 +542,19 @@ const Fe = (e) => Me(e) ? !0 : e?.[Symbol.toStringTag] === "KeyObject", ae = ["C
|
|
|
542
542
|
r = new Set(a);
|
|
543
543
|
continue;
|
|
544
544
|
}
|
|
545
|
-
for (const
|
|
546
|
-
if (r.has(
|
|
545
|
+
for (const s of a) {
|
|
546
|
+
if (r.has(s))
|
|
547
547
|
return !1;
|
|
548
|
-
r.add(
|
|
548
|
+
r.add(s);
|
|
549
549
|
}
|
|
550
550
|
}
|
|
551
551
|
return !0;
|
|
552
552
|
};
|
|
553
|
-
function
|
|
553
|
+
function Vt(e) {
|
|
554
554
|
return typeof e == "object" && e !== null;
|
|
555
555
|
}
|
|
556
|
-
function
|
|
557
|
-
if (!
|
|
556
|
+
function M(e) {
|
|
557
|
+
if (!Vt(e) || Object.prototype.toString.call(e) !== "[object Object]")
|
|
558
558
|
return !1;
|
|
559
559
|
if (Object.getPrototypeOf(e) === null)
|
|
560
560
|
return !0;
|
|
@@ -563,14 +563,26 @@ function se(e) {
|
|
|
563
563
|
t = Object.getPrototypeOf(t);
|
|
564
564
|
return Object.getPrototypeOf(e) === t;
|
|
565
565
|
}
|
|
566
|
-
const
|
|
566
|
+
const jt = (e, t) => {
|
|
567
567
|
if (e.startsWith("RS") || e.startsWith("PS")) {
|
|
568
568
|
const { modulusLength: r } = t.algorithm;
|
|
569
569
|
if (typeof r != "number" || r < 2048)
|
|
570
570
|
throw new TypeError(`${e} requires key modulusLength to be 2048 bits or larger`);
|
|
571
571
|
}
|
|
572
572
|
};
|
|
573
|
-
function
|
|
573
|
+
function j(e) {
|
|
574
|
+
return M(e) && typeof e.kty == "string";
|
|
575
|
+
}
|
|
576
|
+
function Ft(e) {
|
|
577
|
+
return e.kty !== "oct" && typeof e.d == "string";
|
|
578
|
+
}
|
|
579
|
+
function Bt(e) {
|
|
580
|
+
return e.kty !== "oct" && typeof e.d > "u";
|
|
581
|
+
}
|
|
582
|
+
function qt(e) {
|
|
583
|
+
return j(e) && e.kty === "oct" && typeof e.k == "string";
|
|
584
|
+
}
|
|
585
|
+
function zt(e) {
|
|
574
586
|
let t, r;
|
|
575
587
|
switch (e.kty) {
|
|
576
588
|
case "RSA": {
|
|
@@ -595,7 +607,7 @@ function Jt(e) {
|
|
|
595
607
|
}, r = e.d ? ["decrypt", "unwrapKey"] : ["encrypt", "wrapKey"];
|
|
596
608
|
break;
|
|
597
609
|
default:
|
|
598
|
-
throw new
|
|
610
|
+
throw new _('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
|
|
599
611
|
}
|
|
600
612
|
break;
|
|
601
613
|
}
|
|
@@ -617,7 +629,7 @@ function Jt(e) {
|
|
|
617
629
|
t = { name: "ECDH", namedCurve: e.crv }, r = e.d ? ["deriveBits"] : [];
|
|
618
630
|
break;
|
|
619
631
|
default:
|
|
620
|
-
throw new
|
|
632
|
+
throw new _('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
|
|
621
633
|
}
|
|
622
634
|
break;
|
|
623
635
|
}
|
|
@@ -633,52 +645,52 @@ function Jt(e) {
|
|
|
633
645
|
t = { name: e.crv }, r = e.d ? ["deriveBits"] : [];
|
|
634
646
|
break;
|
|
635
647
|
default:
|
|
636
|
-
throw new
|
|
648
|
+
throw new _('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
|
|
637
649
|
}
|
|
638
650
|
break;
|
|
639
651
|
}
|
|
640
652
|
default:
|
|
641
|
-
throw new
|
|
653
|
+
throw new _('Invalid or unsupported JWK "kty" (Key Type) Parameter value');
|
|
642
654
|
}
|
|
643
655
|
return { algorithm: t, keyUsages: r };
|
|
644
656
|
}
|
|
645
|
-
const
|
|
657
|
+
const Xe = async (e) => {
|
|
646
658
|
if (!e.alg)
|
|
647
659
|
throw new TypeError('"alg" argument is required when "jwk.alg" is not present');
|
|
648
|
-
const { algorithm: t, keyUsages: r } =
|
|
660
|
+
const { algorithm: t, keyUsages: r } = zt(e), n = [
|
|
649
661
|
t,
|
|
650
662
|
e.ext ?? !1,
|
|
651
663
|
e.key_ops ?? r
|
|
652
664
|
], a = { ...e };
|
|
653
|
-
return delete a.alg, delete a.use,
|
|
654
|
-
},
|
|
655
|
-
let
|
|
656
|
-
const
|
|
657
|
-
let
|
|
658
|
-
if (
|
|
659
|
-
return
|
|
660
|
-
const o = await
|
|
661
|
-
return a ?
|
|
662
|
-
},
|
|
663
|
-
if (
|
|
665
|
+
return delete a.alg, delete a.use, he.subtle.importKey("jwk", a, ...n);
|
|
666
|
+
}, Ze = (e) => P(e);
|
|
667
|
+
let $, H;
|
|
668
|
+
const et = (e) => e?.[Symbol.toStringTag] === "KeyObject", ue = async (e, t, r, n, a = !1) => {
|
|
669
|
+
let s = e.get(t);
|
|
670
|
+
if (s != null && s[n])
|
|
671
|
+
return s[n];
|
|
672
|
+
const o = await Xe({ ...r, alg: n });
|
|
673
|
+
return a && Object.freeze(t), s ? s[n] = o : e.set(t, { [n]: o }), o;
|
|
674
|
+
}, Qt = (e, t) => {
|
|
675
|
+
if (et(e)) {
|
|
664
676
|
let r = e.export({ format: "jwk" });
|
|
665
|
-
return delete r.d, delete r.dp, delete r.dq, delete r.p, delete r.q, delete r.qi, r.k ?
|
|
677
|
+
return delete r.d, delete r.dp, delete r.dq, delete r.p, delete r.q, delete r.qi, r.k ? Ze(r.k) : (H || (H = /* @__PURE__ */ new WeakMap()), ue(H, e, r, t));
|
|
666
678
|
}
|
|
667
|
-
return e;
|
|
668
|
-
},
|
|
669
|
-
if (
|
|
679
|
+
return j(e) ? e.k ? P(e.k) : (H || (H = /* @__PURE__ */ new WeakMap()), ue(H, e, e, t, !0)) : e;
|
|
680
|
+
}, Xt = (e, t) => {
|
|
681
|
+
if (et(e)) {
|
|
670
682
|
let r = e.export({ format: "jwk" });
|
|
671
|
-
return r.k ?
|
|
683
|
+
return r.k ? Ze(r.k) : ($ || ($ = /* @__PURE__ */ new WeakMap()), ue($, e, r, t));
|
|
672
684
|
}
|
|
673
|
-
return e;
|
|
674
|
-
},
|
|
685
|
+
return j(e) ? e.k ? P(e.k) : ($ || ($ = /* @__PURE__ */ new WeakMap()), ue($, e, e, t, !0)) : e;
|
|
686
|
+
}, Zt = { normalizePublicKey: Qt, normalizePrivateKey: Xt }, O = (e, t, r = 0) => {
|
|
675
687
|
r === 0 && (t.unshift(t.length), t.unshift(6));
|
|
676
688
|
const n = e.indexOf(t[0], r);
|
|
677
689
|
if (n === -1)
|
|
678
690
|
return !1;
|
|
679
691
|
const a = e.subarray(n, n + t.length);
|
|
680
|
-
return a.length !== t.length ? !1 : a.every((
|
|
681
|
-
},
|
|
692
|
+
return a.length !== t.length ? !1 : a.every((s, o) => s === t[o]) || O(e, t, n + 1);
|
|
693
|
+
}, Ne = (e) => {
|
|
682
694
|
switch (!0) {
|
|
683
695
|
case O(e, [42, 134, 72, 206, 61, 3, 1, 7]):
|
|
684
696
|
return "P-256";
|
|
@@ -695,106 +707,156 @@ const qe = (e) => e?.[Symbol.toStringTag] === "KeyObject", ze = async (e, t, r,
|
|
|
695
707
|
case O(e, [43, 101, 113]):
|
|
696
708
|
return "Ed448";
|
|
697
709
|
default:
|
|
698
|
-
throw new
|
|
710
|
+
throw new _("Invalid or unsupported EC Key Curve or OKP Key Sub Type");
|
|
699
711
|
}
|
|
700
|
-
},
|
|
701
|
-
let
|
|
712
|
+
}, er = async (e, t, r, n, a) => {
|
|
713
|
+
let s, o;
|
|
702
714
|
const i = new Uint8Array(atob(r.replace(e, "")).split("").map((c) => c.charCodeAt(0)));
|
|
703
715
|
switch (n) {
|
|
704
716
|
case "PS256":
|
|
705
717
|
case "PS384":
|
|
706
718
|
case "PS512":
|
|
707
|
-
|
|
719
|
+
s = { name: "RSA-PSS", hash: `SHA-${n.slice(-3)}` }, o = ["verify"];
|
|
708
720
|
break;
|
|
709
721
|
case "RS256":
|
|
710
722
|
case "RS384":
|
|
711
723
|
case "RS512":
|
|
712
|
-
|
|
724
|
+
s = { name: "RSASSA-PKCS1-v1_5", hash: `SHA-${n.slice(-3)}` }, o = ["verify"];
|
|
713
725
|
break;
|
|
714
726
|
case "RSA-OAEP":
|
|
715
727
|
case "RSA-OAEP-256":
|
|
716
728
|
case "RSA-OAEP-384":
|
|
717
729
|
case "RSA-OAEP-512":
|
|
718
|
-
|
|
730
|
+
s = {
|
|
719
731
|
name: "RSA-OAEP",
|
|
720
732
|
hash: `SHA-${parseInt(n.slice(-3), 10) || 1}`
|
|
721
|
-
},
|
|
733
|
+
}, o = ["encrypt", "wrapKey"];
|
|
722
734
|
break;
|
|
723
735
|
case "ES256":
|
|
724
|
-
|
|
736
|
+
s = { name: "ECDSA", namedCurve: "P-256" }, o = ["verify"];
|
|
725
737
|
break;
|
|
726
738
|
case "ES384":
|
|
727
|
-
|
|
739
|
+
s = { name: "ECDSA", namedCurve: "P-384" }, o = ["verify"];
|
|
728
740
|
break;
|
|
729
741
|
case "ES512":
|
|
730
|
-
|
|
742
|
+
s = { name: "ECDSA", namedCurve: "P-521" }, o = ["verify"];
|
|
731
743
|
break;
|
|
732
744
|
case "ECDH-ES":
|
|
733
745
|
case "ECDH-ES+A128KW":
|
|
734
746
|
case "ECDH-ES+A192KW":
|
|
735
747
|
case "ECDH-ES+A256KW": {
|
|
736
|
-
const c =
|
|
737
|
-
|
|
748
|
+
const c = Ne(i);
|
|
749
|
+
s = c.startsWith("P-") ? { name: "ECDH", namedCurve: c } : { name: c }, o = [];
|
|
738
750
|
break;
|
|
739
751
|
}
|
|
740
752
|
case "EdDSA":
|
|
741
|
-
|
|
753
|
+
s = { name: Ne(i) }, o = ["verify"];
|
|
742
754
|
break;
|
|
743
755
|
default:
|
|
744
|
-
throw new
|
|
756
|
+
throw new _('Invalid or unsupported "alg" (Algorithm) value');
|
|
745
757
|
}
|
|
746
|
-
return
|
|
747
|
-
},
|
|
748
|
-
async function
|
|
758
|
+
return he.subtle.importKey(t, i, s, !1, o);
|
|
759
|
+
}, tr = (e, t, r) => er(/(?:-----(?:BEGIN|END) PUBLIC KEY-----|\s)/g, "spki", e, t);
|
|
760
|
+
async function rr(e, t, r) {
|
|
749
761
|
if (e.indexOf("-----BEGIN PUBLIC KEY-----") !== 0)
|
|
750
762
|
throw new TypeError('"spki" must be SPKI formatted string');
|
|
751
|
-
return
|
|
763
|
+
return tr(e, t);
|
|
764
|
+
}
|
|
765
|
+
async function nr(e, t) {
|
|
766
|
+
if (!M(e))
|
|
767
|
+
throw new TypeError("JWK must be an object");
|
|
768
|
+
switch (t || (t = e.alg), e.kty) {
|
|
769
|
+
case "oct":
|
|
770
|
+
if (typeof e.k != "string" || !e.k)
|
|
771
|
+
throw new TypeError('missing "k" (Key Value) Parameter value');
|
|
772
|
+
return P(e.k);
|
|
773
|
+
case "RSA":
|
|
774
|
+
if (e.oth !== void 0)
|
|
775
|
+
throw new _('RSA JWK "oth" (Other Primes Info) Parameter value is not supported');
|
|
776
|
+
case "EC":
|
|
777
|
+
case "OKP":
|
|
778
|
+
return Xe({ ...e, alg: t });
|
|
779
|
+
default:
|
|
780
|
+
throw new _('Unsupported "kty" (Key Type) Parameter value');
|
|
781
|
+
}
|
|
752
782
|
}
|
|
753
|
-
const
|
|
783
|
+
const x = (e) => e?.[Symbol.toStringTag], Te = (e, t, r) => {
|
|
784
|
+
var n, a;
|
|
785
|
+
if (t.use !== void 0 && t.use !== "sig")
|
|
786
|
+
throw new TypeError("Invalid key for this operation, when present its use must be sig");
|
|
787
|
+
if (t.key_ops !== void 0 && ((a = (n = t.key_ops).includes) == null ? void 0 : a.call(n, r)) !== !0)
|
|
788
|
+
throw new TypeError(`Invalid key for this operation, when present its key_ops must include ${r}`);
|
|
789
|
+
if (t.alg !== void 0 && t.alg !== e)
|
|
790
|
+
throw new TypeError(`Invalid key for this operation, when present its alg must be ${e}`);
|
|
791
|
+
return !0;
|
|
792
|
+
}, ar = (e, t, r, n) => {
|
|
754
793
|
if (!(t instanceof Uint8Array)) {
|
|
755
|
-
if (
|
|
756
|
-
|
|
794
|
+
if (n && j(t)) {
|
|
795
|
+
if (qt(t) && Te(e, t, r))
|
|
796
|
+
return;
|
|
797
|
+
throw new TypeError('JSON Web Key for symmetric algorithms must have JWK "kty" (Key Type) equal to "oct" and the JWK "k" (Key Value) present');
|
|
798
|
+
}
|
|
799
|
+
if (!Qe(t))
|
|
800
|
+
throw new TypeError(ze(e, t, ...ce, "Uint8Array", n ? "JSON Web Key" : null));
|
|
757
801
|
if (t.type !== "secret")
|
|
758
|
-
throw new TypeError(`${
|
|
802
|
+
throw new TypeError(`${x(t)} instances for symmetric algorithms must be of type "secret"`);
|
|
759
803
|
}
|
|
760
|
-
},
|
|
761
|
-
if (
|
|
762
|
-
|
|
804
|
+
}, or = (e, t, r, n) => {
|
|
805
|
+
if (n && j(t))
|
|
806
|
+
switch (r) {
|
|
807
|
+
case "sign":
|
|
808
|
+
if (Ft(t) && Te(e, t, r))
|
|
809
|
+
return;
|
|
810
|
+
throw new TypeError("JSON Web Key for this operation be a private JWK");
|
|
811
|
+
case "verify":
|
|
812
|
+
if (Bt(t) && Te(e, t, r))
|
|
813
|
+
return;
|
|
814
|
+
throw new TypeError("JSON Web Key for this operation be a public JWK");
|
|
815
|
+
}
|
|
816
|
+
if (!Qe(t))
|
|
817
|
+
throw new TypeError(ze(e, t, ...ce, n ? "JSON Web Key" : null));
|
|
763
818
|
if (t.type === "secret")
|
|
764
|
-
throw new TypeError(`${
|
|
819
|
+
throw new TypeError(`${x(t)} instances for asymmetric algorithms must not be of type "secret"`);
|
|
820
|
+
if (r === "sign" && t.type === "public")
|
|
821
|
+
throw new TypeError(`${x(t)} instances for asymmetric algorithm signing must be of type "private"`);
|
|
822
|
+
if (r === "decrypt" && t.type === "public")
|
|
823
|
+
throw new TypeError(`${x(t)} instances for asymmetric algorithm decryption must be of type "private"`);
|
|
765
824
|
if (t.algorithm && r === "verify" && t.type === "private")
|
|
766
|
-
throw new TypeError(`${
|
|
825
|
+
throw new TypeError(`${x(t)} instances for asymmetric algorithm verifying must be of type "public"`);
|
|
767
826
|
if (t.algorithm && r === "encrypt" && t.type === "private")
|
|
768
|
-
throw new TypeError(`${
|
|
769
|
-
}, Xt = (e, t, r) => {
|
|
770
|
-
e.startsWith("HS") || e === "dir" || e.startsWith("PBES2") || /^A\d{3}(?:GCM)?KW$/.test(e) ? zt(e, t) : Qt(e, t, r);
|
|
827
|
+
throw new TypeError(`${x(t)} instances for asymmetric algorithm encryption must be of type "public"`);
|
|
771
828
|
};
|
|
772
|
-
function
|
|
829
|
+
function tt(e, t, r, n) {
|
|
830
|
+
t.startsWith("HS") || t === "dir" || t.startsWith("PBES2") || /^A\d{3}(?:GCM)?KW$/.test(t) ? ar(t, r, n, e) : or(t, r, n, e);
|
|
831
|
+
}
|
|
832
|
+
tt.bind(void 0, !1);
|
|
833
|
+
const De = tt.bind(void 0, !0);
|
|
834
|
+
function sr(e, t, r, n, a) {
|
|
773
835
|
if (a.crit !== void 0 && n?.crit === void 0)
|
|
774
836
|
throw new e('"crit" (Critical) Header Parameter MUST be integrity protected');
|
|
775
837
|
if (!n || n.crit === void 0)
|
|
776
838
|
return /* @__PURE__ */ new Set();
|
|
777
|
-
if (!Array.isArray(n.crit) || n.crit.length === 0 || n.crit.some((
|
|
839
|
+
if (!Array.isArray(n.crit) || n.crit.length === 0 || n.crit.some((o) => typeof o != "string" || o.length === 0))
|
|
778
840
|
throw new e('"crit" (Critical) Header Parameter MUST be an array of non-empty strings when present');
|
|
779
|
-
let
|
|
780
|
-
r !== void 0 ?
|
|
781
|
-
for (const
|
|
782
|
-
if (!
|
|
783
|
-
throw new
|
|
784
|
-
if (a[
|
|
785
|
-
throw new e(`Extension Header Parameter "${
|
|
786
|
-
if (
|
|
787
|
-
throw new e(`Extension Header Parameter "${
|
|
841
|
+
let s;
|
|
842
|
+
r !== void 0 ? s = new Map([...Object.entries(r), ...t.entries()]) : s = t;
|
|
843
|
+
for (const o of n.crit) {
|
|
844
|
+
if (!s.has(o))
|
|
845
|
+
throw new _(`Extension Header Parameter "${o}" is not recognized`);
|
|
846
|
+
if (a[o] === void 0)
|
|
847
|
+
throw new e(`Extension Header Parameter "${o}" is missing`);
|
|
848
|
+
if (s.get(o) && n[o] === void 0)
|
|
849
|
+
throw new e(`Extension Header Parameter "${o}" MUST be integrity protected`);
|
|
788
850
|
}
|
|
789
851
|
return new Set(n.crit);
|
|
790
852
|
}
|
|
791
|
-
const
|
|
853
|
+
const ir = (e, t) => {
|
|
792
854
|
if (t !== void 0 && (!Array.isArray(t) || t.some((r) => typeof r != "string")))
|
|
793
855
|
throw new TypeError(`"${e}" option must be an array of strings`);
|
|
794
856
|
if (t)
|
|
795
857
|
return new Set(t);
|
|
796
858
|
};
|
|
797
|
-
function
|
|
859
|
+
function cr(e, t) {
|
|
798
860
|
const r = `SHA-${e.slice(-3)}`;
|
|
799
861
|
switch (e) {
|
|
800
862
|
case "HS256":
|
|
@@ -816,31 +878,31 @@ function tr(e, t) {
|
|
|
816
878
|
case "EdDSA":
|
|
817
879
|
return { name: t.name };
|
|
818
880
|
default:
|
|
819
|
-
throw new
|
|
881
|
+
throw new _(`alg ${e} is not supported either by JOSE or your javascript runtime`);
|
|
820
882
|
}
|
|
821
883
|
}
|
|
822
|
-
async function
|
|
823
|
-
if (t = await
|
|
824
|
-
return
|
|
884
|
+
async function ur(e, t, r) {
|
|
885
|
+
if (t = await Zt.normalizePublicKey(t, e), Be(t))
|
|
886
|
+
return Gt(t, e, r), t;
|
|
825
887
|
if (t instanceof Uint8Array) {
|
|
826
888
|
if (!e.startsWith("HS"))
|
|
827
|
-
throw new TypeError(
|
|
828
|
-
return
|
|
889
|
+
throw new TypeError(Ce(t, ...ce));
|
|
890
|
+
return he.subtle.importKey("raw", t, { hash: `SHA-${e.slice(-3)}`, name: "HMAC" }, !1, [r]);
|
|
829
891
|
}
|
|
830
|
-
throw new TypeError(
|
|
892
|
+
throw new TypeError(Ce(t, ...ce, "Uint8Array", "JSON Web Key"));
|
|
831
893
|
}
|
|
832
|
-
const
|
|
833
|
-
const a = await
|
|
834
|
-
|
|
835
|
-
const
|
|
894
|
+
const lr = async (e, t, r, n) => {
|
|
895
|
+
const a = await ur(e, t, "verify");
|
|
896
|
+
jt(e, a);
|
|
897
|
+
const s = cr(e, a.algorithm);
|
|
836
898
|
try {
|
|
837
|
-
return await
|
|
899
|
+
return await he.subtle.verify(s, a, r, n);
|
|
838
900
|
} catch {
|
|
839
901
|
return !1;
|
|
840
902
|
}
|
|
841
903
|
};
|
|
842
|
-
async function
|
|
843
|
-
if (!
|
|
904
|
+
async function dr(e, t, r) {
|
|
905
|
+
if (!M(e))
|
|
844
906
|
throw new w("Flattened JWS must be an object");
|
|
845
907
|
if (e.protected === void 0 && e.header === void 0)
|
|
846
908
|
throw new w('Flattened JWS must have either of the "protected" or "header" members');
|
|
@@ -850,69 +912,69 @@ async function ar(e, t, r) {
|
|
|
850
912
|
throw new w("JWS Payload missing");
|
|
851
913
|
if (typeof e.signature != "string")
|
|
852
914
|
throw new w("JWS Signature missing or incorrect type");
|
|
853
|
-
if (e.header !== void 0 && !
|
|
915
|
+
if (e.header !== void 0 && !M(e.header))
|
|
854
916
|
throw new w("JWS Unprotected Header incorrect type");
|
|
855
917
|
let n = {};
|
|
856
918
|
if (e.protected)
|
|
857
919
|
try {
|
|
858
|
-
const T =
|
|
859
|
-
n = JSON.parse(
|
|
920
|
+
const T = P(e.protected);
|
|
921
|
+
n = JSON.parse(q.decode(T));
|
|
860
922
|
} catch {
|
|
861
923
|
throw new w("JWS Protected Header is invalid");
|
|
862
924
|
}
|
|
863
|
-
if (!
|
|
925
|
+
if (!Mt(n, e.header))
|
|
864
926
|
throw new w("JWS Protected and JWS Unprotected Header Parameter names must be disjoint");
|
|
865
927
|
const a = {
|
|
866
928
|
...n,
|
|
867
929
|
...e.header
|
|
868
|
-
},
|
|
869
|
-
let
|
|
870
|
-
if (
|
|
930
|
+
}, s = sr(w, /* @__PURE__ */ new Map([["b64", !0]]), r?.crit, n, a);
|
|
931
|
+
let o = !0;
|
|
932
|
+
if (s.has("b64") && (o = n.b64, typeof o != "boolean"))
|
|
871
933
|
throw new w('The "b64" (base64url-encode payload) Header Parameter must be a boolean');
|
|
872
934
|
const { alg: i } = a;
|
|
873
935
|
if (typeof i != "string" || !i)
|
|
874
936
|
throw new w('JWS "alg" (Algorithm) Header Parameter missing or invalid');
|
|
875
|
-
const c = r &&
|
|
937
|
+
const c = r && ir("algorithms", r.algorithms);
|
|
876
938
|
if (c && !c.has(i))
|
|
877
|
-
throw new
|
|
878
|
-
if (
|
|
939
|
+
throw new Wt('"alg" (Algorithm) Header Parameter value not allowed');
|
|
940
|
+
if (o) {
|
|
879
941
|
if (typeof e.payload != "string")
|
|
880
942
|
throw new w("JWS Payload must be a string");
|
|
881
943
|
} else if (typeof e.payload != "string" && !(e.payload instanceof Uint8Array))
|
|
882
944
|
throw new w("JWS Payload must be a string or an Uint8Array instance");
|
|
883
945
|
let h = !1;
|
|
884
|
-
typeof t == "function"
|
|
885
|
-
const y =
|
|
946
|
+
typeof t == "function" ? (t = await t(n, e), h = !0, De(i, t, "verify"), j(t) && (t = await nr(t, i))) : De(i, t, "verify");
|
|
947
|
+
const y = Ht(Z.encode(e.protected ?? ""), Z.encode("."), typeof e.payload == "string" ? Z.encode(e.payload) : e.payload);
|
|
886
948
|
let p;
|
|
887
949
|
try {
|
|
888
|
-
p =
|
|
950
|
+
p = P(e.signature);
|
|
889
951
|
} catch {
|
|
890
952
|
throw new w("Failed to base64url decode the signature");
|
|
891
953
|
}
|
|
892
|
-
if (!await
|
|
893
|
-
throw new
|
|
954
|
+
if (!await lr(i, t, p, y))
|
|
955
|
+
throw new Jt();
|
|
894
956
|
let l;
|
|
895
|
-
if (
|
|
957
|
+
if (o)
|
|
896
958
|
try {
|
|
897
|
-
l =
|
|
959
|
+
l = P(e.payload);
|
|
898
960
|
} catch {
|
|
899
961
|
throw new w("Failed to base64url decode the payload");
|
|
900
962
|
}
|
|
901
|
-
else typeof e.payload == "string" ? l =
|
|
963
|
+
else typeof e.payload == "string" ? l = Z.encode(e.payload) : l = e.payload;
|
|
902
964
|
const A = { payload: l };
|
|
903
965
|
return e.protected !== void 0 && (A.protectedHeader = n), e.header !== void 0 && (A.unprotectedHeader = e.header), h ? { ...A, key: t } : A;
|
|
904
966
|
}
|
|
905
|
-
async function
|
|
906
|
-
if (e instanceof Uint8Array && (e =
|
|
967
|
+
async function hr(e, t, r) {
|
|
968
|
+
if (e instanceof Uint8Array && (e = q.decode(e)), typeof e != "string")
|
|
907
969
|
throw new w("Compact JWS must be a string or Uint8Array");
|
|
908
|
-
const { 0: n, 1: a, 2:
|
|
909
|
-
if (
|
|
970
|
+
const { 0: n, 1: a, 2: s, length: o } = e.split(".");
|
|
971
|
+
if (o !== 3)
|
|
910
972
|
throw new w("Invalid Compact JWS");
|
|
911
|
-
const i = await
|
|
973
|
+
const i = await dr({ payload: a, protected: n, signature: s }, t, r), c = { payload: i.payload, protectedHeader: i.protectedHeader };
|
|
912
974
|
return typeof t == "function" ? { ...c, key: i.key } : c;
|
|
913
975
|
}
|
|
914
|
-
const
|
|
915
|
-
const t =
|
|
976
|
+
const pr = (e) => Math.floor(e.getTime() / 1e3), rt = 60, nt = rt * 60, be = nt * 24, yr = be * 7, fr = be * 365.25, gr = /^(\+|\-)? ?(\d+|\d+\.\d+) ?(seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)(?: (ago|from now))?$/i, Ke = (e) => {
|
|
977
|
+
const t = gr.exec(e);
|
|
916
978
|
if (!t || t[4] && t[1])
|
|
917
979
|
throw new TypeError("Invalid time period format");
|
|
918
980
|
const r = parseFloat(t[2]), n = t[3].toLowerCase();
|
|
@@ -930,56 +992,56 @@ const or = (e) => Math.floor(e.getTime() / 1e3), Qe = 60, Xe = Qe * 60, Ae = Xe
|
|
|
930
992
|
case "min":
|
|
931
993
|
case "mins":
|
|
932
994
|
case "m":
|
|
933
|
-
a = Math.round(r *
|
|
995
|
+
a = Math.round(r * rt);
|
|
934
996
|
break;
|
|
935
997
|
case "hour":
|
|
936
998
|
case "hours":
|
|
937
999
|
case "hr":
|
|
938
1000
|
case "hrs":
|
|
939
1001
|
case "h":
|
|
940
|
-
a = Math.round(r *
|
|
1002
|
+
a = Math.round(r * nt);
|
|
941
1003
|
break;
|
|
942
1004
|
case "day":
|
|
943
1005
|
case "days":
|
|
944
1006
|
case "d":
|
|
945
|
-
a = Math.round(r *
|
|
1007
|
+
a = Math.round(r * be);
|
|
946
1008
|
break;
|
|
947
1009
|
case "week":
|
|
948
1010
|
case "weeks":
|
|
949
1011
|
case "w":
|
|
950
|
-
a = Math.round(r *
|
|
1012
|
+
a = Math.round(r * yr);
|
|
951
1013
|
break;
|
|
952
1014
|
default:
|
|
953
|
-
a = Math.round(r *
|
|
1015
|
+
a = Math.round(r * fr);
|
|
954
1016
|
break;
|
|
955
1017
|
}
|
|
956
1018
|
return t[1] === "-" || t[4] === "ago" ? -a : a;
|
|
957
|
-
},
|
|
1019
|
+
}, Ue = (e) => e.toLowerCase().replace(/^application\//, ""), Er = (e, t) => typeof e == "string" ? t.includes(e) : Array.isArray(e) ? t.some(Set.prototype.has.bind(new Set(e))) : !1, mr = (e, t, r = {}) => {
|
|
958
1020
|
let n;
|
|
959
1021
|
try {
|
|
960
|
-
n = JSON.parse(
|
|
1022
|
+
n = JSON.parse(q.decode(t));
|
|
961
1023
|
} catch {
|
|
962
1024
|
}
|
|
963
|
-
if (!
|
|
1025
|
+
if (!M(n))
|
|
964
1026
|
throw new v("JWT Claims Set must be a top-level JSON object");
|
|
965
1027
|
const { typ: a } = r;
|
|
966
|
-
if (a && (typeof e.typ != "string" ||
|
|
1028
|
+
if (a && (typeof e.typ != "string" || Ue(e.typ) !== Ue(a)))
|
|
967
1029
|
throw new R('unexpected "typ" JWT header value', n, "typ", "check_failed");
|
|
968
|
-
const { requiredClaims:
|
|
969
|
-
h !== void 0 && y.push("iat"), c !== void 0 && y.push("aud"), i !== void 0 && y.push("sub"),
|
|
1030
|
+
const { requiredClaims: s = [], issuer: o, subject: i, audience: c, maxTokenAge: h } = r, y = [...s];
|
|
1031
|
+
h !== void 0 && y.push("iat"), c !== void 0 && y.push("aud"), i !== void 0 && y.push("sub"), o !== void 0 && y.push("iss");
|
|
970
1032
|
for (const T of new Set(y.reverse()))
|
|
971
1033
|
if (!(T in n))
|
|
972
1034
|
throw new R(`missing required "${T}" claim`, n, T, "missing");
|
|
973
|
-
if (
|
|
1035
|
+
if (o && !(Array.isArray(o) ? o : [o]).includes(n.iss))
|
|
974
1036
|
throw new R('unexpected "iss" claim value', n, "iss", "check_failed");
|
|
975
1037
|
if (i && n.sub !== i)
|
|
976
1038
|
throw new R('unexpected "sub" claim value', n, "sub", "check_failed");
|
|
977
|
-
if (c && !
|
|
1039
|
+
if (c && !Er(n.aud, typeof c == "string" ? [c] : c))
|
|
978
1040
|
throw new R('unexpected "aud" claim value', n, "aud", "check_failed");
|
|
979
1041
|
let p;
|
|
980
1042
|
switch (typeof r.clockTolerance) {
|
|
981
1043
|
case "string":
|
|
982
|
-
p =
|
|
1044
|
+
p = Ke(r.clockTolerance);
|
|
983
1045
|
break;
|
|
984
1046
|
case "number":
|
|
985
1047
|
p = r.clockTolerance;
|
|
@@ -990,7 +1052,7 @@ const or = (e) => Math.floor(e.getTime() / 1e3), Qe = 60, Xe = Qe * 60, Ae = Xe
|
|
|
990
1052
|
default:
|
|
991
1053
|
throw new TypeError("Invalid clockTolerance option type");
|
|
992
1054
|
}
|
|
993
|
-
const { currentDate: l } = r, A =
|
|
1055
|
+
const { currentDate: l } = r, A = pr(l || /* @__PURE__ */ new Date());
|
|
994
1056
|
if ((n.iat !== void 0 || h) && typeof n.iat != "number")
|
|
995
1057
|
throw new R('"iat" claim must be a number', n, "iat", "invalid");
|
|
996
1058
|
if (n.nbf !== void 0) {
|
|
@@ -1003,27 +1065,27 @@ const or = (e) => Math.floor(e.getTime() / 1e3), Qe = 60, Xe = Qe * 60, Ae = Xe
|
|
|
1003
1065
|
if (typeof n.exp != "number")
|
|
1004
1066
|
throw new R('"exp" claim must be a number', n, "exp", "invalid");
|
|
1005
1067
|
if (n.exp <= A - p)
|
|
1006
|
-
throw new
|
|
1068
|
+
throw new Pe('"exp" claim timestamp check failed', n, "exp", "check_failed");
|
|
1007
1069
|
}
|
|
1008
1070
|
if (h) {
|
|
1009
|
-
const T = A - n.iat,
|
|
1010
|
-
if (T - p >
|
|
1011
|
-
throw new
|
|
1071
|
+
const T = A - n.iat, ye = typeof h == "number" ? h : Ke(h);
|
|
1072
|
+
if (T - p > ye)
|
|
1073
|
+
throw new Pe('"iat" claim timestamp check failed (too far in the past)', n, "iat", "check_failed");
|
|
1012
1074
|
if (T < 0 - p)
|
|
1013
1075
|
throw new R('"iat" claim timestamp check failed (it should be in the past)', n, "iat", "check_failed");
|
|
1014
1076
|
}
|
|
1015
1077
|
return n;
|
|
1016
1078
|
};
|
|
1017
|
-
async function
|
|
1079
|
+
async function wr(e, t, r) {
|
|
1018
1080
|
var n;
|
|
1019
|
-
const a = await
|
|
1081
|
+
const a = await hr(e, t, r);
|
|
1020
1082
|
if ((n = a.protectedHeader.crit) != null && n.includes("b64") && a.protectedHeader.b64 === !1)
|
|
1021
1083
|
throw new v("JWTs MUST NOT use unencoded payload");
|
|
1022
|
-
const
|
|
1023
|
-
return typeof t == "function" ? { ...
|
|
1084
|
+
const s = { payload: mr(a.protectedHeader, a.payload, r), protectedHeader: a.protectedHeader };
|
|
1085
|
+
return typeof t == "function" ? { ...s, key: a.key } : s;
|
|
1024
1086
|
}
|
|
1025
|
-
const
|
|
1026
|
-
function
|
|
1087
|
+
const Sr = P;
|
|
1088
|
+
function Ar(e) {
|
|
1027
1089
|
if (typeof e != "string")
|
|
1028
1090
|
throw new v("JWTs must use Compact JWS serialization, JWT must be a string");
|
|
1029
1091
|
const { 1: t, length: r } = e.split(".");
|
|
@@ -1035,152 +1097,152 @@ function yr(e) {
|
|
|
1035
1097
|
throw new v("JWTs must contain a payload");
|
|
1036
1098
|
let n;
|
|
1037
1099
|
try {
|
|
1038
|
-
n =
|
|
1100
|
+
n = Sr(t);
|
|
1039
1101
|
} catch {
|
|
1040
1102
|
throw new v("Failed to base64url decode the payload");
|
|
1041
1103
|
}
|
|
1042
1104
|
let a;
|
|
1043
1105
|
try {
|
|
1044
|
-
a = JSON.parse(
|
|
1106
|
+
a = JSON.parse(q.decode(n));
|
|
1045
1107
|
} catch {
|
|
1046
1108
|
throw new v("Failed to parse the decoded payload as JSON");
|
|
1047
1109
|
}
|
|
1048
|
-
if (!
|
|
1110
|
+
if (!M(a))
|
|
1049
1111
|
throw new v("Invalid JWT Claims Set");
|
|
1050
1112
|
return a;
|
|
1051
1113
|
}
|
|
1052
|
-
const
|
|
1114
|
+
const V = async (e) => {
|
|
1053
1115
|
try {
|
|
1054
|
-
const t = f.ALG, r = await
|
|
1055
|
-
return await
|
|
1116
|
+
const t = f.ALG, r = await rr($t, t);
|
|
1117
|
+
return await wr(e, r, {
|
|
1056
1118
|
issuer: f.ISSUER
|
|
1057
1119
|
});
|
|
1058
1120
|
} catch {
|
|
1059
1121
|
return;
|
|
1060
1122
|
}
|
|
1061
|
-
},
|
|
1123
|
+
}, Tr = (e) => {
|
|
1062
1124
|
try {
|
|
1063
|
-
return
|
|
1125
|
+
return Ar(e);
|
|
1064
1126
|
} catch {
|
|
1065
1127
|
return;
|
|
1066
1128
|
}
|
|
1067
1129
|
};
|
|
1068
1130
|
var E = [];
|
|
1069
|
-
for (var
|
|
1070
|
-
E.push((
|
|
1071
|
-
function
|
|
1131
|
+
for (var me = 0; me < 256; ++me)
|
|
1132
|
+
E.push((me + 256).toString(16).slice(1));
|
|
1133
|
+
function Rr(e, t = 0) {
|
|
1072
1134
|
return (E[e[t + 0]] + E[e[t + 1]] + E[e[t + 2]] + E[e[t + 3]] + "-" + E[e[t + 4]] + E[e[t + 5]] + "-" + E[e[t + 6]] + E[e[t + 7]] + "-" + E[e[t + 8]] + E[e[t + 9]] + "-" + E[e[t + 10]] + E[e[t + 11]] + E[e[t + 12]] + E[e[t + 13]] + E[e[t + 14]] + E[e[t + 15]]).toLowerCase();
|
|
1073
1135
|
}
|
|
1074
|
-
var
|
|
1075
|
-
function
|
|
1076
|
-
if (!
|
|
1136
|
+
var te, br = new Uint8Array(16);
|
|
1137
|
+
function _r() {
|
|
1138
|
+
if (!te && (te = typeof crypto < "u" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto), !te))
|
|
1077
1139
|
throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
|
|
1078
|
-
return
|
|
1140
|
+
return te(br);
|
|
1079
1141
|
}
|
|
1080
|
-
var
|
|
1081
|
-
const
|
|
1082
|
-
randomUUID:
|
|
1142
|
+
var Ir = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto);
|
|
1143
|
+
const $e = {
|
|
1144
|
+
randomUUID: Ir
|
|
1083
1145
|
};
|
|
1084
|
-
function
|
|
1085
|
-
if (
|
|
1086
|
-
return
|
|
1146
|
+
function He(e, t, r) {
|
|
1147
|
+
if ($e.randomUUID && !t && !e)
|
|
1148
|
+
return $e.randomUUID();
|
|
1087
1149
|
e = e || {};
|
|
1088
|
-
var n = e.random || (e.rng ||
|
|
1089
|
-
return n[6] = n[6] & 15 | 64, n[8] = n[8] & 63 | 128,
|
|
1150
|
+
var n = e.random || (e.rng || _r)();
|
|
1151
|
+
return n[6] = n[6] & 15 | 64, n[8] = n[8] & 63 | 128, Rr(n);
|
|
1090
1152
|
}
|
|
1091
|
-
const
|
|
1153
|
+
const Le = globalThis.crypto, kr = (e) => `${He()}${He()}`.slice(0, e), vr = (e) => btoa(
|
|
1092
1154
|
[...new Uint8Array(e)].map((t) => String.fromCharCode(t)).join("")
|
|
1093
1155
|
);
|
|
1094
|
-
async function
|
|
1095
|
-
if (!
|
|
1156
|
+
async function Or(e) {
|
|
1157
|
+
if (!Le.subtle)
|
|
1096
1158
|
throw new Error(
|
|
1097
1159
|
"crypto.subtle is available only in secure contexts (HTTPS)."
|
|
1098
1160
|
);
|
|
1099
|
-
const t = new TextEncoder().encode(e), r = await
|
|
1100
|
-
return
|
|
1161
|
+
const t = new TextEncoder().encode(e), r = await Le.subtle.digest("SHA-256", t);
|
|
1162
|
+
return vr(r).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
1101
1163
|
}
|
|
1102
|
-
async function
|
|
1103
|
-
const r =
|
|
1164
|
+
async function Pr(e) {
|
|
1165
|
+
const r = kr(43), n = await Or(r);
|
|
1104
1166
|
return {
|
|
1105
1167
|
code_verifier: r,
|
|
1106
1168
|
code_challenge: n
|
|
1107
1169
|
};
|
|
1108
1170
|
}
|
|
1109
|
-
const
|
|
1171
|
+
const en = async (e, t) => {
|
|
1110
1172
|
var r;
|
|
1111
|
-
const n = await
|
|
1173
|
+
const n = await V(e);
|
|
1112
1174
|
if (!n || !Array.isArray((r = n.payload) == null ? void 0 : r[f.SCOPES_KEY]))
|
|
1113
1175
|
return !1;
|
|
1114
1176
|
const a = n.payload[f.SCOPES_KEY];
|
|
1115
|
-
return Array.isArray(t) ? t.every((
|
|
1116
|
-
(
|
|
1177
|
+
return Array.isArray(t) ? t.every((s) => a.includes(s)) : Object.keys(t).some(
|
|
1178
|
+
(s) => t[s].every((o) => a.includes(o))
|
|
1117
1179
|
);
|
|
1118
1180
|
};
|
|
1119
|
-
function
|
|
1181
|
+
function at(e, t) {
|
|
1120
1182
|
window.dispatchEvent(new StorageEvent("storage", { key: e, newValue: t }));
|
|
1121
1183
|
}
|
|
1122
|
-
const
|
|
1184
|
+
const We = (e, t) => {
|
|
1123
1185
|
const r = JSON.stringify(
|
|
1124
1186
|
typeof t == "function" ? t() : t
|
|
1125
1187
|
);
|
|
1126
|
-
window.localStorage.setItem(e, r),
|
|
1127
|
-
},
|
|
1128
|
-
window.localStorage.removeItem(e),
|
|
1129
|
-
},
|
|
1130
|
-
function
|
|
1188
|
+
window.localStorage.setItem(e, r), at(e, r);
|
|
1189
|
+
}, Cr = (e) => {
|
|
1190
|
+
window.localStorage.removeItem(e), at(e, null);
|
|
1191
|
+
}, Je = (e) => window.localStorage.getItem(e), Nr = (e) => (window.addEventListener("storage", e), () => window.removeEventListener("storage", e));
|
|
1192
|
+
function re({
|
|
1131
1193
|
key: e,
|
|
1132
1194
|
initialValue: t
|
|
1133
1195
|
}) {
|
|
1134
|
-
const r =
|
|
1135
|
-
(
|
|
1196
|
+
const r = bt(Nr, () => Je(e)), n = D(
|
|
1197
|
+
(o) => {
|
|
1136
1198
|
try {
|
|
1137
|
-
const i = typeof
|
|
1138
|
-
i == null ?
|
|
1199
|
+
const i = typeof o == "function" ? o(JSON.parse(r)) : o;
|
|
1200
|
+
i == null ? Cr(e) : We(e, i);
|
|
1139
1201
|
} catch (i) {
|
|
1140
1202
|
console.warn(i);
|
|
1141
1203
|
}
|
|
1142
1204
|
},
|
|
1143
1205
|
[e, r]
|
|
1144
|
-
), a =
|
|
1206
|
+
), a = D(() => {
|
|
1145
1207
|
n(t);
|
|
1146
|
-
}, [t, n]),
|
|
1208
|
+
}, [t, n]), s = D(() => {
|
|
1147
1209
|
n(null);
|
|
1148
1210
|
}, [n]);
|
|
1149
|
-
return
|
|
1211
|
+
return xe(() => {
|
|
1150
1212
|
try {
|
|
1151
|
-
|
|
1152
|
-
} catch (
|
|
1153
|
-
console.warn(
|
|
1213
|
+
Je(e) === null && typeof t < "u" && We(e, t);
|
|
1214
|
+
} catch (o) {
|
|
1215
|
+
console.warn(o);
|
|
1154
1216
|
}
|
|
1155
|
-
}, [e, t]), [r ? JSON.parse(r) : null, n, a,
|
|
1217
|
+
}, [e, t]), [r ? JSON.parse(r) : null, n, a, s];
|
|
1156
1218
|
}
|
|
1157
1219
|
var m = [];
|
|
1158
|
-
for (var
|
|
1159
|
-
m.push((
|
|
1160
|
-
function
|
|
1220
|
+
for (var we = 0; we < 256; ++we)
|
|
1221
|
+
m.push((we + 256).toString(16).slice(1));
|
|
1222
|
+
function Dr(e, t = 0) {
|
|
1161
1223
|
return (m[e[t + 0]] + m[e[t + 1]] + m[e[t + 2]] + m[e[t + 3]] + "-" + m[e[t + 4]] + m[e[t + 5]] + "-" + m[e[t + 6]] + m[e[t + 7]] + "-" + m[e[t + 8]] + m[e[t + 9]] + "-" + m[e[t + 10]] + m[e[t + 11]] + m[e[t + 12]] + m[e[t + 13]] + m[e[t + 14]] + m[e[t + 15]]).toLowerCase();
|
|
1162
1224
|
}
|
|
1163
|
-
var
|
|
1164
|
-
function
|
|
1165
|
-
if (!
|
|
1225
|
+
var ne, Kr = new Uint8Array(16);
|
|
1226
|
+
function Ur() {
|
|
1227
|
+
if (!ne && (ne = typeof crypto < "u" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto), !ne))
|
|
1166
1228
|
throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
|
|
1167
|
-
return
|
|
1229
|
+
return ne(Kr);
|
|
1168
1230
|
}
|
|
1169
|
-
var
|
|
1170
|
-
const
|
|
1171
|
-
randomUUID:
|
|
1231
|
+
var $r = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto);
|
|
1232
|
+
const Ye = {
|
|
1233
|
+
randomUUID: $r
|
|
1172
1234
|
};
|
|
1173
|
-
function
|
|
1174
|
-
if (
|
|
1175
|
-
return
|
|
1235
|
+
function Se(e, t, r) {
|
|
1236
|
+
if (Ye.randomUUID && !t && !e)
|
|
1237
|
+
return Ye.randomUUID();
|
|
1176
1238
|
e = e || {};
|
|
1177
|
-
var n = e.random || (e.rng ||
|
|
1178
|
-
return n[6] = n[6] & 15 | 64, n[8] = n[8] & 63 | 128,
|
|
1239
|
+
var n = e.random || (e.rng || Ur)();
|
|
1240
|
+
return n[6] = n[6] & 15 | 64, n[8] = n[8] & 63 | 128, Dr(n);
|
|
1179
1241
|
}
|
|
1180
|
-
const
|
|
1242
|
+
const L = "Your session has expired. For your security, please log in again to continue.", Hr = "Your session has been successfully terminated.", Ae = "Login failed. Please try again.", Lr = "Error getting access token, please re-authenticate.", Wr = "You forgot to wrap your component in <AuthProvider>.", le = {
|
|
1181
1243
|
dev: "https://auth.gizmette.local.com:3003",
|
|
1182
1244
|
prod: "https://mylogin.gizmette.com/auth"
|
|
1183
|
-
},
|
|
1245
|
+
}, ae = "@@auth@@", B = "LOADING", se = "LOGIN", ot = "LOGOUT", z = "success", I = "failure", st = "include", it = "POST", ct = "application/json", oe = {
|
|
1184
1246
|
GET_REGISTRATION_OPTIONS: `mutation GetPasskeyRegistrationOptions(
|
|
1185
1247
|
$clientId: String!,
|
|
1186
1248
|
$username: String!,
|
|
@@ -1261,39 +1323,39 @@ const K = "Your session has expired. For your security, please log in again to c
|
|
|
1261
1323
|
email
|
|
1262
1324
|
}
|
|
1263
1325
|
}`
|
|
1264
|
-
},
|
|
1326
|
+
}, W = {
|
|
1265
1327
|
GET_REGISTRATION_OPTIONS: {
|
|
1266
|
-
schema:
|
|
1328
|
+
schema: oe.GET_REGISTRATION_OPTIONS,
|
|
1267
1329
|
method: "getPasskeyRegistrationOptions"
|
|
1268
1330
|
},
|
|
1269
1331
|
VERIFY_REGISTRATION: {
|
|
1270
|
-
schema:
|
|
1332
|
+
schema: oe.VERIFY_REGISTRATION,
|
|
1271
1333
|
method: "verifyPasskeyRegistration"
|
|
1272
1334
|
},
|
|
1273
1335
|
GET_AUTHENTICATION_OPTIONS: {
|
|
1274
|
-
schema:
|
|
1336
|
+
schema: oe.GET_AUTHENTICATION_OPTIONS,
|
|
1275
1337
|
method: "getPasskeyAuthenticationOptions"
|
|
1276
1338
|
},
|
|
1277
1339
|
VERIFY_AUTHENTICATION: {
|
|
1278
|
-
schema:
|
|
1340
|
+
schema: oe.VERIFY_AUTHENTICATION,
|
|
1279
1341
|
method: "verifyPasskeyAuthentication"
|
|
1280
1342
|
}
|
|
1281
|
-
},
|
|
1343
|
+
}, J = async ({
|
|
1282
1344
|
accessToken: e,
|
|
1283
1345
|
type: t,
|
|
1284
1346
|
clientId: r,
|
|
1285
1347
|
params: n = {}
|
|
1286
1348
|
}) => {
|
|
1287
1349
|
try {
|
|
1288
|
-
const a = `Bearer ${e}`,
|
|
1289
|
-
|
|
1350
|
+
const a = `Bearer ${e}`, s = await fetch(
|
|
1351
|
+
ut ? `${le.dev}/graphql` : `${le.prod}/graphql`,
|
|
1290
1352
|
{
|
|
1291
|
-
credentials:
|
|
1292
|
-
method:
|
|
1353
|
+
credentials: st,
|
|
1354
|
+
method: it,
|
|
1293
1355
|
headers: {
|
|
1294
1356
|
authorization: a,
|
|
1295
|
-
"Content-Type":
|
|
1296
|
-
[
|
|
1357
|
+
"Content-Type": ct,
|
|
1358
|
+
[Fe.CLIENT_ID]: `${r}`
|
|
1297
1359
|
},
|
|
1298
1360
|
body: JSON.stringify({
|
|
1299
1361
|
query: t.schema,
|
|
@@ -1301,30 +1363,30 @@ const K = "Your session has expired. For your security, please log in again to c
|
|
|
1301
1363
|
})
|
|
1302
1364
|
}
|
|
1303
1365
|
);
|
|
1304
|
-
if (
|
|
1366
|
+
if (s.status !== 200)
|
|
1305
1367
|
return { status: I, data: [] };
|
|
1306
|
-
const { data:
|
|
1368
|
+
const { data: o } = await s.json();
|
|
1307
1369
|
return {
|
|
1308
|
-
status:
|
|
1309
|
-
data:
|
|
1370
|
+
status: z,
|
|
1371
|
+
data: o[t.method]
|
|
1310
1372
|
};
|
|
1311
1373
|
} catch (a) {
|
|
1312
1374
|
return console.error(a), { status: I, data: [] };
|
|
1313
1375
|
}
|
|
1314
|
-
},
|
|
1376
|
+
}, pe = async ({
|
|
1315
1377
|
type: e,
|
|
1316
1378
|
clientId: t,
|
|
1317
1379
|
params: r = {}
|
|
1318
1380
|
}) => {
|
|
1319
1381
|
try {
|
|
1320
1382
|
const n = await fetch(
|
|
1321
|
-
|
|
1383
|
+
ut ? `${le.dev}/${e}` : `${le.prod}/${e}`,
|
|
1322
1384
|
{
|
|
1323
|
-
credentials:
|
|
1324
|
-
method:
|
|
1385
|
+
credentials: st,
|
|
1386
|
+
method: it,
|
|
1325
1387
|
headers: {
|
|
1326
|
-
"Content-Type":
|
|
1327
|
-
[
|
|
1388
|
+
"Content-Type": ct,
|
|
1389
|
+
[Fe.CLIENT_ID]: `${t}`
|
|
1328
1390
|
},
|
|
1329
1391
|
body: JSON.stringify(r)
|
|
1330
1392
|
}
|
|
@@ -1333,27 +1395,27 @@ const K = "Your session has expired. For your security, please log in again to c
|
|
|
1333
1395
|
return { status: I, data: [] };
|
|
1334
1396
|
const { data: a } = await n.json();
|
|
1335
1397
|
return {
|
|
1336
|
-
status:
|
|
1398
|
+
status: z,
|
|
1337
1399
|
data: a || []
|
|
1338
1400
|
};
|
|
1339
1401
|
} catch (n) {
|
|
1340
1402
|
return console.error(n), { status: I, data: [] };
|
|
1341
1403
|
}
|
|
1342
|
-
},
|
|
1404
|
+
}, Jr = process.env.NODE_ENV === "production", ut = !Jr, lt = {
|
|
1343
1405
|
isLoading: !0,
|
|
1344
1406
|
isAuthenticated: !1,
|
|
1345
1407
|
user: void 0,
|
|
1346
1408
|
logoutReason: "",
|
|
1347
1409
|
debug: !1,
|
|
1348
1410
|
authenticationType: ""
|
|
1349
|
-
},
|
|
1411
|
+
}, Yr = (e) => {
|
|
1350
1412
|
try {
|
|
1351
|
-
const t =
|
|
1413
|
+
const t = Tr(e);
|
|
1352
1414
|
return t ? t[f.USER_ID_KEY] : "";
|
|
1353
1415
|
} catch {
|
|
1354
1416
|
return "";
|
|
1355
1417
|
}
|
|
1356
|
-
},
|
|
1418
|
+
}, xr = async ({
|
|
1357
1419
|
userId: e,
|
|
1358
1420
|
clientId: t,
|
|
1359
1421
|
domain: r,
|
|
@@ -1361,8 +1423,8 @@ const K = "Your session has expired. For your security, please log in again to c
|
|
|
1361
1423
|
}) => {
|
|
1362
1424
|
try {
|
|
1363
1425
|
return {
|
|
1364
|
-
status: (await
|
|
1365
|
-
type:
|
|
1426
|
+
status: (await pe({
|
|
1427
|
+
type: de.LOGOUT,
|
|
1366
1428
|
clientId: t,
|
|
1367
1429
|
params: {
|
|
1368
1430
|
userId: e,
|
|
@@ -1376,34 +1438,34 @@ const K = "Your session has expired. For your security, please log in again to c
|
|
|
1376
1438
|
status: I
|
|
1377
1439
|
};
|
|
1378
1440
|
}
|
|
1379
|
-
},
|
|
1441
|
+
}, Gr = async ({
|
|
1380
1442
|
username: e,
|
|
1381
1443
|
password: t,
|
|
1382
1444
|
clientId: r,
|
|
1383
1445
|
nonce: n,
|
|
1384
1446
|
type: a,
|
|
1385
|
-
sessionExpiration:
|
|
1386
|
-
code:
|
|
1447
|
+
sessionExpiration: s,
|
|
1448
|
+
code: o,
|
|
1387
1449
|
code_verifier: i,
|
|
1388
1450
|
domain: c,
|
|
1389
1451
|
ua: h
|
|
1390
1452
|
}) => {
|
|
1391
1453
|
try {
|
|
1392
|
-
const y = await
|
|
1393
|
-
type:
|
|
1454
|
+
const y = await pe({
|
|
1455
|
+
type: de.LOGIN,
|
|
1394
1456
|
clientId: r,
|
|
1395
1457
|
params: {
|
|
1396
|
-
type: a ||
|
|
1458
|
+
type: a || G.ID_AND_ACCESS_TOKEN,
|
|
1397
1459
|
username: e,
|
|
1398
1460
|
password: t,
|
|
1399
|
-
sessionExpiration:
|
|
1461
|
+
sessionExpiration: s,
|
|
1400
1462
|
nonce: n,
|
|
1401
|
-
code:
|
|
1463
|
+
code: o,
|
|
1402
1464
|
code_verifier: i,
|
|
1403
1465
|
domain: c,
|
|
1404
1466
|
ua: h
|
|
1405
1467
|
}
|
|
1406
|
-
}), p = await
|
|
1468
|
+
}), p = await V(y?.data?.idToken);
|
|
1407
1469
|
return p && p.payload[f.USER_ID_KEY] !== "" && p.payload[f.NONCE_KEY] === n ? {
|
|
1408
1470
|
idToken: y.data.idToken,
|
|
1409
1471
|
accessToken: y.data.accessToken,
|
|
@@ -1419,23 +1481,23 @@ const K = "Your session has expired. For your security, please log in again to c
|
|
|
1419
1481
|
status: !1
|
|
1420
1482
|
};
|
|
1421
1483
|
}
|
|
1422
|
-
},
|
|
1484
|
+
}, Mr = async ({
|
|
1423
1485
|
nonce: e,
|
|
1424
1486
|
clientId: t,
|
|
1425
1487
|
code_challenge: r
|
|
1426
1488
|
}) => {
|
|
1427
1489
|
try {
|
|
1428
|
-
const n = await
|
|
1429
|
-
type:
|
|
1490
|
+
const n = await pe({
|
|
1491
|
+
type: de.CODE,
|
|
1430
1492
|
clientId: t,
|
|
1431
1493
|
params: {
|
|
1432
|
-
type:
|
|
1494
|
+
type: G.CODE,
|
|
1433
1495
|
nonce: e,
|
|
1434
1496
|
code_challenge: r
|
|
1435
1497
|
}
|
|
1436
1498
|
});
|
|
1437
1499
|
return n?.data?.code ? {
|
|
1438
|
-
status:
|
|
1500
|
+
status: z,
|
|
1439
1501
|
data: n.data.code
|
|
1440
1502
|
} : {
|
|
1441
1503
|
status: I,
|
|
@@ -1447,30 +1509,30 @@ const K = "Your session has expired. For your security, please log in again to c
|
|
|
1447
1509
|
data: ""
|
|
1448
1510
|
};
|
|
1449
1511
|
}
|
|
1450
|
-
},
|
|
1512
|
+
}, Vr = async ({
|
|
1451
1513
|
clientId: e,
|
|
1452
1514
|
userId: t,
|
|
1453
1515
|
nonce: r,
|
|
1454
1516
|
refreshToken: n,
|
|
1455
1517
|
accessToken: a,
|
|
1456
|
-
domain:
|
|
1518
|
+
domain: s
|
|
1457
1519
|
}) => {
|
|
1458
1520
|
try {
|
|
1459
|
-
const
|
|
1460
|
-
type:
|
|
1521
|
+
const o = await pe({
|
|
1522
|
+
type: de.REFRESH,
|
|
1461
1523
|
clientId: e,
|
|
1462
1524
|
params: {
|
|
1463
|
-
type:
|
|
1525
|
+
type: G.REFRESH_TOKEN,
|
|
1464
1526
|
userId: t,
|
|
1465
1527
|
nonce: r,
|
|
1466
1528
|
refreshToken: n,
|
|
1467
1529
|
accessToken: a,
|
|
1468
|
-
domain:
|
|
1530
|
+
domain: s
|
|
1469
1531
|
}
|
|
1470
|
-
}), i = await
|
|
1532
|
+
}), i = await V(o?.data?.accessToken);
|
|
1471
1533
|
return i && i.payload[f.USER_ID_KEY] !== "" && i.payload[f.NONCE_KEY] === r ? {
|
|
1472
|
-
accessToken:
|
|
1473
|
-
refreshToken:
|
|
1534
|
+
accessToken: o.data.accessToken,
|
|
1535
|
+
refreshToken: o.data.refreshToken,
|
|
1474
1536
|
userId: i.payload[f.USER_ID_KEY],
|
|
1475
1537
|
status: !0
|
|
1476
1538
|
} : {
|
|
@@ -1482,11 +1544,11 @@ const K = "Your session has expired. For your security, please log in again to c
|
|
|
1482
1544
|
};
|
|
1483
1545
|
}
|
|
1484
1546
|
};
|
|
1485
|
-
class
|
|
1547
|
+
class jr {
|
|
1486
1548
|
constructor(t = null, r = null) {
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1549
|
+
X(this, "refreshTokenPromise", null);
|
|
1550
|
+
X(this, "accessToken");
|
|
1551
|
+
X(this, "refreshToken");
|
|
1490
1552
|
this.accessToken = t || "", this.refreshToken = r || "";
|
|
1491
1553
|
}
|
|
1492
1554
|
async refreshtoken({
|
|
@@ -1513,9 +1575,9 @@ class Wr {
|
|
|
1513
1575
|
nonce: n,
|
|
1514
1576
|
domain: a
|
|
1515
1577
|
}) {
|
|
1516
|
-
const
|
|
1517
|
-
if (
|
|
1518
|
-
const
|
|
1578
|
+
const s = await V(this.refreshToken);
|
|
1579
|
+
if (s && s.payload[f.USER_ID_KEY] !== "") {
|
|
1580
|
+
const o = await Vr({
|
|
1519
1581
|
clientId: t,
|
|
1520
1582
|
userId: r,
|
|
1521
1583
|
nonce: n,
|
|
@@ -1523,10 +1585,10 @@ class Wr {
|
|
|
1523
1585
|
accessToken: this.accessToken,
|
|
1524
1586
|
domain: a
|
|
1525
1587
|
});
|
|
1526
|
-
return
|
|
1527
|
-
status:
|
|
1528
|
-
newAccessToken:
|
|
1529
|
-
newRefreshToken:
|
|
1588
|
+
return o.status ? (this.accessToken = o.accessToken, this.refreshToken = o.refreshToken, {
|
|
1589
|
+
status: z,
|
|
1590
|
+
newAccessToken: o.accessToken,
|
|
1591
|
+
newRefreshToken: o.refreshToken
|
|
1530
1592
|
}) : {
|
|
1531
1593
|
status: I
|
|
1532
1594
|
};
|
|
@@ -1536,108 +1598,108 @@ class Wr {
|
|
|
1536
1598
|
};
|
|
1537
1599
|
}
|
|
1538
1600
|
}
|
|
1539
|
-
const
|
|
1601
|
+
const Fr = (e) => D(
|
|
1540
1602
|
(...t) => {
|
|
1541
1603
|
e && console.info(`==> [Auth ${Date.now()}]: `, ...t);
|
|
1542
1604
|
},
|
|
1543
1605
|
[e]
|
|
1544
|
-
),
|
|
1545
|
-
throw new Error(
|
|
1546
|
-
},
|
|
1606
|
+
), Y = () => {
|
|
1607
|
+
throw new Error(Wr);
|
|
1608
|
+
}, dt = _t({
|
|
1547
1609
|
isAuthenticated: !1,
|
|
1548
1610
|
isLoading: !1,
|
|
1549
|
-
login:
|
|
1550
|
-
logout:
|
|
1551
|
-
getAccessToken:
|
|
1552
|
-
getIdToken:
|
|
1553
|
-
registeringForPasskey:
|
|
1554
|
-
loginWithPasskey:
|
|
1611
|
+
login: Y,
|
|
1612
|
+
logout: Y,
|
|
1613
|
+
getAccessToken: Y,
|
|
1614
|
+
getIdToken: Y,
|
|
1615
|
+
registeringForPasskey: Y,
|
|
1616
|
+
loginWithPasskey: Y,
|
|
1555
1617
|
logoutReason: "",
|
|
1556
1618
|
authenticationType: ""
|
|
1557
|
-
}),
|
|
1558
|
-
state:
|
|
1619
|
+
}), Br = Rt.createContext({
|
|
1620
|
+
state: lt,
|
|
1559
1621
|
dispatch: () => {
|
|
1560
1622
|
}
|
|
1561
|
-
}),
|
|
1623
|
+
}), qr = (e, t) => t?.type === B ? {
|
|
1562
1624
|
...e,
|
|
1563
1625
|
isLoading: t.payload.isLoading
|
|
1564
|
-
} : t?.type ===
|
|
1626
|
+
} : t?.type === se ? {
|
|
1565
1627
|
...e,
|
|
1566
1628
|
isLoading: !1,
|
|
1567
1629
|
isAuthenticated: !0,
|
|
1568
1630
|
user: t.payload.user,
|
|
1569
1631
|
authenticationType: t.payload.authenticationType,
|
|
1570
1632
|
logoutReason: ""
|
|
1571
|
-
} : t?.type ===
|
|
1633
|
+
} : t?.type === ot ? {
|
|
1572
1634
|
...e,
|
|
1573
1635
|
isLoading: !1,
|
|
1574
1636
|
isAuthenticated: !1,
|
|
1575
1637
|
user: void 0,
|
|
1576
1638
|
authenticationType: "",
|
|
1577
1639
|
logoutReason: t.payload.logoutReason
|
|
1578
|
-
} : e,
|
|
1640
|
+
} : e, tn = ({
|
|
1579
1641
|
children: e,
|
|
1580
1642
|
sessionExpiration: t,
|
|
1581
1643
|
clientId: r,
|
|
1582
1644
|
domain: n = "",
|
|
1583
1645
|
debug: a = !1
|
|
1584
1646
|
}) => {
|
|
1585
|
-
const [
|
|
1586
|
-
...
|
|
1647
|
+
const [s, o] = It(qr, {
|
|
1648
|
+
...lt,
|
|
1587
1649
|
debug: a
|
|
1588
|
-
}), i =
|
|
1589
|
-
key: `${
|
|
1590
|
-
}), [l, A, , T] =
|
|
1591
|
-
key: `${
|
|
1592
|
-
}), [
|
|
1650
|
+
}), i = Fr(a), c = kt(!1), [h, y, , p] = re({
|
|
1651
|
+
key: `${ae}::${r}::@@user@@`
|
|
1652
|
+
}), [l, A, , T] = re({
|
|
1653
|
+
key: `${ae}::${r}::@@access@@`
|
|
1654
|
+
}), [ye, fe, , _e] = re(
|
|
1593
1655
|
{
|
|
1594
|
-
key: `${
|
|
1656
|
+
key: `${ae}::${r}::@@refresh@@`
|
|
1595
1657
|
}
|
|
1596
|
-
), [
|
|
1597
|
-
key: `${
|
|
1598
|
-
}),
|
|
1599
|
-
i("removeLocalStorage: removing local storage"), p(), T(),
|
|
1658
|
+
), [ht, Ie, , ke] = re({
|
|
1659
|
+
key: `${ae}::${r}::@@nonce@@`
|
|
1660
|
+
}), pt = new jr(l, ye), Q = D(() => {
|
|
1661
|
+
i("removeLocalStorage: removing local storage"), p(), T(), _e(), ke();
|
|
1600
1662
|
}, [
|
|
1601
1663
|
T,
|
|
1602
1664
|
p,
|
|
1665
|
+
ke,
|
|
1603
1666
|
_e,
|
|
1604
|
-
Te,
|
|
1605
1667
|
i
|
|
1606
|
-
]),
|
|
1668
|
+
]), F = D(
|
|
1607
1669
|
(u) => {
|
|
1608
1670
|
i(
|
|
1609
1671
|
"removeStateAndLocalStorage: removing state and local storage with reason: ",
|
|
1610
1672
|
u
|
|
1611
|
-
),
|
|
1612
|
-
type:
|
|
1673
|
+
), o({
|
|
1674
|
+
type: ot,
|
|
1613
1675
|
payload: {
|
|
1614
|
-
logoutReason: u ||
|
|
1676
|
+
logoutReason: u || L
|
|
1615
1677
|
}
|
|
1616
|
-
}),
|
|
1678
|
+
}), Q(), o({ type: B, payload: { isLoading: !1 } });
|
|
1617
1679
|
},
|
|
1618
|
-
[
|
|
1619
|
-
),
|
|
1680
|
+
[Q, i]
|
|
1681
|
+
), C = D(
|
|
1620
1682
|
async (u) => {
|
|
1621
1683
|
i("invalidateAndLogout: invalidating and logging out");
|
|
1622
|
-
const { user: g } =
|
|
1684
|
+
const { user: g } = s, d = g?.userId || Yr(h);
|
|
1623
1685
|
d || i(
|
|
1624
1686
|
"invalidateAndLogout: user cannot be identified, logging out without userId"
|
|
1625
|
-
), await
|
|
1687
|
+
), await xr({
|
|
1626
1688
|
userId: d,
|
|
1627
1689
|
clientId: r,
|
|
1628
1690
|
domain: n,
|
|
1629
1691
|
idToken: h
|
|
1630
|
-
}),
|
|
1692
|
+
}), F(u || L);
|
|
1631
1693
|
},
|
|
1632
|
-
[h,
|
|
1694
|
+
[h, s, r, n, F, i]
|
|
1633
1695
|
);
|
|
1634
|
-
|
|
1696
|
+
xe(() => {
|
|
1635
1697
|
if (!c.current)
|
|
1636
|
-
return
|
|
1698
|
+
return s.isLoading && h !== null ? (async () => {
|
|
1637
1699
|
try {
|
|
1638
|
-
const u = await
|
|
1639
|
-
u && u.payload[f.USER_ID_KEY] !== "" ? (i("useEffect: setting the authentication state"),
|
|
1640
|
-
type:
|
|
1700
|
+
const u = await V(h);
|
|
1701
|
+
u && u.payload[f.USER_ID_KEY] !== "" ? (i("useEffect: setting the authentication state"), o({
|
|
1702
|
+
type: se,
|
|
1641
1703
|
payload: {
|
|
1642
1704
|
authenticationType: u.payload[f.AUTH_TYPE_KEY],
|
|
1643
1705
|
user: {
|
|
@@ -1646,88 +1708,88 @@ const Yr = (e) => N(
|
|
|
1646
1708
|
email: u.payload[f.EMAIL_KEY]
|
|
1647
1709
|
}
|
|
1648
1710
|
}
|
|
1649
|
-
})) : (i("useEffect: invalid JWT, invalidating and logging out"), await
|
|
1711
|
+
})) : (i("useEffect: invalid JWT, invalidating and logging out"), await C(L));
|
|
1650
1712
|
} catch {
|
|
1651
1713
|
i(
|
|
1652
1714
|
"useEffect: exception validating JWT, invalidating and logging out"
|
|
1653
|
-
), await
|
|
1715
|
+
), await C(L);
|
|
1654
1716
|
}
|
|
1655
|
-
})() : (i("useEffect: setting the loading state to false"),
|
|
1717
|
+
})() : (i("useEffect: setting the loading state to false"), o({ type: B, payload: { isLoading: !1 } })), () => {
|
|
1656
1718
|
c.current = !0;
|
|
1657
1719
|
};
|
|
1658
|
-
}, [
|
|
1659
|
-
const
|
|
1660
|
-
|
|
1661
|
-
const d =
|
|
1662
|
-
|
|
1663
|
-
const { code_verifier:
|
|
1720
|
+
}, [s.isLoading, h, C, i]);
|
|
1721
|
+
const yt = async (u, g) => {
|
|
1722
|
+
o({ type: B, payload: { isLoading: !0 } }), Q();
|
|
1723
|
+
const d = Se();
|
|
1724
|
+
Ie(d), i("login: Logging in with password");
|
|
1725
|
+
const { code_verifier: N, code_challenge: St } = await Pr(), ve = await Mr({
|
|
1664
1726
|
nonce: d,
|
|
1665
1727
|
clientId: r,
|
|
1666
|
-
code_challenge:
|
|
1728
|
+
code_challenge: St
|
|
1667
1729
|
});
|
|
1668
|
-
if (
|
|
1669
|
-
const U = await
|
|
1730
|
+
if (ve.status) {
|
|
1731
|
+
const U = await Gr({
|
|
1670
1732
|
username: u,
|
|
1671
1733
|
password: g,
|
|
1672
1734
|
clientId: r,
|
|
1673
1735
|
sessionExpiration: t,
|
|
1674
1736
|
nonce: d,
|
|
1675
|
-
type:
|
|
1676
|
-
code:
|
|
1677
|
-
code_verifier:
|
|
1737
|
+
type: G.CODE,
|
|
1738
|
+
code: ve.data,
|
|
1739
|
+
code_verifier: N,
|
|
1678
1740
|
domain: n,
|
|
1679
1741
|
ua: navigator.userAgent
|
|
1680
1742
|
});
|
|
1681
|
-
return U.status ? (y(U.idToken), A(U.accessToken),
|
|
1682
|
-
type:
|
|
1743
|
+
return U.status ? (y(U.idToken), A(U.accessToken), fe(U.refreshToken), o({
|
|
1744
|
+
type: se,
|
|
1683
1745
|
payload: {
|
|
1684
|
-
authenticationType:
|
|
1746
|
+
authenticationType: G.CODE,
|
|
1685
1747
|
user: {
|
|
1686
1748
|
userId: U.userId,
|
|
1687
1749
|
username: u,
|
|
1688
1750
|
email: U.email
|
|
1689
1751
|
}
|
|
1690
1752
|
}
|
|
1691
|
-
}), !0) : (
|
|
1753
|
+
}), !0) : (F(Ae), !1);
|
|
1692
1754
|
}
|
|
1693
1755
|
return !1;
|
|
1694
|
-
},
|
|
1695
|
-
u?.preventDefault(), await
|
|
1696
|
-
},
|
|
1697
|
-
const { isAuthenticated: u, user: g } =
|
|
1756
|
+
}, ft = async (u) => {
|
|
1757
|
+
u?.preventDefault(), await C(Hr);
|
|
1758
|
+
}, gt = async () => {
|
|
1759
|
+
const { isAuthenticated: u, user: g } = s;
|
|
1698
1760
|
try {
|
|
1699
1761
|
if (u && g && g.userId) {
|
|
1700
1762
|
if (l) {
|
|
1701
1763
|
i("getAccessToken");
|
|
1702
|
-
const
|
|
1703
|
-
if (
|
|
1764
|
+
const N = await V(l);
|
|
1765
|
+
if (N && N.payload[f.USER_ID_KEY] !== "")
|
|
1704
1766
|
return l;
|
|
1705
1767
|
}
|
|
1706
1768
|
i("getAccessToken: invalid access token, trying to refresh it");
|
|
1707
|
-
const d = await
|
|
1769
|
+
const d = await pt.refreshtoken({
|
|
1708
1770
|
clientId: r,
|
|
1709
1771
|
userId: g.userId,
|
|
1710
|
-
nonce:
|
|
1772
|
+
nonce: ht,
|
|
1711
1773
|
domain: n
|
|
1712
1774
|
});
|
|
1713
|
-
return d.status && d.status === "success" && d.newAccessToken ? (A(d.newAccessToken),
|
|
1775
|
+
return d.status && d.status === "success" && d.newAccessToken ? (A(d.newAccessToken), fe(d.newRefreshToken), d.newAccessToken) : (i(
|
|
1714
1776
|
"getAccessToken: invalid refresh token, need to re-authenticate"
|
|
1715
|
-
), await
|
|
1777
|
+
), await C(L), "");
|
|
1716
1778
|
}
|
|
1717
1779
|
return i(
|
|
1718
1780
|
"getAccessToken: user is not authenticated, cannot get access token"
|
|
1719
|
-
), await
|
|
1781
|
+
), await C(L), "";
|
|
1720
1782
|
} catch {
|
|
1721
1783
|
return i(
|
|
1722
1784
|
"getAccessToken: exception occurred, invalidating and logging out"
|
|
1723
|
-
), await
|
|
1785
|
+
), await C(Lr), "";
|
|
1724
1786
|
}
|
|
1725
|
-
},
|
|
1726
|
-
const { user: u } =
|
|
1727
|
-
let g = await
|
|
1787
|
+
}, Et = () => s.isAuthenticated && h ? h : "", mt = async () => {
|
|
1788
|
+
const { user: u } = s;
|
|
1789
|
+
let g = await J({
|
|
1728
1790
|
accessToken: l,
|
|
1729
1791
|
clientId: r,
|
|
1730
|
-
type:
|
|
1792
|
+
type: W.GET_REGISTRATION_OPTIONS,
|
|
1731
1793
|
params: {
|
|
1732
1794
|
clientId: r,
|
|
1733
1795
|
id: u?.userId,
|
|
@@ -1736,11 +1798,11 @@ const Yr = (e) => N(
|
|
|
1736
1798
|
});
|
|
1737
1799
|
if (g.status)
|
|
1738
1800
|
try {
|
|
1739
|
-
const d = await
|
|
1740
|
-
return g = await
|
|
1801
|
+
const d = await Nt(g.data);
|
|
1802
|
+
return g = await J({
|
|
1741
1803
|
accessToken: l,
|
|
1742
1804
|
clientId: r,
|
|
1743
|
-
type:
|
|
1805
|
+
type: W.VERIFY_REGISTRATION,
|
|
1744
1806
|
params: {
|
|
1745
1807
|
clientId: r,
|
|
1746
1808
|
id: u?.userId,
|
|
@@ -1749,10 +1811,10 @@ const Yr = (e) => N(
|
|
|
1749
1811
|
}
|
|
1750
1812
|
}), !!(g.status && g.data.length > 0);
|
|
1751
1813
|
} catch {
|
|
1752
|
-
return await
|
|
1814
|
+
return await J({
|
|
1753
1815
|
accessToken: l,
|
|
1754
1816
|
clientId: r,
|
|
1755
|
-
type:
|
|
1817
|
+
type: W.VERIFY_REGISTRATION,
|
|
1756
1818
|
params: {
|
|
1757
1819
|
clientId: r,
|
|
1758
1820
|
id: u?.userId,
|
|
@@ -1762,15 +1824,15 @@ const Yr = (e) => N(
|
|
|
1762
1824
|
}), !1;
|
|
1763
1825
|
}
|
|
1764
1826
|
return !1;
|
|
1765
|
-
},
|
|
1766
|
-
|
|
1767
|
-
const u =
|
|
1768
|
-
|
|
1769
|
-
const g =
|
|
1770
|
-
let d = await
|
|
1827
|
+
}, wt = async () => {
|
|
1828
|
+
o({ type: B, payload: { isLoading: !0 } }), Q();
|
|
1829
|
+
const u = Se();
|
|
1830
|
+
Ie(u), i("loginWithPasskey");
|
|
1831
|
+
const g = Se();
|
|
1832
|
+
let d = await J({
|
|
1771
1833
|
accessToken: l,
|
|
1772
1834
|
clientId: r,
|
|
1773
|
-
type:
|
|
1835
|
+
type: W.GET_AUTHENTICATION_OPTIONS,
|
|
1774
1836
|
params: {
|
|
1775
1837
|
id: g,
|
|
1776
1838
|
clientId: r
|
|
@@ -1778,36 +1840,36 @@ const Yr = (e) => N(
|
|
|
1778
1840
|
});
|
|
1779
1841
|
if (d.status)
|
|
1780
1842
|
try {
|
|
1781
|
-
const
|
|
1782
|
-
return d = await
|
|
1843
|
+
const N = await Ut(d.data);
|
|
1844
|
+
return d = await J({
|
|
1783
1845
|
accessToken: l,
|
|
1784
1846
|
clientId: r,
|
|
1785
|
-
type:
|
|
1847
|
+
type: W.VERIFY_AUTHENTICATION,
|
|
1786
1848
|
params: {
|
|
1787
1849
|
clientId: r,
|
|
1788
1850
|
id: g,
|
|
1789
|
-
authentication:
|
|
1851
|
+
authentication: N,
|
|
1790
1852
|
nonce: u,
|
|
1791
1853
|
domain: n,
|
|
1792
1854
|
sessionExpiration: t,
|
|
1793
1855
|
ua: navigator.userAgent
|
|
1794
1856
|
}
|
|
1795
|
-
}), d.data.status ===
|
|
1796
|
-
type:
|
|
1857
|
+
}), d.data.status === z ? (y(d.data.idToken), A(d.data.accessToken), fe(d.data.refreshToken), o({
|
|
1858
|
+
type: se,
|
|
1797
1859
|
payload: {
|
|
1798
|
-
authenticationType:
|
|
1860
|
+
authenticationType: G.PASSKEY,
|
|
1799
1861
|
user: {
|
|
1800
1862
|
userId: d.data.userId,
|
|
1801
1863
|
username: d.data.username,
|
|
1802
1864
|
email: d.data.email
|
|
1803
1865
|
}
|
|
1804
1866
|
}
|
|
1805
|
-
}), !0) : (
|
|
1867
|
+
}), !0) : (F(Ae), !1);
|
|
1806
1868
|
} catch {
|
|
1807
|
-
return await
|
|
1869
|
+
return await J({
|
|
1808
1870
|
accessToken: l,
|
|
1809
1871
|
clientId: r,
|
|
1810
|
-
type:
|
|
1872
|
+
type: W.VERIFY_AUTHENTICATION,
|
|
1811
1873
|
params: {
|
|
1812
1874
|
clientId: r,
|
|
1813
1875
|
id: g,
|
|
@@ -1816,29 +1878,29 @@ const Yr = (e) => N(
|
|
|
1816
1878
|
domain: n,
|
|
1817
1879
|
sessionExpiration: t
|
|
1818
1880
|
}
|
|
1819
|
-
}),
|
|
1881
|
+
}), F(Ae), !1;
|
|
1820
1882
|
}
|
|
1821
1883
|
return !1;
|
|
1822
1884
|
};
|
|
1823
|
-
return /* @__PURE__ */
|
|
1824
|
-
|
|
1885
|
+
return /* @__PURE__ */ Oe(Br.Provider, { value: { state: s, dispatch: o }, children: /* @__PURE__ */ Oe(
|
|
1886
|
+
dt.Provider,
|
|
1825
1887
|
{
|
|
1826
1888
|
value: {
|
|
1827
|
-
...
|
|
1828
|
-
login:
|
|
1829
|
-
logout:
|
|
1830
|
-
getAccessToken:
|
|
1831
|
-
getIdToken:
|
|
1832
|
-
registeringForPasskey:
|
|
1833
|
-
loginWithPasskey:
|
|
1889
|
+
...s,
|
|
1890
|
+
login: yt,
|
|
1891
|
+
logout: ft,
|
|
1892
|
+
getAccessToken: gt,
|
|
1893
|
+
getIdToken: Et,
|
|
1894
|
+
registeringForPasskey: mt,
|
|
1895
|
+
loginWithPasskey: wt
|
|
1834
1896
|
},
|
|
1835
1897
|
children: e
|
|
1836
1898
|
}
|
|
1837
1899
|
) });
|
|
1838
|
-
},
|
|
1900
|
+
}, rn = (e = dt) => vt(e);
|
|
1839
1901
|
export {
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1902
|
+
G as AUTH_TYPES,
|
|
1903
|
+
tn as AuthProvider,
|
|
1904
|
+
en as isGranted,
|
|
1905
|
+
rn as useAuth
|
|
1844
1906
|
};
|