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