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