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