@versini/auth-common 4.6.0 → 4.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +225 -213
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
@versini/auth-common v4.6.
|
|
2
|
+
@versini/auth-common v4.6.1
|
|
3
3
|
© 2025 gizmette.com
|
|
4
4
|
*/
|
|
5
5
|
try {
|
|
6
6
|
window.__VERSINI_AUTH_COMMON__ || (window.__VERSINI_AUTH_COMMON__ = {
|
|
7
|
-
version: "4.6.
|
|
8
|
-
buildTime: "11/
|
|
7
|
+
version: "4.6.1",
|
|
8
|
+
buildTime: "11/29/2025 08:06 PM EST",
|
|
9
9
|
homepage: "https://github.com/aversini/auth-client",
|
|
10
10
|
license: "MIT"
|
|
11
11
|
});
|
|
12
12
|
} catch {
|
|
13
13
|
}
|
|
14
|
-
const
|
|
14
|
+
const st = {
|
|
15
15
|
ID_TOKEN: "id_token",
|
|
16
16
|
ACCESS_TOKEN: "token",
|
|
17
17
|
ID_AND_ACCESS_TOKEN: "id_token token",
|
|
@@ -20,10 +20,10 @@ const it = {
|
|
|
20
20
|
PASSKEY: "passkey",
|
|
21
21
|
AUTH0: "auth0",
|
|
22
22
|
GOOGLE: "google"
|
|
23
|
-
},
|
|
23
|
+
}, ct = {
|
|
24
24
|
CLIENT_ID: "X-Auth-ClientId",
|
|
25
25
|
AUTH_TYPE: "X-Auth-Type"
|
|
26
|
-
},
|
|
26
|
+
}, oe = {
|
|
27
27
|
ACCESS_TOKEN: "access_token"
|
|
28
28
|
}, y = {
|
|
29
29
|
ALG: "RS256",
|
|
@@ -39,7 +39,7 @@ const it = {
|
|
|
39
39
|
SCOPE_KEY: "scope",
|
|
40
40
|
CLIENT_ID_KEY: "aud",
|
|
41
41
|
ISSUER: "gizmette.com"
|
|
42
|
-
},
|
|
42
|
+
}, ie = `-----BEGIN PUBLIC KEY-----
|
|
43
43
|
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAsF6i3Jd9fY/3COqCw/m7
|
|
44
44
|
w5PKyTYLGAI2I6SIIdpe6i6DOCbEkmDz7LdVsBqwNtVi8gvWYIj+8ol6rU3qu1v5
|
|
45
45
|
i1Jd45GSK4kzkVdgCmQZbM5ak0KI99q5wsrAIzUd+LRJ2HRvWtr5IYdsIiXaQjle
|
|
@@ -47,24 +47,34 @@ aMwPFOIcJH+rKfFgNcHLcaS5syp7zU1ANwZ+trgR+DifBr8TLVkBynmNeTyhDm2+
|
|
|
47
47
|
l0haqjMk0UoNPPE8iYBWUHQJJE1Dqstj65d6Eh5g64Pao25y4cmYJbKjiblIGEkE
|
|
48
48
|
sjqybA9mARAqh9k/eiIopecWSiffNQTwVQVd2I9ZH3BalhEXHlqFgrjz51kFqg81
|
|
49
49
|
awIDAQAB
|
|
50
|
-
-----END PUBLIC KEY-----`,
|
|
50
|
+
-----END PUBLIC KEY-----`, dt = {
|
|
51
51
|
ACCESS: "5m",
|
|
52
52
|
ID: "90d",
|
|
53
53
|
REFRESH: "90d"
|
|
54
|
-
},
|
|
54
|
+
}, ut = {
|
|
55
55
|
CODE: "code",
|
|
56
56
|
LOGOUT: "logout",
|
|
57
57
|
LOGIN: "login",
|
|
58
58
|
REFRESH: "refresh",
|
|
59
59
|
GOOGLE: "google"
|
|
60
|
-
},
|
|
61
|
-
function
|
|
60
|
+
}, N = new TextEncoder(), T = new TextDecoder();
|
|
61
|
+
function se(...e) {
|
|
62
62
|
const t = e.reduce((a, { length: o }) => a + o, 0), r = new Uint8Array(t);
|
|
63
63
|
let n = 0;
|
|
64
64
|
for (const a of e)
|
|
65
65
|
r.set(a, n), n += a.length;
|
|
66
66
|
return r;
|
|
67
67
|
}
|
|
68
|
+
function D(e) {
|
|
69
|
+
const t = new Uint8Array(e.length);
|
|
70
|
+
for (let r = 0; r < e.length; r++) {
|
|
71
|
+
const n = e.charCodeAt(r);
|
|
72
|
+
if (n > 127)
|
|
73
|
+
throw new TypeError("non-ASCII string encountered in encode()");
|
|
74
|
+
t[r] = n;
|
|
75
|
+
}
|
|
76
|
+
return t;
|
|
77
|
+
}
|
|
68
78
|
function G(e) {
|
|
69
79
|
if (Uint8Array.fromBase64)
|
|
70
80
|
return Uint8Array.fromBase64(e);
|
|
@@ -73,13 +83,13 @@ function G(e) {
|
|
|
73
83
|
r[n] = t.charCodeAt(n);
|
|
74
84
|
return r;
|
|
75
85
|
}
|
|
76
|
-
function
|
|
86
|
+
function v(e) {
|
|
77
87
|
if (Uint8Array.fromBase64)
|
|
78
|
-
return Uint8Array.fromBase64(typeof e == "string" ? e :
|
|
88
|
+
return Uint8Array.fromBase64(typeof e == "string" ? e : T.decode(e), {
|
|
79
89
|
alphabet: "base64url"
|
|
80
90
|
});
|
|
81
91
|
let t = e;
|
|
82
|
-
t instanceof Uint8Array && (t =
|
|
92
|
+
t instanceof Uint8Array && (t = T.decode(t)), t = t.replace(/-/g, "+").replace(/_/g, "/");
|
|
83
93
|
try {
|
|
84
94
|
return G(t);
|
|
85
95
|
} catch {
|
|
@@ -103,7 +113,7 @@ class p extends A {
|
|
|
103
113
|
super(t, { cause: { claim: n, reason: a, payload: r } }), this.claim = n, this.reason = a, this.payload = r;
|
|
104
114
|
}
|
|
105
115
|
}
|
|
106
|
-
class
|
|
116
|
+
class M extends A {
|
|
107
117
|
static code = "ERR_JWT_EXPIRED";
|
|
108
118
|
code = "ERR_JWT_EXPIRED";
|
|
109
119
|
claim;
|
|
@@ -113,7 +123,7 @@ class U extends A {
|
|
|
113
123
|
super(t, { cause: { claim: n, reason: a, payload: r } }), this.claim = n, this.reason = a, this.payload = r;
|
|
114
124
|
}
|
|
115
125
|
}
|
|
116
|
-
class
|
|
126
|
+
class ce extends A {
|
|
117
127
|
static code = "ERR_JOSE_ALG_NOT_ALLOWED";
|
|
118
128
|
code = "ERR_JOSE_ALG_NOT_ALLOWED";
|
|
119
129
|
}
|
|
@@ -129,23 +139,18 @@ class S extends A {
|
|
|
129
139
|
static code = "ERR_JWT_INVALID";
|
|
130
140
|
code = "ERR_JWT_INVALID";
|
|
131
141
|
}
|
|
132
|
-
class
|
|
142
|
+
class de extends A {
|
|
133
143
|
static code = "ERR_JWS_SIGNATURE_VERIFICATION_FAILED";
|
|
134
144
|
code = "ERR_JWS_SIGNATURE_VERIFICATION_FAILED";
|
|
135
145
|
constructor(t = "signature verification failed", r) {
|
|
136
146
|
super(t, r);
|
|
137
147
|
}
|
|
138
148
|
}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
}
|
|
142
|
-
function b(e, t) {
|
|
143
|
-
return e.name === t;
|
|
144
|
-
}
|
|
145
|
-
function W(e) {
|
|
149
|
+
const h = (e, t = "algorithm.name") => new TypeError(`CryptoKey does not support this operation, its ${t} must be ${e}`), b = (e, t) => e.name === t;
|
|
150
|
+
function x(e) {
|
|
146
151
|
return parseInt(e.name.slice(4), 10);
|
|
147
152
|
}
|
|
148
|
-
function
|
|
153
|
+
function ue(e) {
|
|
149
154
|
switch (e) {
|
|
150
155
|
case "ES256":
|
|
151
156
|
return "P-256";
|
|
@@ -157,11 +162,11 @@ function de(e) {
|
|
|
157
162
|
throw new Error("unreachable");
|
|
158
163
|
}
|
|
159
164
|
}
|
|
160
|
-
function
|
|
165
|
+
function fe(e, t) {
|
|
161
166
|
if (!e.usages.includes(t))
|
|
162
167
|
throw new TypeError(`CryptoKey does not support this operation, its usages must include ${t}.`);
|
|
163
168
|
}
|
|
164
|
-
function
|
|
169
|
+
function le(e, t, r) {
|
|
165
170
|
switch (t) {
|
|
166
171
|
case "HS256":
|
|
167
172
|
case "HS384":
|
|
@@ -169,7 +174,7 @@ function fe(e, t, r) {
|
|
|
169
174
|
if (!b(e.algorithm, "HMAC"))
|
|
170
175
|
throw h("HMAC");
|
|
171
176
|
const n = parseInt(t.slice(2), 10);
|
|
172
|
-
if (
|
|
177
|
+
if (x(e.algorithm.hash) !== n)
|
|
173
178
|
throw h(`SHA-${n}`, "algorithm.hash");
|
|
174
179
|
break;
|
|
175
180
|
}
|
|
@@ -179,7 +184,7 @@ function fe(e, t, r) {
|
|
|
179
184
|
if (!b(e.algorithm, "RSASSA-PKCS1-v1_5"))
|
|
180
185
|
throw h("RSASSA-PKCS1-v1_5");
|
|
181
186
|
const n = parseInt(t.slice(2), 10);
|
|
182
|
-
if (
|
|
187
|
+
if (x(e.algorithm.hash) !== n)
|
|
183
188
|
throw h(`SHA-${n}`, "algorithm.hash");
|
|
184
189
|
break;
|
|
185
190
|
}
|
|
@@ -189,7 +194,7 @@ function fe(e, t, r) {
|
|
|
189
194
|
if (!b(e.algorithm, "RSA-PSS"))
|
|
190
195
|
throw h("RSA-PSS");
|
|
191
196
|
const n = parseInt(t.slice(2), 10);
|
|
192
|
-
if (
|
|
197
|
+
if (x(e.algorithm.hash) !== n)
|
|
193
198
|
throw h(`SHA-${n}`, "algorithm.hash");
|
|
194
199
|
break;
|
|
195
200
|
}
|
|
@@ -211,7 +216,7 @@ function fe(e, t, r) {
|
|
|
211
216
|
case "ES512": {
|
|
212
217
|
if (!b(e.algorithm, "ECDSA"))
|
|
213
218
|
throw h("ECDSA");
|
|
214
|
-
const n =
|
|
219
|
+
const n = ue(t);
|
|
215
220
|
if (e.algorithm.namedCurve !== n)
|
|
216
221
|
throw h(n, "algorithm.namedCurve");
|
|
217
222
|
break;
|
|
@@ -219,26 +224,25 @@ function fe(e, t, r) {
|
|
|
219
224
|
default:
|
|
220
225
|
throw new TypeError("CryptoKey does not support this operation");
|
|
221
226
|
}
|
|
222
|
-
|
|
227
|
+
fe(e, r);
|
|
223
228
|
}
|
|
224
|
-
function
|
|
229
|
+
function q(e, t, ...r) {
|
|
225
230
|
if (r = r.filter(Boolean), r.length > 2) {
|
|
226
231
|
const n = r.pop();
|
|
227
232
|
e += `one of type ${r.join(", ")}, or ${n}.`;
|
|
228
233
|
} else r.length === 2 ? e += `one of type ${r[0]} or ${r[1]}.` : e += `of type ${r[0]}.`;
|
|
229
234
|
return t == null ? e += ` Received ${t}` : typeof t == "function" && t.name ? e += ` Received function ${t.name}` : typeof t == "object" && t != null && t.constructor?.name && (e += ` Received an instance of ${t.constructor.name}`), e;
|
|
230
235
|
}
|
|
231
|
-
const
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
const Q = (e) => z(e) || X(e), pe = (...e) => {
|
|
236
|
+
const pe = (e, ...t) => q("Key must be ", e, ...t), z = (e, t, ...r) => q(`Key for the ${e} algorithm must be `, t, ...r), X = (e) => {
|
|
237
|
+
if (e?.[Symbol.toStringTag] === "CryptoKey")
|
|
238
|
+
return !0;
|
|
239
|
+
try {
|
|
240
|
+
return e instanceof CryptoKey;
|
|
241
|
+
} catch {
|
|
242
|
+
return !1;
|
|
243
|
+
}
|
|
244
|
+
}, Q = (e) => e?.[Symbol.toStringTag] === "KeyObject", Z = (e) => X(e) || Q(e);
|
|
245
|
+
function he(...e) {
|
|
242
246
|
const t = e.filter(Boolean);
|
|
243
247
|
if (t.length === 0 || t.length === 1)
|
|
244
248
|
return !0;
|
|
@@ -256,12 +260,10 @@ const Q = (e) => z(e) || X(e), pe = (...e) => {
|
|
|
256
260
|
}
|
|
257
261
|
}
|
|
258
262
|
return !0;
|
|
259
|
-
};
|
|
260
|
-
function he(e) {
|
|
261
|
-
return typeof e == "object" && e !== null;
|
|
262
263
|
}
|
|
263
|
-
const
|
|
264
|
-
|
|
264
|
+
const ye = (e) => typeof e == "object" && e !== null;
|
|
265
|
+
function P(e) {
|
|
266
|
+
if (!ye(e) || Object.prototype.toString.call(e) !== "[object Object]")
|
|
265
267
|
return !1;
|
|
266
268
|
if (Object.getPrototypeOf(e) === null)
|
|
267
269
|
return !0;
|
|
@@ -269,20 +271,22 @@ const P = (e) => {
|
|
|
269
271
|
for (; Object.getPrototypeOf(t) !== null; )
|
|
270
272
|
t = Object.getPrototypeOf(t);
|
|
271
273
|
return Object.getPrototypeOf(e) === t;
|
|
272
|
-
}
|
|
274
|
+
}
|
|
275
|
+
function me(e, t) {
|
|
273
276
|
if (e.startsWith("RS") || e.startsWith("PS")) {
|
|
274
277
|
const { modulusLength: r } = t.algorithm;
|
|
275
278
|
if (typeof r != "number" || r < 2048)
|
|
276
279
|
throw new TypeError(`${e} requires key modulusLength to be 2048 bits or larger`);
|
|
277
280
|
}
|
|
278
|
-
}
|
|
281
|
+
}
|
|
282
|
+
const W = (e, t) => {
|
|
279
283
|
if (e.byteLength !== t.length)
|
|
280
284
|
return !1;
|
|
281
285
|
for (let r = 0; r < e.byteLength; r++)
|
|
282
286
|
if (e[r] !== t[r])
|
|
283
287
|
return !1;
|
|
284
288
|
return !0;
|
|
285
|
-
},
|
|
289
|
+
}, Se = (e) => ({ data: e, pos: 0 }), R = (e) => {
|
|
286
290
|
const t = e.data[e.pos++];
|
|
287
291
|
if (t & 128) {
|
|
288
292
|
const r = t & 127;
|
|
@@ -292,39 +296,39 @@ const P = (e) => {
|
|
|
292
296
|
return n;
|
|
293
297
|
}
|
|
294
298
|
return t;
|
|
295
|
-
},
|
|
299
|
+
}, O = (e, t, r) => {
|
|
296
300
|
if (e.data[e.pos++] !== t)
|
|
297
301
|
throw new Error(r);
|
|
298
|
-
},
|
|
302
|
+
}, j = (e, t) => {
|
|
299
303
|
const r = e.data.subarray(e.pos, e.pos + t);
|
|
300
304
|
return e.pos += t, r;
|
|
301
|
-
},
|
|
302
|
-
|
|
303
|
-
const t =
|
|
304
|
-
return
|
|
305
|
+
}, Ee = (e) => {
|
|
306
|
+
O(e, 6, "Expected algorithm OID");
|
|
307
|
+
const t = R(e);
|
|
308
|
+
return j(e, t);
|
|
305
309
|
};
|
|
306
|
-
function
|
|
307
|
-
|
|
308
|
-
const t =
|
|
310
|
+
function we(e) {
|
|
311
|
+
O(e, 48, "Invalid SPKI structure"), R(e), O(e, 48, "Expected algorithm identifier");
|
|
312
|
+
const t = R(e);
|
|
309
313
|
return { algIdStart: e.pos, algIdLength: t };
|
|
310
314
|
}
|
|
311
|
-
const
|
|
312
|
-
const t =
|
|
313
|
-
if (
|
|
315
|
+
const Ae = (e) => {
|
|
316
|
+
const t = Ee(e);
|
|
317
|
+
if (W(t, [43, 101, 110]))
|
|
314
318
|
return "X25519";
|
|
315
|
-
if (!
|
|
319
|
+
if (!W(t, [42, 134, 72, 206, 61, 2, 1]))
|
|
316
320
|
throw new Error("Unsupported key algorithm");
|
|
317
|
-
|
|
318
|
-
const r =
|
|
321
|
+
O(e, 6, "Expected curve OID");
|
|
322
|
+
const r = R(e), n = j(e, r);
|
|
319
323
|
for (const { name: a, oid: o } of [
|
|
320
324
|
{ name: "P-256", oid: [42, 134, 72, 206, 61, 3, 1, 7] },
|
|
321
325
|
{ name: "P-384", oid: [43, 129, 4, 0, 34] },
|
|
322
326
|
{ name: "P-521", oid: [43, 129, 4, 0, 35] }
|
|
323
327
|
])
|
|
324
|
-
if (
|
|
328
|
+
if (W(n, o))
|
|
325
329
|
return a;
|
|
326
330
|
throw new Error("Unsupported named curve");
|
|
327
|
-
},
|
|
331
|
+
}, ge = async (e, t, r, n) => {
|
|
328
332
|
let a, o;
|
|
329
333
|
const i = () => ["verify"], s = () => ["encrypt", "wrapKey"];
|
|
330
334
|
switch (r) {
|
|
@@ -379,15 +383,15 @@ const we = (e) => {
|
|
|
379
383
|
throw new E('Invalid or unsupported "alg" (Algorithm) value');
|
|
380
384
|
}
|
|
381
385
|
return crypto.subtle.importKey(e, t, a, n?.extractable ?? !0, o);
|
|
382
|
-
},
|
|
383
|
-
const n =
|
|
386
|
+
}, be = (e, t) => G(e.replace(t, "")), Ce = (e, t, r) => {
|
|
387
|
+
const n = be(e, /(?:-----(?:BEGIN|END) PUBLIC KEY-----|\s)/g);
|
|
384
388
|
let a = r;
|
|
385
389
|
return t?.startsWith?.("ECDH-ES") && (a ||= {}, a.getNamedCurve = (o) => {
|
|
386
|
-
const i =
|
|
387
|
-
return
|
|
388
|
-
}),
|
|
390
|
+
const i = Se(o);
|
|
391
|
+
return we(i), Ae(i);
|
|
392
|
+
}), ge("spki", n, t, a);
|
|
389
393
|
};
|
|
390
|
-
function
|
|
394
|
+
function Ke(e) {
|
|
391
395
|
let t, r;
|
|
392
396
|
switch (e.kty) {
|
|
393
397
|
case "AKP": {
|
|
@@ -472,18 +476,18 @@ function Ce(e) {
|
|
|
472
476
|
}
|
|
473
477
|
return { algorithm: t, keyUsages: r };
|
|
474
478
|
}
|
|
475
|
-
|
|
479
|
+
async function Te(e) {
|
|
476
480
|
if (!e.alg)
|
|
477
481
|
throw new TypeError('"alg" argument is required when "jwk.alg" is not present');
|
|
478
|
-
const { algorithm: t, keyUsages: r } =
|
|
482
|
+
const { algorithm: t, keyUsages: r } = Ke(e), n = { ...e };
|
|
479
483
|
return n.kty !== "AKP" && delete n.alg, delete n.use, crypto.subtle.importKey("jwk", n, t, e.ext ?? !(e.d || e.priv), e.key_ops ?? r);
|
|
480
|
-
}
|
|
484
|
+
}
|
|
481
485
|
async function ve(e, t, r) {
|
|
482
486
|
if (e.indexOf("-----BEGIN PUBLIC KEY-----") !== 0)
|
|
483
487
|
throw new TypeError('"spki" must be SPKI formatted string');
|
|
484
|
-
return
|
|
488
|
+
return Ce(e, t, r);
|
|
485
489
|
}
|
|
486
|
-
|
|
490
|
+
function Pe(e, t, r, n, a) {
|
|
487
491
|
if (a.crit !== void 0 && n?.crit === void 0)
|
|
488
492
|
throw new e('"crit" (Critical) Header Parameter MUST be integrity protected');
|
|
489
493
|
if (!n || n.crit === void 0)
|
|
@@ -501,33 +505,23 @@ const Te = (e, t, r, n, a) => {
|
|
|
501
505
|
throw new e(`Extension Header Parameter "${i}" MUST be integrity protected`);
|
|
502
506
|
}
|
|
503
507
|
return new Set(n.crit);
|
|
504
|
-
}
|
|
508
|
+
}
|
|
509
|
+
function _e(e, t) {
|
|
505
510
|
if (t !== void 0 && (!Array.isArray(t) || t.some((r) => typeof r != "string")))
|
|
506
511
|
throw new TypeError(`"${e}" option must be an array of strings`);
|
|
507
512
|
if (t)
|
|
508
513
|
return new Set(t);
|
|
509
|
-
};
|
|
510
|
-
function L(e) {
|
|
511
|
-
return P(e) && typeof e.kty == "string";
|
|
512
|
-
}
|
|
513
|
-
function _e(e) {
|
|
514
|
-
return e.kty !== "oct" && (e.kty === "AKP" && typeof e.priv == "string" || typeof e.d == "string");
|
|
515
|
-
}
|
|
516
|
-
function Ie(e) {
|
|
517
|
-
return e.kty !== "oct" && typeof e.d > "u" && typeof e.priv > "u";
|
|
518
|
-
}
|
|
519
|
-
function Re(e) {
|
|
520
|
-
return e.kty === "oct" && typeof e.k == "string";
|
|
521
514
|
}
|
|
515
|
+
const L = (e) => P(e) && typeof e.kty == "string", Ie = (e) => e.kty !== "oct" && (e.kty === "AKP" && typeof e.priv == "string" || typeof e.d == "string"), Re = (e) => e.kty !== "oct" && e.d === void 0 && e.priv === void 0, Oe = (e) => e.kty === "oct" && typeof e.k == "string";
|
|
522
516
|
let K;
|
|
523
|
-
const
|
|
517
|
+
const $ = async (e, t, r, n = !1) => {
|
|
524
518
|
K ||= /* @__PURE__ */ new WeakMap();
|
|
525
519
|
let a = K.get(e);
|
|
526
520
|
if (a?.[r])
|
|
527
521
|
return a[r];
|
|
528
|
-
const o = await
|
|
522
|
+
const o = await Te({ ...t, alg: r });
|
|
529
523
|
return n && Object.freeze(e), a ? a[r] = o : K.set(e, { [r]: o }), o;
|
|
530
|
-
},
|
|
524
|
+
}, De = (e, t) => {
|
|
531
525
|
K ||= /* @__PURE__ */ new WeakMap();
|
|
532
526
|
let r = K.get(e);
|
|
533
527
|
if (r?.[t])
|
|
@@ -623,26 +617,28 @@ const M = async (e, t, r, n = !1) => {
|
|
|
623
617
|
if (!o)
|
|
624
618
|
throw new TypeError("given KeyObject instance cannot be used for this algorithm");
|
|
625
619
|
return r ? r[t] = o : K.set(e, { [t]: o }), o;
|
|
626
|
-
}
|
|
627
|
-
|
|
620
|
+
};
|
|
621
|
+
async function xe(e, t) {
|
|
622
|
+
if (e instanceof Uint8Array || X(e))
|
|
628
623
|
return e;
|
|
629
|
-
if (
|
|
624
|
+
if (Q(e)) {
|
|
630
625
|
if (e.type === "secret")
|
|
631
626
|
return e.export();
|
|
632
627
|
if ("toCryptoKey" in e && typeof e.toCryptoKey == "function")
|
|
633
628
|
try {
|
|
634
|
-
return
|
|
629
|
+
return De(e, t);
|
|
635
630
|
} catch (n) {
|
|
636
631
|
if (n instanceof TypeError)
|
|
637
632
|
throw n;
|
|
638
633
|
}
|
|
639
634
|
let r = e.export({ format: "jwk" });
|
|
640
|
-
return
|
|
635
|
+
return $(e, r, t);
|
|
641
636
|
}
|
|
642
637
|
if (L(e))
|
|
643
|
-
return e.k ?
|
|
638
|
+
return e.k ? v(e.k) : $(e, e, t, !0);
|
|
644
639
|
throw new Error("unreachable");
|
|
645
|
-
}
|
|
640
|
+
}
|
|
641
|
+
const C = (e) => e?.[Symbol.toStringTag], J = (e, t, r) => {
|
|
646
642
|
if (t.use !== void 0) {
|
|
647
643
|
let n;
|
|
648
644
|
switch (r) {
|
|
@@ -688,31 +684,31 @@ const M = async (e, t, r, n = !1) => {
|
|
|
688
684
|
}, We = (e, t, r) => {
|
|
689
685
|
if (!(t instanceof Uint8Array)) {
|
|
690
686
|
if (L(t)) {
|
|
691
|
-
if (
|
|
687
|
+
if (Oe(t) && J(e, t, r))
|
|
692
688
|
return;
|
|
693
689
|
throw new TypeError('JSON Web Key for symmetric algorithms must have JWK "kty" (Key Type) equal to "oct" and the JWK "k" (Key Value) present');
|
|
694
690
|
}
|
|
695
|
-
if (!
|
|
696
|
-
throw new TypeError(
|
|
691
|
+
if (!Z(t))
|
|
692
|
+
throw new TypeError(z(e, t, "CryptoKey", "KeyObject", "JSON Web Key", "Uint8Array"));
|
|
697
693
|
if (t.type !== "secret")
|
|
698
694
|
throw new TypeError(`${C(t)} instances for symmetric algorithms must be of type "secret"`);
|
|
699
695
|
}
|
|
700
|
-
},
|
|
696
|
+
}, He = (e, t, r) => {
|
|
701
697
|
if (L(t))
|
|
702
698
|
switch (r) {
|
|
703
699
|
case "decrypt":
|
|
704
700
|
case "sign":
|
|
705
|
-
if (
|
|
701
|
+
if (Ie(t) && J(e, t, r))
|
|
706
702
|
return;
|
|
707
703
|
throw new TypeError("JSON Web Key for this operation be a private JWK");
|
|
708
704
|
case "encrypt":
|
|
709
705
|
case "verify":
|
|
710
|
-
if (
|
|
706
|
+
if (Re(t) && J(e, t, r))
|
|
711
707
|
return;
|
|
712
708
|
throw new TypeError("JSON Web Key for this operation be a public JWK");
|
|
713
709
|
}
|
|
714
|
-
if (!
|
|
715
|
-
throw new TypeError(
|
|
710
|
+
if (!Z(t))
|
|
711
|
+
throw new TypeError(z(e, t, "CryptoKey", "KeyObject", "JSON Web Key"));
|
|
716
712
|
if (t.type === "secret")
|
|
717
713
|
throw new TypeError(`${C(t)} instances for asymmetric algorithms must not be of type "secret"`);
|
|
718
714
|
if (t.type === "public")
|
|
@@ -729,9 +725,21 @@ const M = async (e, t, r, n = !1) => {
|
|
|
729
725
|
case "encrypt":
|
|
730
726
|
throw new TypeError(`${C(t)} instances for asymmetric algorithm encryption must be of type "public"`);
|
|
731
727
|
}
|
|
732
|
-
}
|
|
733
|
-
|
|
734
|
-
|
|
728
|
+
};
|
|
729
|
+
function Je(e, t, r) {
|
|
730
|
+
switch (e.substring(0, 2)) {
|
|
731
|
+
case "A1":
|
|
732
|
+
case "A2":
|
|
733
|
+
case "di":
|
|
734
|
+
case "HS":
|
|
735
|
+
case "PB":
|
|
736
|
+
We(e, t, r);
|
|
737
|
+
break;
|
|
738
|
+
default:
|
|
739
|
+
He(e, t, r);
|
|
740
|
+
}
|
|
741
|
+
}
|
|
742
|
+
function Le(e, t) {
|
|
735
743
|
const r = `SHA-${e.slice(-3)}`;
|
|
736
744
|
switch (e) {
|
|
737
745
|
case "HS256":
|
|
@@ -760,24 +768,26 @@ const M = async (e, t, r, n = !1) => {
|
|
|
760
768
|
default:
|
|
761
769
|
throw new E(`alg ${e} is not supported either by JOSE or your javascript runtime`);
|
|
762
770
|
}
|
|
763
|
-
}
|
|
771
|
+
}
|
|
772
|
+
async function Ue(e, t, r) {
|
|
764
773
|
if (t instanceof Uint8Array) {
|
|
765
774
|
if (!e.startsWith("HS"))
|
|
766
|
-
throw new TypeError(
|
|
775
|
+
throw new TypeError(pe(t, "CryptoKey", "KeyObject", "JSON Web Key"));
|
|
767
776
|
return crypto.subtle.importKey("raw", t, { hash: `SHA-${e.slice(-3)}`, name: "HMAC" }, !1, [r]);
|
|
768
777
|
}
|
|
769
|
-
return
|
|
770
|
-
}
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
778
|
+
return le(t, e, r), t;
|
|
779
|
+
}
|
|
780
|
+
async function Ne(e, t, r, n) {
|
|
781
|
+
const a = await Ue(e, t, "verify");
|
|
782
|
+
me(e, a);
|
|
783
|
+
const o = Le(e, a.algorithm);
|
|
774
784
|
try {
|
|
775
785
|
return await crypto.subtle.verify(o, a, r, n);
|
|
776
786
|
} catch {
|
|
777
787
|
return !1;
|
|
778
788
|
}
|
|
779
|
-
}
|
|
780
|
-
async function
|
|
789
|
+
}
|
|
790
|
+
async function Me(e, t, r) {
|
|
781
791
|
if (!P(e))
|
|
782
792
|
throw new d("Flattened JWS must be an object");
|
|
783
793
|
if (e.protected === void 0 && e.header === void 0)
|
|
@@ -793,65 +803,66 @@ async function Ue(e, t, r) {
|
|
|
793
803
|
let n = {};
|
|
794
804
|
if (e.protected)
|
|
795
805
|
try {
|
|
796
|
-
const
|
|
797
|
-
n = JSON.parse(
|
|
806
|
+
const ae = v(e.protected);
|
|
807
|
+
n = JSON.parse(T.decode(ae));
|
|
798
808
|
} catch {
|
|
799
809
|
throw new d("JWS Protected Header is invalid");
|
|
800
810
|
}
|
|
801
|
-
if (!
|
|
811
|
+
if (!he(n, e.header))
|
|
802
812
|
throw new d("JWS Protected and JWS Unprotected Header Parameter names must be disjoint");
|
|
803
813
|
const a = {
|
|
804
814
|
...n,
|
|
805
815
|
...e.header
|
|
806
|
-
}, o =
|
|
816
|
+
}, o = Pe(d, /* @__PURE__ */ new Map([["b64", !0]]), r?.crit, n, a);
|
|
807
817
|
let i = !0;
|
|
808
818
|
if (o.has("b64") && (i = n.b64, typeof i != "boolean"))
|
|
809
819
|
throw new d('The "b64" (base64url-encode payload) Header Parameter must be a boolean');
|
|
810
820
|
const { alg: s } = a;
|
|
811
821
|
if (typeof s != "string" || !s)
|
|
812
822
|
throw new d('JWS "alg" (Algorithm) Header Parameter missing or invalid');
|
|
813
|
-
const u = r &&
|
|
823
|
+
const u = r && _e("algorithms", r.algorithms);
|
|
814
824
|
if (u && !u.has(s))
|
|
815
|
-
throw new
|
|
825
|
+
throw new ce('"alg" (Algorithm) Header Parameter value not allowed');
|
|
816
826
|
if (i) {
|
|
817
827
|
if (typeof e.payload != "string")
|
|
818
828
|
throw new d("JWS Payload must be a string");
|
|
819
829
|
} else if (typeof e.payload != "string" && !(e.payload instanceof Uint8Array))
|
|
820
830
|
throw new d("JWS Payload must be a string or an Uint8Array instance");
|
|
821
831
|
let m = !1;
|
|
822
|
-
typeof t == "function" && (t = await t(n, e), m = !0),
|
|
823
|
-
const w =
|
|
832
|
+
typeof t == "function" && (t = await t(n, e), m = !0), Je(s, t, "verify");
|
|
833
|
+
const w = se(e.protected !== void 0 ? D(e.protected) : new Uint8Array(), D("."), typeof e.payload == "string" ? i ? D(e.payload) : N.encode(e.payload) : e.payload);
|
|
824
834
|
let l;
|
|
825
835
|
try {
|
|
826
|
-
l =
|
|
836
|
+
l = v(e.signature);
|
|
827
837
|
} catch {
|
|
828
838
|
throw new d("Failed to base64url decode the signature");
|
|
829
839
|
}
|
|
830
|
-
const _ = await
|
|
840
|
+
const _ = await xe(t, s);
|
|
831
841
|
if (!await Ne(s, _, l, w))
|
|
832
|
-
throw new
|
|
842
|
+
throw new de();
|
|
833
843
|
let f;
|
|
834
844
|
if (i)
|
|
835
845
|
try {
|
|
836
|
-
f =
|
|
846
|
+
f = v(e.payload);
|
|
837
847
|
} catch {
|
|
838
848
|
throw new d("Failed to base64url decode the payload");
|
|
839
849
|
}
|
|
840
|
-
else typeof e.payload == "string" ? f =
|
|
850
|
+
else typeof e.payload == "string" ? f = N.encode(e.payload) : f = e.payload;
|
|
841
851
|
const g = { payload: f };
|
|
842
852
|
return e.protected !== void 0 && (g.protectedHeader = n), e.header !== void 0 && (g.unprotectedHeader = e.header), m ? { ...g, key: _ } : g;
|
|
843
853
|
}
|
|
844
|
-
async function
|
|
845
|
-
if (e instanceof Uint8Array && (e =
|
|
854
|
+
async function $e(e, t, r) {
|
|
855
|
+
if (e instanceof Uint8Array && (e = T.decode(e)), typeof e != "string")
|
|
846
856
|
throw new d("Compact JWS must be a string or Uint8Array");
|
|
847
857
|
const { 0: n, 1: a, 2: o, length: i } = e.split(".");
|
|
848
858
|
if (i !== 3)
|
|
849
859
|
throw new d("Invalid Compact JWS");
|
|
850
|
-
const s = await
|
|
860
|
+
const s = await Me({ payload: a, protected: n, signature: o }, t, r), u = { payload: s.payload, protectedHeader: s.protectedHeader };
|
|
851
861
|
return typeof t == "function" ? { ...u, key: s.key } : u;
|
|
852
862
|
}
|
|
853
|
-
const
|
|
854
|
-
|
|
863
|
+
const ke = (e) => Math.floor(e.getTime() / 1e3), ee = 60, te = ee * 60, U = te * 24, Be = U * 7, Ye = U * 365.25, Fe = /^(\+|\-)? ?(\d+|\d+\.\d+) ?(seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)(?: (ago|from now))?$/i;
|
|
864
|
+
function k(e) {
|
|
865
|
+
const t = Fe.exec(e);
|
|
855
866
|
if (!t || t[4] && t[1])
|
|
856
867
|
throw new TypeError("Invalid time period format");
|
|
857
868
|
const r = parseFloat(t[2]), n = t[3].toLowerCase();
|
|
@@ -869,41 +880,42 @@ const $e = (e) => Math.floor(e.getTime() / 1e3), j = 60, ee = j * 60, N = ee * 2
|
|
|
869
880
|
case "min":
|
|
870
881
|
case "mins":
|
|
871
882
|
case "m":
|
|
872
|
-
a = Math.round(r *
|
|
883
|
+
a = Math.round(r * ee);
|
|
873
884
|
break;
|
|
874
885
|
case "hour":
|
|
875
886
|
case "hours":
|
|
876
887
|
case "hr":
|
|
877
888
|
case "hrs":
|
|
878
889
|
case "h":
|
|
879
|
-
a = Math.round(r *
|
|
890
|
+
a = Math.round(r * te);
|
|
880
891
|
break;
|
|
881
892
|
case "day":
|
|
882
893
|
case "days":
|
|
883
894
|
case "d":
|
|
884
|
-
a = Math.round(r *
|
|
895
|
+
a = Math.round(r * U);
|
|
885
896
|
break;
|
|
886
897
|
case "week":
|
|
887
898
|
case "weeks":
|
|
888
899
|
case "w":
|
|
889
|
-
a = Math.round(r *
|
|
900
|
+
a = Math.round(r * Be);
|
|
890
901
|
break;
|
|
891
902
|
default:
|
|
892
|
-
a = Math.round(r *
|
|
903
|
+
a = Math.round(r * Ye);
|
|
893
904
|
break;
|
|
894
905
|
}
|
|
895
906
|
return t[1] === "-" || t[4] === "ago" ? -a : a;
|
|
896
|
-
}
|
|
907
|
+
}
|
|
908
|
+
const B = (e) => e.includes("/") ? e.toLowerCase() : `application/${e.toLowerCase()}`, Ve = (e, t) => typeof e == "string" ? t.includes(e) : Array.isArray(e) ? t.some(Set.prototype.has.bind(new Set(e))) : !1;
|
|
897
909
|
function Ge(e, t, r = {}) {
|
|
898
910
|
let n;
|
|
899
911
|
try {
|
|
900
|
-
n = JSON.parse(
|
|
912
|
+
n = JSON.parse(T.decode(t));
|
|
901
913
|
} catch {
|
|
902
914
|
}
|
|
903
915
|
if (!P(n))
|
|
904
916
|
throw new S("JWT Claims Set must be a top-level JSON object");
|
|
905
917
|
const { typ: a } = r;
|
|
906
|
-
if (a && (typeof e.typ != "string" ||
|
|
918
|
+
if (a && (typeof e.typ != "string" || B(e.typ) !== B(a)))
|
|
907
919
|
throw new p('unexpected "typ" JWT header value', n, "typ", "check_failed");
|
|
908
920
|
const { requiredClaims: o = [], issuer: i, subject: s, audience: u, maxTokenAge: m } = r, w = [...o];
|
|
909
921
|
m !== void 0 && w.push("iat"), u !== void 0 && w.push("aud"), s !== void 0 && w.push("sub"), i !== void 0 && w.push("iss");
|
|
@@ -914,12 +926,12 @@ function Ge(e, t, r = {}) {
|
|
|
914
926
|
throw new p('unexpected "iss" claim value', n, "iss", "check_failed");
|
|
915
927
|
if (s && n.sub !== s)
|
|
916
928
|
throw new p('unexpected "sub" claim value', n, "sub", "check_failed");
|
|
917
|
-
if (u && !
|
|
929
|
+
if (u && !Ve(n.aud, typeof u == "string" ? [u] : u))
|
|
918
930
|
throw new p('unexpected "aud" claim value', n, "aud", "check_failed");
|
|
919
931
|
let l;
|
|
920
932
|
switch (typeof r.clockTolerance) {
|
|
921
933
|
case "string":
|
|
922
|
-
l =
|
|
934
|
+
l = k(r.clockTolerance);
|
|
923
935
|
break;
|
|
924
936
|
case "number":
|
|
925
937
|
l = r.clockTolerance;
|
|
@@ -930,7 +942,7 @@ function Ge(e, t, r = {}) {
|
|
|
930
942
|
default:
|
|
931
943
|
throw new TypeError("Invalid clockTolerance option type");
|
|
932
944
|
}
|
|
933
|
-
const { currentDate: _ } = r, I =
|
|
945
|
+
const { currentDate: _ } = r, I = ke(_ || /* @__PURE__ */ new Date());
|
|
934
946
|
if ((n.iat !== void 0 || m) && typeof n.iat != "number")
|
|
935
947
|
throw new p('"iat" claim must be a number', n, "iat", "invalid");
|
|
936
948
|
if (n.nbf !== void 0) {
|
|
@@ -943,25 +955,25 @@ function Ge(e, t, r = {}) {
|
|
|
943
955
|
if (typeof n.exp != "number")
|
|
944
956
|
throw new p('"exp" claim must be a number', n, "exp", "invalid");
|
|
945
957
|
if (n.exp <= I - l)
|
|
946
|
-
throw new
|
|
958
|
+
throw new M('"exp" claim timestamp check failed', n, "exp", "check_failed");
|
|
947
959
|
}
|
|
948
960
|
if (m) {
|
|
949
|
-
const f = I - n.iat, g = typeof m == "number" ? m :
|
|
961
|
+
const f = I - n.iat, g = typeof m == "number" ? m : k(m);
|
|
950
962
|
if (f - l > g)
|
|
951
|
-
throw new
|
|
963
|
+
throw new M('"iat" claim timestamp check failed (too far in the past)', n, "iat", "check_failed");
|
|
952
964
|
if (f < 0 - l)
|
|
953
965
|
throw new p('"iat" claim timestamp check failed (it should be in the past)', n, "iat", "check_failed");
|
|
954
966
|
}
|
|
955
967
|
return n;
|
|
956
968
|
}
|
|
957
|
-
async function
|
|
958
|
-
const n = await
|
|
969
|
+
async function qe(e, t, r) {
|
|
970
|
+
const n = await $e(e, t, r);
|
|
959
971
|
if (n.protectedHeader.crit?.includes("b64") && n.protectedHeader.b64 === !1)
|
|
960
972
|
throw new S("JWTs MUST NOT use unencoded payload");
|
|
961
973
|
const o = { payload: Ge(n.protectedHeader, n.payload, r), protectedHeader: n.protectedHeader };
|
|
962
974
|
return typeof t == "function" ? { ...o, key: n.key } : o;
|
|
963
975
|
}
|
|
964
|
-
function
|
|
976
|
+
function re(e) {
|
|
965
977
|
if (typeof e != "string")
|
|
966
978
|
throw new S("JWTs must use Compact JWS serialization, JWT must be a string");
|
|
967
979
|
const { 1: t, length: r } = e.split(".");
|
|
@@ -973,13 +985,13 @@ function te(e) {
|
|
|
973
985
|
throw new S("JWTs must contain a payload");
|
|
974
986
|
let n;
|
|
975
987
|
try {
|
|
976
|
-
n =
|
|
988
|
+
n = v(t);
|
|
977
989
|
} catch {
|
|
978
990
|
throw new S("Failed to base64url decode the payload");
|
|
979
991
|
}
|
|
980
992
|
let a;
|
|
981
993
|
try {
|
|
982
|
-
a = JSON.parse(
|
|
994
|
+
a = JSON.parse(T.decode(n));
|
|
983
995
|
} catch {
|
|
984
996
|
throw new S("Failed to parse the decoded payload as JSON");
|
|
985
997
|
}
|
|
@@ -987,93 +999,93 @@ function te(e) {
|
|
|
987
999
|
throw new S("Invalid JWT Claims Set");
|
|
988
1000
|
return a;
|
|
989
1001
|
}
|
|
990
|
-
const
|
|
1002
|
+
const ze = async (e) => {
|
|
991
1003
|
try {
|
|
992
|
-
const t = y.ALG, n = await ve(
|
|
993
|
-
return await
|
|
1004
|
+
const t = y.ALG, n = await ve(ie, t);
|
|
1005
|
+
return await qe(e, n, {
|
|
994
1006
|
issuer: y.ISSUER
|
|
995
1007
|
});
|
|
996
1008
|
} catch {
|
|
997
1009
|
return;
|
|
998
1010
|
}
|
|
999
|
-
},
|
|
1011
|
+
}, ft = (e) => {
|
|
1000
1012
|
try {
|
|
1001
|
-
return
|
|
1013
|
+
return re(e);
|
|
1002
1014
|
} catch {
|
|
1003
1015
|
return;
|
|
1004
1016
|
}
|
|
1005
1017
|
}, c = [];
|
|
1006
1018
|
for (let e = 0; e < 256; ++e)
|
|
1007
1019
|
c.push((e + 256).toString(16).slice(1));
|
|
1008
|
-
function
|
|
1020
|
+
function Xe(e, t = 0) {
|
|
1009
1021
|
return (c[e[t + 0]] + c[e[t + 1]] + c[e[t + 2]] + c[e[t + 3]] + "-" + c[e[t + 4]] + c[e[t + 5]] + "-" + c[e[t + 6]] + c[e[t + 7]] + "-" + c[e[t + 8]] + c[e[t + 9]] + "-" + c[e[t + 10]] + c[e[t + 11]] + c[e[t + 12]] + c[e[t + 13]] + c[e[t + 14]] + c[e[t + 15]]).toLowerCase();
|
|
1010
1022
|
}
|
|
1011
1023
|
let H;
|
|
1012
|
-
const
|
|
1013
|
-
function
|
|
1024
|
+
const Qe = new Uint8Array(16);
|
|
1025
|
+
function Ze() {
|
|
1014
1026
|
if (!H) {
|
|
1015
1027
|
if (typeof crypto > "u" || !crypto.getRandomValues)
|
|
1016
1028
|
throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
|
|
1017
1029
|
H = crypto.getRandomValues.bind(crypto);
|
|
1018
1030
|
}
|
|
1019
|
-
return H(
|
|
1031
|
+
return H(Qe);
|
|
1020
1032
|
}
|
|
1021
|
-
const
|
|
1022
|
-
function
|
|
1023
|
-
if (
|
|
1024
|
-
return
|
|
1033
|
+
const je = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto), Y = { randomUUID: je };
|
|
1034
|
+
function F(e, t, r) {
|
|
1035
|
+
if (Y.randomUUID && !e)
|
|
1036
|
+
return Y.randomUUID();
|
|
1025
1037
|
e = e || {};
|
|
1026
|
-
const n = e.random ?? e.rng?.() ??
|
|
1038
|
+
const n = e.random ?? e.rng?.() ?? Ze();
|
|
1027
1039
|
if (n.length < 16)
|
|
1028
1040
|
throw new Error("Random bytes length must be >= 16");
|
|
1029
|
-
return n[6] = n[6] & 15 | 64, n[8] = n[8] & 63 | 128,
|
|
1041
|
+
return n[6] = n[6] & 15 | 64, n[8] = n[8] & 63 | 128, Xe(n);
|
|
1030
1042
|
}
|
|
1031
|
-
const
|
|
1043
|
+
const V = globalThis.crypto, et = (e) => `${F()}${F()}`.slice(0, e), tt = (e) => btoa(
|
|
1032
1044
|
[...new Uint8Array(e)].map((t) => String.fromCharCode(t)).join("")
|
|
1033
1045
|
);
|
|
1034
|
-
async function
|
|
1035
|
-
if (!
|
|
1046
|
+
async function ne(e) {
|
|
1047
|
+
if (!V.subtle)
|
|
1036
1048
|
throw new Error(
|
|
1037
1049
|
"crypto.subtle is available only in secure contexts (HTTPS)."
|
|
1038
1050
|
);
|
|
1039
|
-
const t = new TextEncoder().encode(e), r = await
|
|
1040
|
-
return
|
|
1051
|
+
const t = new TextEncoder().encode(e), r = await V.subtle.digest("SHA-256", t);
|
|
1052
|
+
return tt(r).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
1041
1053
|
}
|
|
1042
|
-
async function
|
|
1054
|
+
async function lt(e) {
|
|
1043
1055
|
const t = e || 43;
|
|
1044
1056
|
if (t < 43 || t > 128)
|
|
1045
1057
|
throw `Expected a length between 43 and 128. Received ${e}.`;
|
|
1046
|
-
const r =
|
|
1058
|
+
const r = et(t), n = await ne(r);
|
|
1047
1059
|
return {
|
|
1048
1060
|
code_verifier: r,
|
|
1049
1061
|
code_challenge: n
|
|
1050
1062
|
};
|
|
1051
1063
|
}
|
|
1052
|
-
async function
|
|
1053
|
-
return t === await
|
|
1064
|
+
async function pt(e, t) {
|
|
1065
|
+
return t === await ne(e);
|
|
1054
1066
|
}
|
|
1055
|
-
const
|
|
1067
|
+
const rt = /^Bearer (.+)$/i, nt = (e) => {
|
|
1056
1068
|
if (typeof e?.authorization != "string")
|
|
1057
1069
|
return;
|
|
1058
|
-
const t = e.authorization.match(
|
|
1070
|
+
const t = e.authorization.match(rt);
|
|
1059
1071
|
if (t)
|
|
1060
1072
|
return t[1];
|
|
1061
|
-
},
|
|
1073
|
+
}, at = (e, t) => {
|
|
1062
1074
|
const r = e?.cookie;
|
|
1063
1075
|
if (typeof r != "string")
|
|
1064
1076
|
return;
|
|
1065
1077
|
const n = new RegExp(`auth.${t}=(.+?)(?:;|$)`), a = r.match(n);
|
|
1066
1078
|
if (a)
|
|
1067
1079
|
return a[1];
|
|
1068
|
-
},
|
|
1069
|
-
const t = e?.[
|
|
1080
|
+
}, ot = (e) => {
|
|
1081
|
+
const t = e?.[oe.ACCESS_TOKEN];
|
|
1070
1082
|
if (typeof t == "string")
|
|
1071
1083
|
return t;
|
|
1072
|
-
},
|
|
1073
|
-
const n =
|
|
1074
|
-
return
|
|
1075
|
-
},
|
|
1076
|
-
const r = await
|
|
1084
|
+
}, ht = ({ headers: e, body: t, clientId: r }) => {
|
|
1085
|
+
const n = nt(e), a = at(e, r);
|
|
1086
|
+
return ot(t) || a || n || "";
|
|
1087
|
+
}, yt = async (e, t) => {
|
|
1088
|
+
const r = await ze(e);
|
|
1077
1089
|
if (!r || !r.payload)
|
|
1078
1090
|
return !1;
|
|
1079
1091
|
let n = [];
|
|
@@ -1086,9 +1098,9 @@ const tt = /^Bearer (.+)$/i, rt = (e) => {
|
|
|
1086
1098
|
return Array.isArray(t) ? t.every((a) => n.includes(a)) : Object.keys(t).some(
|
|
1087
1099
|
(a) => t[a].every((o) => n.includes(o))
|
|
1088
1100
|
);
|
|
1089
|
-
},
|
|
1101
|
+
}, mt = (e, t) => {
|
|
1090
1102
|
try {
|
|
1091
|
-
const r =
|
|
1103
|
+
const r = re(e);
|
|
1092
1104
|
if (!r)
|
|
1093
1105
|
return !1;
|
|
1094
1106
|
let n = [];
|
|
@@ -1104,29 +1116,29 @@ const tt = /^Bearer (.+)$/i, rt = (e) => {
|
|
|
1104
1116
|
} catch {
|
|
1105
1117
|
return !1;
|
|
1106
1118
|
}
|
|
1107
|
-
},
|
|
1119
|
+
}, it = (e, t) => {
|
|
1108
1120
|
const r = e?.cookie;
|
|
1109
1121
|
if (typeof r != "string")
|
|
1110
1122
|
return;
|
|
1111
1123
|
const n = new RegExp(`auth.${t}.session=(.+?)(?:;|$)`), a = r.match(n);
|
|
1112
1124
|
if (a)
|
|
1113
1125
|
return a[1];
|
|
1114
|
-
},
|
|
1126
|
+
}, St = ({ headers: e, clientId: t }) => it(e, t) || "";
|
|
1115
1127
|
export {
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1128
|
+
ut as API_TYPE,
|
|
1129
|
+
st as AUTH_TYPES,
|
|
1130
|
+
oe as BODY,
|
|
1131
|
+
ct as HEADERS,
|
|
1120
1132
|
y as JWT,
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1133
|
+
ie as JWT_PUBLIC_KEY,
|
|
1134
|
+
dt as TOKEN_EXPIRATION,
|
|
1135
|
+
ft as decodeToken,
|
|
1136
|
+
ne as generateCodeChallenge,
|
|
1137
|
+
St as getSession,
|
|
1138
|
+
ht as getToken,
|
|
1139
|
+
yt as isGranted,
|
|
1140
|
+
mt as isGrantedSync,
|
|
1141
|
+
lt as pkceChallengePair,
|
|
1142
|
+
ze as verifyAndExtractToken,
|
|
1143
|
+
pt as verifyChallenge
|
|
1132
1144
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@versini/auth-common",
|
|
3
|
-
"version": "4.6.
|
|
3
|
+
"version": "4.6.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Arno Versini",
|
|
6
6
|
"publishConfig": {
|
|
@@ -34,8 +34,8 @@
|
|
|
34
34
|
"test:coverage": "vitest run --coverage"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"jose": "6.1.
|
|
37
|
+
"jose": "6.1.2",
|
|
38
38
|
"uuid": "11.1.0"
|
|
39
39
|
},
|
|
40
|
-
"gitHead": "
|
|
40
|
+
"gitHead": "f9cc50d9cfb4b7ac832410455a02bb7c65cf82a3"
|
|
41
41
|
}
|