@versini/auth-common 2.7.0 → 2.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +8 -1
- package/dist/index.js +116 -109
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ declare const AUTH_TYPES: {
|
|
|
4
4
|
ID_TOKEN: string;
|
|
5
5
|
ACCESS_TOKEN: string;
|
|
6
6
|
ID_AND_ACCESS_TOKEN: string;
|
|
7
|
+
CODE: string;
|
|
7
8
|
};
|
|
8
9
|
declare const HEADERS: {
|
|
9
10
|
CLIENT_ID: string;
|
|
@@ -19,6 +20,12 @@ declare const JWT_PUBLIC_KEY = "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0B
|
|
|
19
20
|
declare const TOKEN_EXPIRATION: {
|
|
20
21
|
ACCESS: string;
|
|
21
22
|
ID: string;
|
|
23
|
+
REFRESH: string;
|
|
24
|
+
};
|
|
25
|
+
declare const API_TYPE: {
|
|
26
|
+
AUTHENTICATE: string;
|
|
27
|
+
CODE: string;
|
|
28
|
+
LOGOUT: string;
|
|
22
29
|
};
|
|
23
30
|
|
|
24
31
|
declare const verifyAndExtractToken: (token: string) => Promise<jose.JWTVerifyResult<jose.JWTPayload> | undefined>;
|
|
@@ -49,4 +56,4 @@ declare function pkceChallengePair(length?: number): Promise<{
|
|
|
49
56
|
*/
|
|
50
57
|
declare function verifyChallenge(code_verifier: string, expectedChallenge: string): Promise<boolean>;
|
|
51
58
|
|
|
52
|
-
export { AUTH_TYPES, HEADERS, JWT, JWT_PUBLIC_KEY, TOKEN_EXPIRATION, generateCodeChallenge, pkceChallengePair, verifyAndExtractToken, verifyChallenge };
|
|
59
|
+
export { API_TYPE, AUTH_TYPES, HEADERS, JWT, JWT_PUBLIC_KEY, TOKEN_EXPIRATION, generateCodeChallenge, pkceChallengePair, verifyAndExtractToken, verifyChallenge };
|
package/dist/index.js
CHANGED
|
@@ -1,25 +1,26 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
@versini/auth-common v2.
|
|
2
|
+
@versini/auth-common v2.8.0
|
|
3
3
|
© 2024 gizmette.com
|
|
4
4
|
*/
|
|
5
5
|
try {
|
|
6
6
|
window.__VERSINI_AUTH_COMMON__ || (window.__VERSINI_AUTH_COMMON__ = {
|
|
7
|
-
version: "2.
|
|
8
|
-
buildTime: "06/27/2024
|
|
7
|
+
version: "2.8.0",
|
|
8
|
+
buildTime: "06/27/2024 06:57 PM EDT",
|
|
9
9
|
homepage: "https://github.com/aversini/auth-client",
|
|
10
10
|
license: "MIT"
|
|
11
11
|
});
|
|
12
12
|
} catch {
|
|
13
13
|
}
|
|
14
|
-
const
|
|
14
|
+
const Ke = {
|
|
15
15
|
ID_TOKEN: "id_token",
|
|
16
16
|
ACCESS_TOKEN: "token",
|
|
17
|
-
ID_AND_ACCESS_TOKEN: "id_token token"
|
|
17
|
+
ID_AND_ACCESS_TOKEN: "id_token token",
|
|
18
|
+
CODE: "code"
|
|
18
19
|
}, De = {
|
|
19
20
|
CLIENT_ID: "X-Auth-ClientId"
|
|
20
|
-
},
|
|
21
|
+
}, K = {
|
|
21
22
|
ALG: "RS256",
|
|
22
|
-
USER_ID_KEY: "
|
|
23
|
+
USER_ID_KEY: "sub",
|
|
23
24
|
TOKEN_ID_KEY: "__raw",
|
|
24
25
|
NONCE_KEY: "_nonce",
|
|
25
26
|
ISSUER: "gizmette.com"
|
|
@@ -31,15 +32,20 @@ aMwPFOIcJH+rKfFgNcHLcaS5syp7zU1ANwZ+trgR+DifBr8TLVkBynmNeTyhDm2+
|
|
|
31
32
|
l0haqjMk0UoNPPE8iYBWUHQJJE1Dqstj65d6Eh5g64Pao25y4cmYJbKjiblIGEkE
|
|
32
33
|
sjqybA9mARAqh9k/eiIopecWSiffNQTwVQVd2I9ZH3BalhEXHlqFgrjz51kFqg81
|
|
33
34
|
awIDAQAB
|
|
34
|
-
-----END PUBLIC KEY-----`,
|
|
35
|
+
-----END PUBLIC KEY-----`, He = {
|
|
35
36
|
ACCESS: "5m",
|
|
36
|
-
ID: "90d"
|
|
37
|
+
ID: "90d",
|
|
38
|
+
REFRESH: "90d"
|
|
39
|
+
}, Ne = {
|
|
40
|
+
AUTHENTICATE: "authenticate",
|
|
41
|
+
CODE: "code",
|
|
42
|
+
LOGOUT: "logout"
|
|
37
43
|
}, O = crypto, V = (e) => e instanceof CryptoKey, g = new TextEncoder(), _ = new TextDecoder();
|
|
38
44
|
function j(...e) {
|
|
39
|
-
const t = e.reduce((
|
|
45
|
+
const t = e.reduce((o, { length: i }) => o + i, 0), n = new Uint8Array(t);
|
|
40
46
|
let r = 0;
|
|
41
|
-
for (const
|
|
42
|
-
n.set(
|
|
47
|
+
for (const o of e)
|
|
48
|
+
n.set(o, r), r += o.length;
|
|
43
49
|
return n;
|
|
44
50
|
}
|
|
45
51
|
const Z = (e) => {
|
|
@@ -69,16 +75,16 @@ class h extends b {
|
|
|
69
75
|
static get code() {
|
|
70
76
|
return "ERR_JWT_CLAIM_VALIDATION_FAILED";
|
|
71
77
|
}
|
|
72
|
-
constructor(t, n, r = "unspecified",
|
|
73
|
-
super(t), this.code = "ERR_JWT_CLAIM_VALIDATION_FAILED", this.claim = r, this.reason =
|
|
78
|
+
constructor(t, n, r = "unspecified", o = "unspecified") {
|
|
79
|
+
super(t), this.code = "ERR_JWT_CLAIM_VALIDATION_FAILED", this.claim = r, this.reason = o, this.payload = n;
|
|
74
80
|
}
|
|
75
81
|
}
|
|
76
82
|
class D extends b {
|
|
77
83
|
static get code() {
|
|
78
84
|
return "ERR_JWT_EXPIRED";
|
|
79
85
|
}
|
|
80
|
-
constructor(t, n, r = "unspecified",
|
|
81
|
-
super(t), this.code = "ERR_JWT_EXPIRED", this.claim = r, this.reason =
|
|
86
|
+
constructor(t, n, r = "unspecified", o = "unspecified") {
|
|
87
|
+
super(t), this.code = "ERR_JWT_EXPIRED", this.claim = r, this.reason = o, this.payload = n;
|
|
82
88
|
}
|
|
83
89
|
}
|
|
84
90
|
class ee extends b {
|
|
@@ -153,7 +159,7 @@ function ne(e, t) {
|
|
|
153
159
|
throw new TypeError(n);
|
|
154
160
|
}
|
|
155
161
|
}
|
|
156
|
-
function
|
|
162
|
+
function oe(e, t, ...n) {
|
|
157
163
|
switch (t) {
|
|
158
164
|
case "HS256":
|
|
159
165
|
case "HS384":
|
|
@@ -208,28 +214,28 @@ function ae(e, t, ...n) {
|
|
|
208
214
|
function F(e, t, ...n) {
|
|
209
215
|
var r;
|
|
210
216
|
if (n.length > 2) {
|
|
211
|
-
const
|
|
212
|
-
e += `one of type ${n.join(", ")}, or ${
|
|
217
|
+
const o = n.pop();
|
|
218
|
+
e += `one of type ${n.join(", ")}, or ${o}.`;
|
|
213
219
|
} else
|
|
214
220
|
n.length === 2 ? e += `one of type ${n[0]} or ${n[1]}.` : e += `of type ${n[0]}.`;
|
|
215
221
|
return t == null ? e += ` Received ${t}` : typeof t == "function" && t.name ? e += ` Received function ${t.name}` : typeof t == "object" && t != null && (r = t.constructor) != null && r.name && (e += ` Received an instance of ${t.constructor.name}`), e;
|
|
216
222
|
}
|
|
217
|
-
const
|
|
223
|
+
const H = (e, ...t) => F("Key must be ", e, ...t);
|
|
218
224
|
function G(e, t, ...n) {
|
|
219
225
|
return F(`Key for the ${e} algorithm must be `, t, ...n);
|
|
220
226
|
}
|
|
221
|
-
const Y = (e) => V(e),
|
|
227
|
+
const Y = (e) => V(e), E = ["CryptoKey"], ae = (...e) => {
|
|
222
228
|
const t = e.filter(Boolean);
|
|
223
229
|
if (t.length === 0 || t.length === 1)
|
|
224
230
|
return !0;
|
|
225
231
|
let n;
|
|
226
232
|
for (const r of t) {
|
|
227
|
-
const
|
|
233
|
+
const o = Object.keys(r);
|
|
228
234
|
if (!n || n.size === 0) {
|
|
229
|
-
n = new Set(
|
|
235
|
+
n = new Set(o);
|
|
230
236
|
continue;
|
|
231
237
|
}
|
|
232
|
-
for (const i of
|
|
238
|
+
for (const i of o) {
|
|
233
239
|
if (n.has(i))
|
|
234
240
|
return !1;
|
|
235
241
|
n.add(i);
|
|
@@ -261,9 +267,9 @@ const ce = (e, t) => {
|
|
|
261
267
|
const r = e.indexOf(t[0], n);
|
|
262
268
|
if (r === -1)
|
|
263
269
|
return !1;
|
|
264
|
-
const
|
|
265
|
-
return
|
|
266
|
-
},
|
|
270
|
+
const o = e.subarray(r, r + t.length);
|
|
271
|
+
return o.length !== t.length ? !1 : o.every((i, a) => i === t[a]) || S(e, t, r + 1);
|
|
272
|
+
}, N = (e) => {
|
|
267
273
|
switch (!0) {
|
|
268
274
|
case S(e, [42, 134, 72, 206, 61, 3, 1, 7]):
|
|
269
275
|
return "P-256";
|
|
@@ -282,19 +288,19 @@ const ce = (e, t) => {
|
|
|
282
288
|
default:
|
|
283
289
|
throw new C("Invalid or unsupported EC Key Curve or OKP Key Sub Type");
|
|
284
290
|
}
|
|
285
|
-
}, se = async (e, t, n, r,
|
|
286
|
-
let i,
|
|
291
|
+
}, se = async (e, t, n, r, o) => {
|
|
292
|
+
let i, a;
|
|
287
293
|
const c = new Uint8Array(atob(n.replace(e, "")).split("").map((s) => s.charCodeAt(0)));
|
|
288
294
|
switch (r) {
|
|
289
295
|
case "PS256":
|
|
290
296
|
case "PS384":
|
|
291
297
|
case "PS512":
|
|
292
|
-
i = { name: "RSA-PSS", hash: `SHA-${r.slice(-3)}` },
|
|
298
|
+
i = { name: "RSA-PSS", hash: `SHA-${r.slice(-3)}` }, a = ["verify"];
|
|
293
299
|
break;
|
|
294
300
|
case "RS256":
|
|
295
301
|
case "RS384":
|
|
296
302
|
case "RS512":
|
|
297
|
-
i = { name: "RSASSA-PKCS1-v1_5", hash: `SHA-${r.slice(-3)}` },
|
|
303
|
+
i = { name: "RSASSA-PKCS1-v1_5", hash: `SHA-${r.slice(-3)}` }, a = ["verify"];
|
|
298
304
|
break;
|
|
299
305
|
case "RSA-OAEP":
|
|
300
306
|
case "RSA-OAEP-256":
|
|
@@ -303,32 +309,32 @@ const ce = (e, t) => {
|
|
|
303
309
|
i = {
|
|
304
310
|
name: "RSA-OAEP",
|
|
305
311
|
hash: `SHA-${parseInt(r.slice(-3), 10) || 1}`
|
|
306
|
-
},
|
|
312
|
+
}, a = ["encrypt", "wrapKey"];
|
|
307
313
|
break;
|
|
308
314
|
case "ES256":
|
|
309
|
-
i = { name: "ECDSA", namedCurve: "P-256" },
|
|
315
|
+
i = { name: "ECDSA", namedCurve: "P-256" }, a = ["verify"];
|
|
310
316
|
break;
|
|
311
317
|
case "ES384":
|
|
312
|
-
i = { name: "ECDSA", namedCurve: "P-384" },
|
|
318
|
+
i = { name: "ECDSA", namedCurve: "P-384" }, a = ["verify"];
|
|
313
319
|
break;
|
|
314
320
|
case "ES512":
|
|
315
|
-
i = { name: "ECDSA", namedCurve: "P-521" },
|
|
321
|
+
i = { name: "ECDSA", namedCurve: "P-521" }, a = ["verify"];
|
|
316
322
|
break;
|
|
317
323
|
case "ECDH-ES":
|
|
318
324
|
case "ECDH-ES+A128KW":
|
|
319
325
|
case "ECDH-ES+A192KW":
|
|
320
326
|
case "ECDH-ES+A256KW": {
|
|
321
|
-
const s =
|
|
322
|
-
i = s.startsWith("P-") ? { name: "ECDH", namedCurve: s } : { name: s },
|
|
327
|
+
const s = N(c);
|
|
328
|
+
i = s.startsWith("P-") ? { name: "ECDH", namedCurve: s } : { name: s }, a = [];
|
|
323
329
|
break;
|
|
324
330
|
}
|
|
325
331
|
case "EdDSA":
|
|
326
|
-
i = { name:
|
|
332
|
+
i = { name: N(c) }, a = ["verify"];
|
|
327
333
|
break;
|
|
328
334
|
default:
|
|
329
335
|
throw new C('Invalid or unsupported "alg" (Algorithm) value');
|
|
330
336
|
}
|
|
331
|
-
return O.subtle.importKey(t, c, i, !1,
|
|
337
|
+
return O.subtle.importKey(t, c, i, !1, a);
|
|
332
338
|
}, de = (e, t, n) => se(/(?:-----(?:BEGIN|END) PUBLIC KEY-----|\s)/g, "spki", e, t);
|
|
333
339
|
async function ue(e, t, n) {
|
|
334
340
|
if (e.indexOf("-----BEGIN PUBLIC KEY-----") !== 0)
|
|
@@ -338,38 +344,38 @@ async function ue(e, t, n) {
|
|
|
338
344
|
const le = (e, t) => {
|
|
339
345
|
if (!(t instanceof Uint8Array)) {
|
|
340
346
|
if (!Y(t))
|
|
341
|
-
throw new TypeError(G(e, t, ...
|
|
347
|
+
throw new TypeError(G(e, t, ...E, "Uint8Array"));
|
|
342
348
|
if (t.type !== "secret")
|
|
343
|
-
throw new TypeError(`${
|
|
349
|
+
throw new TypeError(`${E.join(" or ")} instances for symmetric algorithms must be of type "secret"`);
|
|
344
350
|
}
|
|
345
351
|
}, fe = (e, t, n) => {
|
|
346
352
|
if (!Y(t))
|
|
347
|
-
throw new TypeError(G(e, t, ...
|
|
353
|
+
throw new TypeError(G(e, t, ...E));
|
|
348
354
|
if (t.type === "secret")
|
|
349
|
-
throw new TypeError(`${
|
|
355
|
+
throw new TypeError(`${E.join(" or ")} instances for asymmetric algorithms must not be of type "secret"`);
|
|
350
356
|
if (t.algorithm && n === "verify" && t.type === "private")
|
|
351
|
-
throw new TypeError(`${
|
|
357
|
+
throw new TypeError(`${E.join(" or ")} instances for asymmetric algorithm verifying must be of type "public"`);
|
|
352
358
|
if (t.algorithm && n === "encrypt" && t.type === "private")
|
|
353
|
-
throw new TypeError(`${
|
|
359
|
+
throw new TypeError(`${E.join(" or ")} instances for asymmetric algorithm encryption must be of type "public"`);
|
|
354
360
|
}, he = (e, t, n) => {
|
|
355
361
|
e.startsWith("HS") || e === "dir" || e.startsWith("PBES2") || /^A\d{3}(?:GCM)?KW$/.test(e) ? le(e, t) : fe(e, t, n);
|
|
356
362
|
};
|
|
357
|
-
function pe(e, t, n, r,
|
|
358
|
-
if (
|
|
363
|
+
function pe(e, t, n, r, o) {
|
|
364
|
+
if (o.crit !== void 0 && (r == null ? void 0 : r.crit) === void 0)
|
|
359
365
|
throw new e('"crit" (Critical) Header Parameter MUST be integrity protected');
|
|
360
366
|
if (!r || r.crit === void 0)
|
|
361
367
|
return /* @__PURE__ */ new Set();
|
|
362
|
-
if (!Array.isArray(r.crit) || r.crit.length === 0 || r.crit.some((
|
|
368
|
+
if (!Array.isArray(r.crit) || r.crit.length === 0 || r.crit.some((a) => typeof a != "string" || a.length === 0))
|
|
363
369
|
throw new e('"crit" (Critical) Header Parameter MUST be an array of non-empty strings when present');
|
|
364
370
|
let i;
|
|
365
371
|
n !== void 0 ? i = new Map([...Object.entries(n), ...t.entries()]) : i = t;
|
|
366
|
-
for (const
|
|
367
|
-
if (!i.has(
|
|
368
|
-
throw new C(`Extension Header Parameter "${
|
|
369
|
-
if (a
|
|
370
|
-
throw new e(`Extension Header Parameter "${
|
|
371
|
-
if (i.get(
|
|
372
|
-
throw new e(`Extension Header Parameter "${
|
|
372
|
+
for (const a of r.crit) {
|
|
373
|
+
if (!i.has(a))
|
|
374
|
+
throw new C(`Extension Header Parameter "${a}" is not recognized`);
|
|
375
|
+
if (o[a] === void 0)
|
|
376
|
+
throw new e(`Extension Header Parameter "${a}" is missing`);
|
|
377
|
+
if (i.get(a) && r[a] === void 0)
|
|
378
|
+
throw new e(`Extension Header Parameter "${a}" MUST be integrity protected`);
|
|
373
379
|
}
|
|
374
380
|
return new Set(r.crit);
|
|
375
381
|
}
|
|
@@ -406,25 +412,25 @@ function ye(e, t) {
|
|
|
406
412
|
}
|
|
407
413
|
function Se(e, t, n) {
|
|
408
414
|
if (V(t))
|
|
409
|
-
return
|
|
415
|
+
return oe(t, e, n), t;
|
|
410
416
|
if (t instanceof Uint8Array) {
|
|
411
417
|
if (!e.startsWith("HS"))
|
|
412
|
-
throw new TypeError(
|
|
418
|
+
throw new TypeError(H(t, ...E));
|
|
413
419
|
return O.subtle.importKey("raw", t, { hash: `SHA-${e.slice(-3)}`, name: "HMAC" }, !1, [n]);
|
|
414
420
|
}
|
|
415
|
-
throw new TypeError(
|
|
421
|
+
throw new TypeError(H(t, ...E, "Uint8Array"));
|
|
416
422
|
}
|
|
417
|
-
const
|
|
418
|
-
const
|
|
419
|
-
ce(e,
|
|
420
|
-
const i = ye(e,
|
|
423
|
+
const Ee = async (e, t, n, r) => {
|
|
424
|
+
const o = await Se(e, t, "verify");
|
|
425
|
+
ce(e, o);
|
|
426
|
+
const i = ye(e, o.algorithm);
|
|
421
427
|
try {
|
|
422
|
-
return await O.subtle.verify(i,
|
|
428
|
+
return await O.subtle.verify(i, o, n, r);
|
|
423
429
|
} catch {
|
|
424
430
|
return !1;
|
|
425
431
|
}
|
|
426
432
|
};
|
|
427
|
-
async function
|
|
433
|
+
async function we(e, t, n) {
|
|
428
434
|
if (!x(e))
|
|
429
435
|
throw new u("Flattened JWS must be an object");
|
|
430
436
|
if (e.protected === void 0 && e.header === void 0)
|
|
@@ -445,39 +451,39 @@ async function Ee(e, t, n) {
|
|
|
445
451
|
} catch {
|
|
446
452
|
throw new u("JWS Protected Header is invalid");
|
|
447
453
|
}
|
|
448
|
-
if (!
|
|
454
|
+
if (!ae(r, e.header))
|
|
449
455
|
throw new u("JWS Protected and JWS Unprotected Header Parameter names must be disjoint");
|
|
450
|
-
const
|
|
456
|
+
const o = {
|
|
451
457
|
...r,
|
|
452
458
|
...e.header
|
|
453
|
-
}, i = pe(u, /* @__PURE__ */ new Map([["b64", !0]]), n == null ? void 0 : n.crit, r,
|
|
454
|
-
let
|
|
455
|
-
if (i.has("b64") && (
|
|
459
|
+
}, i = pe(u, /* @__PURE__ */ new Map([["b64", !0]]), n == null ? void 0 : n.crit, r, o);
|
|
460
|
+
let a = !0;
|
|
461
|
+
if (i.has("b64") && (a = r.b64, typeof a != "boolean"))
|
|
456
462
|
throw new u('The "b64" (base64url-encode payload) Header Parameter must be a boolean');
|
|
457
|
-
const { alg: c } =
|
|
463
|
+
const { alg: c } = o;
|
|
458
464
|
if (typeof c != "string" || !c)
|
|
459
465
|
throw new u('JWS "alg" (Algorithm) Header Parameter missing or invalid');
|
|
460
466
|
const s = n && me("algorithms", n.algorithms);
|
|
461
467
|
if (s && !s.has(c))
|
|
462
468
|
throw new ee('"alg" (Algorithm) Header Parameter value not allowed');
|
|
463
|
-
if (
|
|
469
|
+
if (a) {
|
|
464
470
|
if (typeof e.payload != "string")
|
|
465
471
|
throw new u("JWS Payload must be a string");
|
|
466
472
|
} else if (typeof e.payload != "string" && !(e.payload instanceof Uint8Array))
|
|
467
473
|
throw new u("JWS Payload must be a string or an Uint8Array instance");
|
|
468
474
|
let p = !1;
|
|
469
475
|
typeof t == "function" && (t = await t(r, e), p = !0), he(c, t, "verify");
|
|
470
|
-
const
|
|
476
|
+
const w = j(g.encode(e.protected ?? ""), g.encode("."), typeof e.payload == "string" ? g.encode(e.payload) : e.payload);
|
|
471
477
|
let f;
|
|
472
478
|
try {
|
|
473
479
|
f = R(e.signature);
|
|
474
480
|
} catch {
|
|
475
481
|
throw new u("Failed to base64url decode the signature");
|
|
476
482
|
}
|
|
477
|
-
if (!await
|
|
483
|
+
if (!await Ee(c, t, f, w))
|
|
478
484
|
throw new te();
|
|
479
485
|
let y;
|
|
480
|
-
if (
|
|
486
|
+
if (a)
|
|
481
487
|
try {
|
|
482
488
|
y = R(e.payload);
|
|
483
489
|
} catch {
|
|
@@ -491,55 +497,55 @@ async function Ee(e, t, n) {
|
|
|
491
497
|
async function be(e, t, n) {
|
|
492
498
|
if (e instanceof Uint8Array && (e = _.decode(e)), typeof e != "string")
|
|
493
499
|
throw new u("Compact JWS must be a string or Uint8Array");
|
|
494
|
-
const { 0: r, 1:
|
|
495
|
-
if (
|
|
500
|
+
const { 0: r, 1: o, 2: i, length: a } = e.split(".");
|
|
501
|
+
if (a !== 3)
|
|
496
502
|
throw new u("Invalid Compact JWS");
|
|
497
|
-
const c = await
|
|
503
|
+
const c = await we({ payload: o, protected: r, signature: i }, t, n), s = { payload: c.payload, protectedHeader: c.protectedHeader };
|
|
498
504
|
return typeof t == "function" ? { ...s, key: c.key } : s;
|
|
499
505
|
}
|
|
500
|
-
const ge = (e) => Math.floor(e.getTime() / 1e3), q = 60, z = q * 60, J = z * 24, Ae = J * 7, Ie = J * 365.25, _e = /^(\+|\-)? ?(\d+|\d+\.\d+) ?(seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)(?: (ago|from now))?$/i,
|
|
506
|
+
const ge = (e) => Math.floor(e.getTime() / 1e3), q = 60, z = q * 60, J = z * 24, Ae = J * 7, Ie = J * 365.25, _e = /^(\+|\-)? ?(\d+|\d+\.\d+) ?(seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)(?: (ago|from now))?$/i, W = (e) => {
|
|
501
507
|
const t = _e.exec(e);
|
|
502
508
|
if (!t || t[4] && t[1])
|
|
503
509
|
throw new TypeError("Invalid time period format");
|
|
504
510
|
const n = parseFloat(t[2]), r = t[3].toLowerCase();
|
|
505
|
-
let
|
|
511
|
+
let o;
|
|
506
512
|
switch (r) {
|
|
507
513
|
case "sec":
|
|
508
514
|
case "secs":
|
|
509
515
|
case "second":
|
|
510
516
|
case "seconds":
|
|
511
517
|
case "s":
|
|
512
|
-
|
|
518
|
+
o = Math.round(n);
|
|
513
519
|
break;
|
|
514
520
|
case "minute":
|
|
515
521
|
case "minutes":
|
|
516
522
|
case "min":
|
|
517
523
|
case "mins":
|
|
518
524
|
case "m":
|
|
519
|
-
|
|
525
|
+
o = Math.round(n * q);
|
|
520
526
|
break;
|
|
521
527
|
case "hour":
|
|
522
528
|
case "hours":
|
|
523
529
|
case "hr":
|
|
524
530
|
case "hrs":
|
|
525
531
|
case "h":
|
|
526
|
-
|
|
532
|
+
o = Math.round(n * z);
|
|
527
533
|
break;
|
|
528
534
|
case "day":
|
|
529
535
|
case "days":
|
|
530
536
|
case "d":
|
|
531
|
-
|
|
537
|
+
o = Math.round(n * J);
|
|
532
538
|
break;
|
|
533
539
|
case "week":
|
|
534
540
|
case "weeks":
|
|
535
541
|
case "w":
|
|
536
|
-
|
|
542
|
+
o = Math.round(n * Ae);
|
|
537
543
|
break;
|
|
538
544
|
default:
|
|
539
|
-
|
|
545
|
+
o = Math.round(n * Ie);
|
|
540
546
|
break;
|
|
541
547
|
}
|
|
542
|
-
return t[1] === "-" || t[4] === "ago" ? -
|
|
548
|
+
return t[1] === "-" || t[4] === "ago" ? -o : o;
|
|
543
549
|
}, $ = (e) => e.toLowerCase().replace(/^application\//, ""), Ce = (e, t) => typeof e == "string" ? t.includes(e) : Array.isArray(e) ? t.some(Set.prototype.has.bind(new Set(e))) : !1, Te = (e, t, n = {}) => {
|
|
544
550
|
let r;
|
|
545
551
|
try {
|
|
@@ -548,15 +554,15 @@ const ge = (e) => Math.floor(e.getTime() / 1e3), q = 60, z = q * 60, J = z * 24,
|
|
|
548
554
|
}
|
|
549
555
|
if (!x(r))
|
|
550
556
|
throw new B("JWT Claims Set must be a top-level JSON object");
|
|
551
|
-
const { typ:
|
|
552
|
-
if (
|
|
557
|
+
const { typ: o } = n;
|
|
558
|
+
if (o && (typeof e.typ != "string" || $(e.typ) !== $(o)))
|
|
553
559
|
throw new h('unexpected "typ" JWT header value', r, "typ", "check_failed");
|
|
554
|
-
const { requiredClaims: i = [], issuer:
|
|
555
|
-
p !== void 0 &&
|
|
556
|
-
for (const l of new Set(
|
|
560
|
+
const { requiredClaims: i = [], issuer: a, subject: c, audience: s, maxTokenAge: p } = n, w = [...i];
|
|
561
|
+
p !== void 0 && w.push("iat"), s !== void 0 && w.push("aud"), c !== void 0 && w.push("sub"), a !== void 0 && w.push("iss");
|
|
562
|
+
for (const l of new Set(w.reverse()))
|
|
557
563
|
if (!(l in r))
|
|
558
564
|
throw new h(`missing required "${l}" claim`, r, l, "missing");
|
|
559
|
-
if (
|
|
565
|
+
if (a && !(Array.isArray(a) ? a : [a]).includes(r.iss))
|
|
560
566
|
throw new h('unexpected "iss" claim value', r, "iss", "check_failed");
|
|
561
567
|
if (c && r.sub !== c)
|
|
562
568
|
throw new h('unexpected "sub" claim value', r, "sub", "check_failed");
|
|
@@ -565,7 +571,7 @@ const ge = (e) => Math.floor(e.getTime() / 1e3), q = 60, z = q * 60, J = z * 24,
|
|
|
565
571
|
let f;
|
|
566
572
|
switch (typeof n.clockTolerance) {
|
|
567
573
|
case "string":
|
|
568
|
-
f =
|
|
574
|
+
f = W(n.clockTolerance);
|
|
569
575
|
break;
|
|
570
576
|
case "number":
|
|
571
577
|
f = n.clockTolerance;
|
|
@@ -576,7 +582,7 @@ const ge = (e) => Math.floor(e.getTime() / 1e3), q = 60, z = q * 60, J = z * 24,
|
|
|
576
582
|
default:
|
|
577
583
|
throw new TypeError("Invalid clockTolerance option type");
|
|
578
584
|
}
|
|
579
|
-
const { currentDate:
|
|
585
|
+
const { currentDate: U } = n, y = ge(U || /* @__PURE__ */ new Date());
|
|
580
586
|
if ((r.iat !== void 0 || p) && typeof r.iat != "number")
|
|
581
587
|
throw new h('"iat" claim must be a number', r, "iat", "invalid");
|
|
582
588
|
if (r.nbf !== void 0) {
|
|
@@ -592,7 +598,7 @@ const ge = (e) => Math.floor(e.getTime() / 1e3), q = 60, z = q * 60, J = z * 24,
|
|
|
592
598
|
throw new D('"exp" claim timestamp check failed', r, "exp", "check_failed");
|
|
593
599
|
}
|
|
594
600
|
if (p) {
|
|
595
|
-
const l = y - r.iat, T = typeof p == "number" ? p :
|
|
601
|
+
const l = y - r.iat, T = typeof p == "number" ? p : W(p);
|
|
596
602
|
if (l - f > T)
|
|
597
603
|
throw new D('"iat" claim timestamp check failed (too far in the past)', r, "iat", "check_failed");
|
|
598
604
|
if (l < 0 - f)
|
|
@@ -601,18 +607,18 @@ const ge = (e) => Math.floor(e.getTime() / 1e3), q = 60, z = q * 60, J = z * 24,
|
|
|
601
607
|
return r;
|
|
602
608
|
};
|
|
603
609
|
async function Re(e, t, n) {
|
|
604
|
-
var
|
|
610
|
+
var a;
|
|
605
611
|
const r = await be(e, t, n);
|
|
606
|
-
if ((
|
|
612
|
+
if ((a = r.protectedHeader.crit) != null && a.includes("b64") && r.protectedHeader.b64 === !1)
|
|
607
613
|
throw new B("JWTs MUST NOT use unencoded payload");
|
|
608
614
|
const i = { payload: Te(r.protectedHeader, r.payload, n), protectedHeader: r.protectedHeader };
|
|
609
615
|
return typeof t == "function" ? { ...i, key: r.key } : i;
|
|
610
616
|
}
|
|
611
617
|
const We = async (e) => {
|
|
612
618
|
try {
|
|
613
|
-
const t =
|
|
619
|
+
const t = K.ALG, r = await ue(X, t);
|
|
614
620
|
return await Re(e, r, {
|
|
615
|
-
issuer:
|
|
621
|
+
issuer: K.ISSUER
|
|
616
622
|
});
|
|
617
623
|
} catch {
|
|
618
624
|
return;
|
|
@@ -641,7 +647,7 @@ function k(e, t, n) {
|
|
|
641
647
|
var r = e.random || (e.rng || xe)();
|
|
642
648
|
return r[6] = r[6] & 15 | 64, r[8] = r[8] & 63 | 128, ve(r);
|
|
643
649
|
}
|
|
644
|
-
const M = globalThis.crypto, Je = (e) => `${k()}${k()}`.slice(0, e),
|
|
650
|
+
const M = globalThis.crypto, Je = (e) => `${k()}${k()}`.slice(0, e), Ue = (e) => btoa(
|
|
645
651
|
[...new Uint8Array(e)].map((t) => String.fromCharCode(t)).join("")
|
|
646
652
|
);
|
|
647
653
|
async function Q(e) {
|
|
@@ -650,9 +656,9 @@ async function Q(e) {
|
|
|
650
656
|
"crypto.subtle is available only in secure contexts (HTTPS)."
|
|
651
657
|
);
|
|
652
658
|
const t = new TextEncoder().encode(e), n = await M.subtle.digest("SHA-256", t);
|
|
653
|
-
return
|
|
659
|
+
return Ue(n).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
654
660
|
}
|
|
655
|
-
async function
|
|
661
|
+
async function $e(e) {
|
|
656
662
|
const t = e || 43;
|
|
657
663
|
if (t < 43 || t > 128)
|
|
658
664
|
throw `Expected a length between 43 and 128. Received ${e}.`;
|
|
@@ -662,17 +668,18 @@ async function He(e) {
|
|
|
662
668
|
code_challenge: r
|
|
663
669
|
};
|
|
664
670
|
}
|
|
665
|
-
async function
|
|
666
|
-
return await Q(e)
|
|
671
|
+
async function Le(e, t) {
|
|
672
|
+
return t === await Q(e);
|
|
667
673
|
}
|
|
668
674
|
export {
|
|
669
|
-
|
|
675
|
+
Ne as API_TYPE,
|
|
676
|
+
Ke as AUTH_TYPES,
|
|
670
677
|
De as HEADERS,
|
|
671
|
-
|
|
678
|
+
K as JWT,
|
|
672
679
|
X as JWT_PUBLIC_KEY,
|
|
673
|
-
|
|
680
|
+
He as TOKEN_EXPIRATION,
|
|
674
681
|
Q as generateCodeChallenge,
|
|
675
|
-
|
|
682
|
+
$e as pkceChallengePair,
|
|
676
683
|
We as verifyAndExtractToken,
|
|
677
|
-
|
|
684
|
+
Le as verifyChallenge
|
|
678
685
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@versini/auth-common",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.8.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Arno Versini",
|
|
6
6
|
"publishConfig": {
|
|
@@ -35,5 +35,5 @@
|
|
|
35
35
|
"jose": "5.4.1",
|
|
36
36
|
"uuid": "10.0.0"
|
|
37
37
|
},
|
|
38
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "2a2665c70c76f0ee6772124b4703ac1bf3446435"
|
|
39
39
|
}
|