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