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