@versini/auth-common 3.1.0 → 3.2.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 +3 -1
- package/dist/index.js +102 -93
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -94,4 +94,6 @@ type GetToken = {
|
|
|
94
94
|
};
|
|
95
95
|
declare const getToken: ({ headers, body, clientId }: GetToken) => string;
|
|
96
96
|
|
|
97
|
-
|
|
97
|
+
declare const isGranted: (token: string, scopes: string[]) => Promise<boolean>;
|
|
98
|
+
|
|
99
|
+
export { API_TYPE, AUTH_TYPES, BODY, type BodyLike, HEADERS, type HeadersLike, JWT, JWT_PUBLIC_KEY, TOKEN_EXPIRATION, decodeToken, generateCodeChallenge, getToken, isGranted, pkceChallengePair, verifyAndExtractToken, verifyChallenge };
|
package/dist/index.js
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
@versini/auth-common v3.
|
|
2
|
+
@versini/auth-common v3.2.0
|
|
3
3
|
© 2024 gizmette.com
|
|
4
4
|
*/
|
|
5
5
|
try {
|
|
6
6
|
window.__VERSINI_AUTH_COMMON__ || (window.__VERSINI_AUTH_COMMON__ = {
|
|
7
|
-
version: "3.
|
|
8
|
-
buildTime: "07/21/2024
|
|
7
|
+
version: "3.2.0",
|
|
8
|
+
buildTime: "07/21/2024 03:41 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 je = {
|
|
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
|
-
},
|
|
21
|
+
}, et = {
|
|
22
22
|
CLIENT_ID: "X-Auth-ClientId"
|
|
23
23
|
}, ne = {
|
|
24
24
|
ACCESS_TOKEN: "access_token"
|
|
25
|
-
},
|
|
25
|
+
}, I = {
|
|
26
26
|
ALG: "RS256",
|
|
27
27
|
USER_ID_KEY: "sub",
|
|
28
28
|
TOKEN_ID_KEY: "__raw",
|
|
@@ -41,15 +41,15 @@ aMwPFOIcJH+rKfFgNcHLcaS5syp7zU1ANwZ+trgR+DifBr8TLVkBynmNeTyhDm2+
|
|
|
41
41
|
l0haqjMk0UoNPPE8iYBWUHQJJE1Dqstj65d6Eh5g64Pao25y4cmYJbKjiblIGEkE
|
|
42
42
|
sjqybA9mARAqh9k/eiIopecWSiffNQTwVQVd2I9ZH3BalhEXHlqFgrjz51kFqg81
|
|
43
43
|
awIDAQAB
|
|
44
|
-
-----END PUBLIC KEY-----`,
|
|
44
|
+
-----END PUBLIC KEY-----`, tt = {
|
|
45
45
|
ACCESS: "5m",
|
|
46
46
|
ID: "90d",
|
|
47
47
|
REFRESH: "90d"
|
|
48
|
-
},
|
|
48
|
+
}, rt = {
|
|
49
49
|
AUTHENTICATE: "authenticate",
|
|
50
50
|
CODE: "code",
|
|
51
51
|
LOGOUT: "logout"
|
|
52
|
-
},
|
|
52
|
+
}, O = crypto, G = (e) => e instanceof CryptoKey, T = new TextEncoder(), C = new TextDecoder();
|
|
53
53
|
function oe(...e) {
|
|
54
54
|
const t = e.reduce((a, { length: i }) => a + i, 0), r = new Uint8Array(t);
|
|
55
55
|
let n = 0;
|
|
@@ -139,10 +139,10 @@ class se extends A {
|
|
|
139
139
|
function m(e, t = "algorithm.name") {
|
|
140
140
|
return new TypeError(`CryptoKey does not support this operation, its ${t} must be ${e}`);
|
|
141
141
|
}
|
|
142
|
-
function
|
|
142
|
+
function _(e, t) {
|
|
143
143
|
return e.name === t;
|
|
144
144
|
}
|
|
145
|
-
function
|
|
145
|
+
function W(e) {
|
|
146
146
|
return parseInt(e.name.slice(4), 10);
|
|
147
147
|
}
|
|
148
148
|
function de(e) {
|
|
@@ -172,30 +172,30 @@ function le(e, t, ...r) {
|
|
|
172
172
|
case "HS256":
|
|
173
173
|
case "HS384":
|
|
174
174
|
case "HS512": {
|
|
175
|
-
if (!
|
|
175
|
+
if (!_(e.algorithm, "HMAC"))
|
|
176
176
|
throw m("HMAC");
|
|
177
177
|
const n = parseInt(t.slice(2), 10);
|
|
178
|
-
if (
|
|
178
|
+
if (W(e.algorithm.hash) !== n)
|
|
179
179
|
throw m(`SHA-${n}`, "algorithm.hash");
|
|
180
180
|
break;
|
|
181
181
|
}
|
|
182
182
|
case "RS256":
|
|
183
183
|
case "RS384":
|
|
184
184
|
case "RS512": {
|
|
185
|
-
if (!
|
|
185
|
+
if (!_(e.algorithm, "RSASSA-PKCS1-v1_5"))
|
|
186
186
|
throw m("RSASSA-PKCS1-v1_5");
|
|
187
187
|
const n = parseInt(t.slice(2), 10);
|
|
188
|
-
if (
|
|
188
|
+
if (W(e.algorithm.hash) !== n)
|
|
189
189
|
throw m(`SHA-${n}`, "algorithm.hash");
|
|
190
190
|
break;
|
|
191
191
|
}
|
|
192
192
|
case "PS256":
|
|
193
193
|
case "PS384":
|
|
194
194
|
case "PS512": {
|
|
195
|
-
if (!
|
|
195
|
+
if (!_(e.algorithm, "RSA-PSS"))
|
|
196
196
|
throw m("RSA-PSS");
|
|
197
197
|
const n = parseInt(t.slice(2), 10);
|
|
198
|
-
if (
|
|
198
|
+
if (W(e.algorithm.hash) !== n)
|
|
199
199
|
throw m(`SHA-${n}`, "algorithm.hash");
|
|
200
200
|
break;
|
|
201
201
|
}
|
|
@@ -207,7 +207,7 @@ function le(e, t, ...r) {
|
|
|
207
207
|
case "ES256":
|
|
208
208
|
case "ES384":
|
|
209
209
|
case "ES512": {
|
|
210
|
-
if (!
|
|
210
|
+
if (!_(e.algorithm, "ECDSA"))
|
|
211
211
|
throw m("ECDSA");
|
|
212
212
|
const n = de(t);
|
|
213
213
|
if (e.algorithm.namedCurve !== n)
|
|
@@ -219,7 +219,7 @@ function le(e, t, ...r) {
|
|
|
219
219
|
}
|
|
220
220
|
ue(e, r);
|
|
221
221
|
}
|
|
222
|
-
function
|
|
222
|
+
function q(e, t, ...r) {
|
|
223
223
|
var n;
|
|
224
224
|
if (r.length > 2) {
|
|
225
225
|
const a = r.pop();
|
|
@@ -227,11 +227,11 @@ function z(e, t, ...r) {
|
|
|
227
227
|
} else r.length === 2 ? e += `one of type ${r[0]} or ${r[1]}.` : e += `of type ${r[0]}.`;
|
|
228
228
|
return t == null ? e += ` Received ${t}` : typeof t == "function" && t.name ? e += ` Received function ${t.name}` : typeof t == "object" && t != null && (n = t.constructor) != null && n.name && (e += ` Received an instance of ${t.constructor.name}`), e;
|
|
229
229
|
}
|
|
230
|
-
const L = (e, ...t) =>
|
|
231
|
-
function
|
|
232
|
-
return
|
|
230
|
+
const L = (e, ...t) => q("Key must be ", e, ...t);
|
|
231
|
+
function z(e, t, ...r) {
|
|
232
|
+
return q(`Key for the ${e} algorithm must be `, t, ...r);
|
|
233
233
|
}
|
|
234
|
-
const X = (e) =>
|
|
234
|
+
const X = (e) => G(e) ? !0 : (e == null ? void 0 : e[Symbol.toStringTag]) === "KeyObject", R = ["CryptoKey"], fe = (...e) => {
|
|
235
235
|
const t = e.filter(Boolean);
|
|
236
236
|
if (t.length === 0 || t.length === 1)
|
|
237
237
|
return !0;
|
|
@@ -253,7 +253,7 @@ const X = (e) => q(e) ? !0 : (e == null ? void 0 : e[Symbol.toStringTag]) === "K
|
|
|
253
253
|
function he(e) {
|
|
254
254
|
return typeof e == "object" && e !== null;
|
|
255
255
|
}
|
|
256
|
-
function
|
|
256
|
+
function K(e) {
|
|
257
257
|
if (!he(e) || Object.prototype.toString.call(e) !== "[object Object]")
|
|
258
258
|
return !1;
|
|
259
259
|
if (Object.getPrototypeOf(e) === null)
|
|
@@ -350,9 +350,9 @@ const Se = async (e) => {
|
|
|
350
350
|
e.ext ?? !1,
|
|
351
351
|
e.key_ops ?? r
|
|
352
352
|
], a = { ...e };
|
|
353
|
-
return delete a.alg, delete a.use,
|
|
353
|
+
return delete a.alg, delete a.use, O.subtle.importKey("jwk", a, ...n);
|
|
354
354
|
}, Q = (e) => b(e);
|
|
355
|
-
let
|
|
355
|
+
let J, D;
|
|
356
356
|
const Z = (e) => (e == null ? void 0 : e[Symbol.toStringTag]) === "KeyObject", j = async (e, t, r, n) => {
|
|
357
357
|
let a = e.get(t);
|
|
358
358
|
if (a != null && a[n])
|
|
@@ -362,13 +362,13 @@ const Z = (e) => (e == null ? void 0 : e[Symbol.toStringTag]) === "KeyObject", j
|
|
|
362
362
|
}, ye = (e, t) => {
|
|
363
363
|
if (Z(e)) {
|
|
364
364
|
let r = e.export({ format: "jwk" });
|
|
365
|
-
return delete r.d, delete r.dp, delete r.dq, delete r.p, delete r.q, delete r.qi, r.k ? Q(r.k) : (
|
|
365
|
+
return delete r.d, delete r.dp, delete r.dq, delete r.p, delete r.q, delete r.qi, r.k ? Q(r.k) : (D || (D = /* @__PURE__ */ new WeakMap()), j(D, e, r, t));
|
|
366
366
|
}
|
|
367
367
|
return e;
|
|
368
368
|
}, Ee = (e, t) => {
|
|
369
369
|
if (Z(e)) {
|
|
370
370
|
let r = e.export({ format: "jwk" });
|
|
371
|
-
return r.k ? Q(r.k) : (
|
|
371
|
+
return r.k ? Q(r.k) : (J || (J = /* @__PURE__ */ new WeakMap()), j(J, e, r, t));
|
|
372
372
|
}
|
|
373
373
|
return e;
|
|
374
374
|
}, we = { normalizePublicKey: ye, normalizePrivateKey: Ee }, E = (e, t, r = 0) => {
|
|
@@ -378,7 +378,7 @@ const Z = (e) => (e == null ? void 0 : e[Symbol.toStringTag]) === "KeyObject", j
|
|
|
378
378
|
return !1;
|
|
379
379
|
const a = e.subarray(n, n + t.length);
|
|
380
380
|
return a.length !== t.length ? !1 : a.every((i, o) => i === t[o]) || E(e, t, n + 1);
|
|
381
|
-
},
|
|
381
|
+
}, k = (e) => {
|
|
382
382
|
switch (!0) {
|
|
383
383
|
case E(e, [42, 134, 72, 206, 61, 3, 1, 7]):
|
|
384
384
|
return "P-256";
|
|
@@ -433,43 +433,43 @@ const Z = (e) => (e == null ? void 0 : e[Symbol.toStringTag]) === "KeyObject", j
|
|
|
433
433
|
case "ECDH-ES+A128KW":
|
|
434
434
|
case "ECDH-ES+A192KW":
|
|
435
435
|
case "ECDH-ES+A256KW": {
|
|
436
|
-
const s =
|
|
436
|
+
const s = k(c);
|
|
437
437
|
i = s.startsWith("P-") ? { name: "ECDH", namedCurve: s } : { name: s }, o = [];
|
|
438
438
|
break;
|
|
439
439
|
}
|
|
440
440
|
case "EdDSA":
|
|
441
|
-
i = { name:
|
|
441
|
+
i = { name: k(c) }, o = ["verify"];
|
|
442
442
|
break;
|
|
443
443
|
default:
|
|
444
444
|
throw new w('Invalid or unsupported "alg" (Algorithm) value');
|
|
445
445
|
}
|
|
446
|
-
return
|
|
446
|
+
return O.subtle.importKey(t, c, i, !1, o);
|
|
447
447
|
}, Ae = (e, t, r) => ge(/(?:-----(?:BEGIN|END) PUBLIC KEY-----|\s)/g, "spki", e, t);
|
|
448
448
|
async function be(e, t, r) {
|
|
449
449
|
if (e.indexOf("-----BEGIN PUBLIC KEY-----") !== 0)
|
|
450
450
|
throw new TypeError('"spki" must be SPKI formatted string');
|
|
451
451
|
return Ae(e, t);
|
|
452
452
|
}
|
|
453
|
-
const
|
|
453
|
+
const P = (e) => e == null ? void 0 : e[Symbol.toStringTag], Ce = (e, t) => {
|
|
454
454
|
if (!(t instanceof Uint8Array)) {
|
|
455
455
|
if (!X(t))
|
|
456
|
-
throw new TypeError(
|
|
456
|
+
throw new TypeError(z(e, t, ...R, "Uint8Array"));
|
|
457
457
|
if (t.type !== "secret")
|
|
458
|
-
throw new TypeError(`${
|
|
458
|
+
throw new TypeError(`${P(t)} instances for symmetric algorithms must be of type "secret"`);
|
|
459
459
|
}
|
|
460
460
|
}, Te = (e, t, r) => {
|
|
461
461
|
if (!X(t))
|
|
462
|
-
throw new TypeError(
|
|
462
|
+
throw new TypeError(z(e, t, ...R));
|
|
463
463
|
if (t.type === "secret")
|
|
464
|
-
throw new TypeError(`${
|
|
464
|
+
throw new TypeError(`${P(t)} instances for asymmetric algorithms must not be of type "secret"`);
|
|
465
465
|
if (t.algorithm && r === "verify" && t.type === "private")
|
|
466
|
-
throw new TypeError(`${
|
|
466
|
+
throw new TypeError(`${P(t)} instances for asymmetric algorithm verifying must be of type "public"`);
|
|
467
467
|
if (t.algorithm && r === "encrypt" && t.type === "private")
|
|
468
|
-
throw new TypeError(`${
|
|
469
|
-
},
|
|
468
|
+
throw new TypeError(`${P(t)} instances for asymmetric algorithm encryption must be of type "public"`);
|
|
469
|
+
}, _e = (e, t, r) => {
|
|
470
470
|
e.startsWith("HS") || e === "dir" || e.startsWith("PBES2") || /^A\d{3}(?:GCM)?KW$/.test(e) ? Ce(e, t) : Te(e, t, r);
|
|
471
471
|
};
|
|
472
|
-
function
|
|
472
|
+
function ve(e, t, r, n, a) {
|
|
473
473
|
if (a.crit !== void 0 && (n == null ? void 0 : n.crit) === void 0)
|
|
474
474
|
throw new e('"crit" (Critical) Header Parameter MUST be integrity protected');
|
|
475
475
|
if (!n || n.crit === void 0)
|
|
@@ -488,13 +488,13 @@ function _e(e, t, r, n, a) {
|
|
|
488
488
|
}
|
|
489
489
|
return new Set(n.crit);
|
|
490
490
|
}
|
|
491
|
-
const
|
|
491
|
+
const Pe = (e, t) => {
|
|
492
492
|
if (t !== void 0 && (!Array.isArray(t) || t.some((r) => typeof r != "string")))
|
|
493
493
|
throw new TypeError(`"${e}" option must be an array of strings`);
|
|
494
494
|
if (t)
|
|
495
495
|
return new Set(t);
|
|
496
496
|
};
|
|
497
|
-
function
|
|
497
|
+
function Ie(e, t) {
|
|
498
498
|
const r = `SHA-${e.slice(-3)}`;
|
|
499
499
|
switch (e) {
|
|
500
500
|
case "HS256":
|
|
@@ -519,28 +519,28 @@ function Re(e, t) {
|
|
|
519
519
|
throw new w(`alg ${e} is not supported either by JOSE or your javascript runtime`);
|
|
520
520
|
}
|
|
521
521
|
}
|
|
522
|
-
async function
|
|
523
|
-
if (t = await we.normalizePublicKey(t, e),
|
|
522
|
+
async function Re(e, t, r) {
|
|
523
|
+
if (t = await we.normalizePublicKey(t, e), G(t))
|
|
524
524
|
return le(t, e, r), t;
|
|
525
525
|
if (t instanceof Uint8Array) {
|
|
526
526
|
if (!e.startsWith("HS"))
|
|
527
527
|
throw new TypeError(L(t, ...R));
|
|
528
|
-
return
|
|
528
|
+
return O.subtle.importKey("raw", t, { hash: `SHA-${e.slice(-3)}`, name: "HMAC" }, !1, [r]);
|
|
529
529
|
}
|
|
530
530
|
throw new TypeError(L(t, ...R, "Uint8Array"));
|
|
531
531
|
}
|
|
532
532
|
const Ke = async (e, t, r, n) => {
|
|
533
|
-
const a = await
|
|
533
|
+
const a = await Re(e, t, "verify");
|
|
534
534
|
pe(e, a);
|
|
535
|
-
const i =
|
|
535
|
+
const i = Ie(e, a.algorithm);
|
|
536
536
|
try {
|
|
537
|
-
return await
|
|
537
|
+
return await O.subtle.verify(i, a, r, n);
|
|
538
538
|
} catch {
|
|
539
539
|
return !1;
|
|
540
540
|
}
|
|
541
541
|
};
|
|
542
542
|
async function Oe(e, t, r) {
|
|
543
|
-
if (!
|
|
543
|
+
if (!K(e))
|
|
544
544
|
throw new u("Flattened JWS must be an object");
|
|
545
545
|
if (e.protected === void 0 && e.header === void 0)
|
|
546
546
|
throw new u('Flattened JWS must have either of the "protected" or "header" members');
|
|
@@ -550,13 +550,13 @@ async function Oe(e, t, r) {
|
|
|
550
550
|
throw new u("JWS Payload missing");
|
|
551
551
|
if (typeof e.signature != "string")
|
|
552
552
|
throw new u("JWS Signature missing or incorrect type");
|
|
553
|
-
if (e.header !== void 0 && !
|
|
553
|
+
if (e.header !== void 0 && !K(e.header))
|
|
554
554
|
throw new u("JWS Unprotected Header incorrect type");
|
|
555
555
|
let n = {};
|
|
556
556
|
if (e.protected)
|
|
557
557
|
try {
|
|
558
|
-
const
|
|
559
|
-
n = JSON.parse(C.decode(
|
|
558
|
+
const x = b(e.protected);
|
|
559
|
+
n = JSON.parse(C.decode(x));
|
|
560
560
|
} catch {
|
|
561
561
|
throw new u("JWS Protected Header is invalid");
|
|
562
562
|
}
|
|
@@ -565,14 +565,14 @@ async function Oe(e, t, r) {
|
|
|
565
565
|
const a = {
|
|
566
566
|
...n,
|
|
567
567
|
...e.header
|
|
568
|
-
}, i =
|
|
568
|
+
}, i = ve(u, /* @__PURE__ */ new Map([["b64", !0]]), r == null ? void 0 : r.crit, n, a);
|
|
569
569
|
let o = !0;
|
|
570
570
|
if (i.has("b64") && (o = n.b64, typeof o != "boolean"))
|
|
571
571
|
throw new u('The "b64" (base64url-encode payload) Header Parameter must be a boolean');
|
|
572
572
|
const { alg: c } = a;
|
|
573
573
|
if (typeof c != "string" || !c)
|
|
574
574
|
throw new u('JWS "alg" (Algorithm) Header Parameter missing or invalid');
|
|
575
|
-
const s = r &&
|
|
575
|
+
const s = r && Pe("algorithms", r.algorithms);
|
|
576
576
|
if (s && !s.has(c))
|
|
577
577
|
throw new ce('"alg" (Algorithm) Header Parameter value not allowed');
|
|
578
578
|
if (o) {
|
|
@@ -581,7 +581,7 @@ async function Oe(e, t, r) {
|
|
|
581
581
|
} else if (typeof e.payload != "string" && !(e.payload instanceof Uint8Array))
|
|
582
582
|
throw new u("JWS Payload must be a string or an Uint8Array instance");
|
|
583
583
|
let p = !1;
|
|
584
|
-
typeof t == "function" && (t = await t(n, e), p = !0),
|
|
584
|
+
typeof t == "function" && (t = await t(n, e), p = !0), _e(c, t, "verify");
|
|
585
585
|
const g = oe(T.encode(e.protected ?? ""), T.encode("."), typeof e.payload == "string" ? T.encode(e.payload) : e.payload);
|
|
586
586
|
let f;
|
|
587
587
|
try {
|
|
@@ -611,7 +611,7 @@ async function xe(e, t, r) {
|
|
|
611
611
|
const c = await Oe({ payload: a, protected: n, signature: i }, t, r), s = { payload: c.payload, protectedHeader: c.protectedHeader };
|
|
612
612
|
return typeof t == "function" ? { ...s, key: c.key } : s;
|
|
613
613
|
}
|
|
614
|
-
const We = (e) => Math.floor(e.getTime() / 1e3), ee = 60, te = ee * 60,
|
|
614
|
+
const We = (e) => Math.floor(e.getTime() / 1e3), ee = 60, te = ee * 60, N = te * 24, Je = N * 7, De = N * 365.25, He = /^(\+|\-)? ?(\d+|\d+\.\d+) ?(seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)(?: (ago|from now))?$/i, M = (e) => {
|
|
615
615
|
const t = He.exec(e);
|
|
616
616
|
if (!t || t[4] && t[1])
|
|
617
617
|
throw new TypeError("Invalid time period format");
|
|
@@ -642,7 +642,7 @@ const We = (e) => Math.floor(e.getTime() / 1e3), ee = 60, te = ee * 60, H = te *
|
|
|
642
642
|
case "day":
|
|
643
643
|
case "days":
|
|
644
644
|
case "d":
|
|
645
|
-
a = Math.round(r *
|
|
645
|
+
a = Math.round(r * N);
|
|
646
646
|
break;
|
|
647
647
|
case "week":
|
|
648
648
|
case "weeks":
|
|
@@ -660,7 +660,7 @@ const We = (e) => Math.floor(e.getTime() / 1e3), ee = 60, te = ee * 60, H = te *
|
|
|
660
660
|
n = JSON.parse(C.decode(t));
|
|
661
661
|
} catch {
|
|
662
662
|
}
|
|
663
|
-
if (!
|
|
663
|
+
if (!K(n))
|
|
664
664
|
throw new S("JWT Claims Set must be a top-level JSON object");
|
|
665
665
|
const { typ: a } = r;
|
|
666
666
|
if (a && (typeof e.typ != "string" || B(e.typ) !== B(a)))
|
|
@@ -679,7 +679,7 @@ const We = (e) => Math.floor(e.getTime() / 1e3), ee = 60, te = ee * 60, H = te *
|
|
|
679
679
|
let f;
|
|
680
680
|
switch (typeof r.clockTolerance) {
|
|
681
681
|
case "string":
|
|
682
|
-
f =
|
|
682
|
+
f = M(r.clockTolerance);
|
|
683
683
|
break;
|
|
684
684
|
case "number":
|
|
685
685
|
f = r.clockTolerance;
|
|
@@ -690,7 +690,7 @@ const We = (e) => Math.floor(e.getTime() / 1e3), ee = 60, te = ee * 60, H = te *
|
|
|
690
690
|
default:
|
|
691
691
|
throw new TypeError("Invalid clockTolerance option type");
|
|
692
692
|
}
|
|
693
|
-
const { currentDate:
|
|
693
|
+
const { currentDate: U } = r, y = We(U || /* @__PURE__ */ new Date());
|
|
694
694
|
if ((n.iat !== void 0 || p) && typeof n.iat != "number")
|
|
695
695
|
throw new h('"iat" claim must be a number', n, "iat", "invalid");
|
|
696
696
|
if (n.nbf !== void 0) {
|
|
@@ -706,8 +706,8 @@ const We = (e) => Math.floor(e.getTime() / 1e3), ee = 60, te = ee * 60, H = te *
|
|
|
706
706
|
throw new $('"exp" claim timestamp check failed', n, "exp", "check_failed");
|
|
707
707
|
}
|
|
708
708
|
if (p) {
|
|
709
|
-
const l = y - n.iat,
|
|
710
|
-
if (l - f >
|
|
709
|
+
const l = y - n.iat, x = typeof p == "number" ? p : M(p);
|
|
710
|
+
if (l - f > x)
|
|
711
711
|
throw new $('"iat" claim timestamp check failed (too far in the past)', n, "iat", "check_failed");
|
|
712
712
|
if (l < 0 - f)
|
|
713
713
|
throw new h('"iat" claim timestamp check failed (it should be in the past)', n, "iat", "check_failed");
|
|
@@ -723,7 +723,7 @@ async function $e(e, t, r) {
|
|
|
723
723
|
return typeof t == "function" ? { ...i, key: n.key } : i;
|
|
724
724
|
}
|
|
725
725
|
const Le = b;
|
|
726
|
-
function
|
|
726
|
+
function ke(e) {
|
|
727
727
|
if (typeof e != "string")
|
|
728
728
|
throw new S("JWTs must use Compact JWS serialization, JWT must be a string");
|
|
729
729
|
const { 1: t, length: r } = e.split(".");
|
|
@@ -745,50 +745,50 @@ function Me(e) {
|
|
|
745
745
|
} catch {
|
|
746
746
|
throw new S("Failed to parse the decoded payload as JSON");
|
|
747
747
|
}
|
|
748
|
-
if (!
|
|
748
|
+
if (!K(a))
|
|
749
749
|
throw new S("Invalid JWT Claims Set");
|
|
750
750
|
return a;
|
|
751
751
|
}
|
|
752
|
-
const
|
|
752
|
+
const Me = async (e) => {
|
|
753
753
|
try {
|
|
754
|
-
const t =
|
|
754
|
+
const t = I.ALG, n = await be(ae, t);
|
|
755
755
|
return await $e(e, n, {
|
|
756
|
-
issuer:
|
|
756
|
+
issuer: I.ISSUER
|
|
757
757
|
});
|
|
758
758
|
} catch {
|
|
759
759
|
return;
|
|
760
760
|
}
|
|
761
761
|
}, nt = (e) => {
|
|
762
762
|
try {
|
|
763
|
-
return
|
|
763
|
+
return ke(e);
|
|
764
764
|
} catch {
|
|
765
765
|
return;
|
|
766
766
|
}
|
|
767
767
|
};
|
|
768
768
|
var d = [];
|
|
769
|
-
for (var
|
|
770
|
-
d.push((
|
|
771
|
-
function
|
|
769
|
+
for (var H = 0; H < 256; ++H)
|
|
770
|
+
d.push((H + 256).toString(16).slice(1));
|
|
771
|
+
function Be(e, t = 0) {
|
|
772
772
|
return (d[e[t + 0]] + d[e[t + 1]] + d[e[t + 2]] + d[e[t + 3]] + "-" + d[e[t + 4]] + d[e[t + 5]] + "-" + d[e[t + 6]] + d[e[t + 7]] + "-" + d[e[t + 8]] + d[e[t + 9]] + "-" + d[e[t + 10]] + d[e[t + 11]] + d[e[t + 12]] + d[e[t + 13]] + d[e[t + 14]] + d[e[t + 15]]).toLowerCase();
|
|
773
773
|
}
|
|
774
|
-
var
|
|
775
|
-
function
|
|
776
|
-
if (!
|
|
774
|
+
var v, Fe = new Uint8Array(16);
|
|
775
|
+
function Ve() {
|
|
776
|
+
if (!v && (v = typeof crypto < "u" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto), !v))
|
|
777
777
|
throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
|
|
778
|
-
return
|
|
778
|
+
return v(Fe);
|
|
779
779
|
}
|
|
780
|
-
var
|
|
780
|
+
var Ye = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto);
|
|
781
781
|
const F = {
|
|
782
|
-
randomUUID:
|
|
782
|
+
randomUUID: Ye
|
|
783
783
|
};
|
|
784
784
|
function V(e, t, r) {
|
|
785
785
|
if (F.randomUUID && !t && !e)
|
|
786
786
|
return F.randomUUID();
|
|
787
787
|
e = e || {};
|
|
788
|
-
var n = e.random || (e.rng ||
|
|
789
|
-
return n[6] = n[6] & 15 | 64, n[8] = n[8] & 63 | 128,
|
|
788
|
+
var n = e.random || (e.rng || Ve)();
|
|
789
|
+
return n[6] = n[6] & 15 | 64, n[8] = n[8] & 63 | 128, Be(n);
|
|
790
790
|
}
|
|
791
|
-
const Y = globalThis.crypto,
|
|
791
|
+
const Y = globalThis.crypto, Ge = (e) => `${V()}${V()}`.slice(0, e), qe = (e) => btoa(
|
|
792
792
|
[...new Uint8Array(e)].map((t) => String.fromCharCode(t)).join("")
|
|
793
793
|
);
|
|
794
794
|
async function re(e) {
|
|
@@ -803,7 +803,7 @@ async function at(e) {
|
|
|
803
803
|
const t = e || 43;
|
|
804
804
|
if (t < 43 || t > 128)
|
|
805
805
|
throw `Expected a length between 43 and 128. Received ${e}.`;
|
|
806
|
-
const r =
|
|
806
|
+
const r = Ge(t), n = await re(r);
|
|
807
807
|
return {
|
|
808
808
|
code_verifier: r,
|
|
809
809
|
code_challenge: n
|
|
@@ -812,39 +812,48 @@ async function at(e) {
|
|
|
812
812
|
async function ot(e, t) {
|
|
813
813
|
return t === await re(e);
|
|
814
814
|
}
|
|
815
|
-
const ze = /^Bearer (.+)$/i,
|
|
815
|
+
const ze = /^Bearer (.+)$/i, Xe = (e) => {
|
|
816
816
|
if (typeof (e == null ? void 0 : e.authorization) != "string")
|
|
817
817
|
return;
|
|
818
818
|
const t = e.authorization.match(ze);
|
|
819
819
|
if (t)
|
|
820
820
|
return t[1];
|
|
821
|
-
},
|
|
821
|
+
}, Qe = (e, t) => {
|
|
822
822
|
const r = e == null ? void 0 : e.cookie;
|
|
823
823
|
if (typeof r != "string")
|
|
824
824
|
return;
|
|
825
825
|
const n = new RegExp(`auth.${t}=(.+?)(?:;|$)`), a = r.match(n);
|
|
826
826
|
if (a)
|
|
827
827
|
return a[1];
|
|
828
|
-
},
|
|
828
|
+
}, Ze = (e) => {
|
|
829
829
|
const t = e == null ? void 0 : e[ne.ACCESS_TOKEN];
|
|
830
830
|
if (typeof t == "string")
|
|
831
831
|
return t;
|
|
832
832
|
}, it = ({ headers: e, body: t, clientId: r }) => {
|
|
833
|
-
const n =
|
|
834
|
-
return
|
|
833
|
+
const n = Xe(e), a = Qe(e, r);
|
|
834
|
+
return Ze(t) || a || n || "";
|
|
835
|
+
}, ct = async (e, t) => {
|
|
836
|
+
var n, a;
|
|
837
|
+
const r = await Me(e);
|
|
838
|
+
if ((a = r && ((n = r == null ? void 0 : r.payload) == null ? void 0 : n[I.SCOPES_KEY])) != null && a.length) {
|
|
839
|
+
const i = r.payload[I.SCOPES_KEY];
|
|
840
|
+
return t.every((o) => i.includes(o));
|
|
841
|
+
}
|
|
842
|
+
return !1;
|
|
835
843
|
};
|
|
836
844
|
export {
|
|
837
|
-
|
|
838
|
-
|
|
845
|
+
rt as API_TYPE,
|
|
846
|
+
je as AUTH_TYPES,
|
|
839
847
|
ne as BODY,
|
|
840
|
-
|
|
841
|
-
|
|
848
|
+
et as HEADERS,
|
|
849
|
+
I as JWT,
|
|
842
850
|
ae as JWT_PUBLIC_KEY,
|
|
843
|
-
|
|
851
|
+
tt as TOKEN_EXPIRATION,
|
|
844
852
|
nt as decodeToken,
|
|
845
853
|
re as generateCodeChallenge,
|
|
846
854
|
it as getToken,
|
|
855
|
+
ct as isGranted,
|
|
847
856
|
at as pkceChallengePair,
|
|
848
|
-
|
|
857
|
+
Me as verifyAndExtractToken,
|
|
849
858
|
ot as verifyChallenge
|
|
850
859
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@versini/auth-common",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.2.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Arno Versini",
|
|
6
6
|
"publishConfig": {
|
|
@@ -36,5 +36,5 @@
|
|
|
36
36
|
"jose": "5.6.3",
|
|
37
37
|
"uuid": "10.0.0"
|
|
38
38
|
},
|
|
39
|
-
"gitHead": "
|
|
39
|
+
"gitHead": "57d681a2201591a0623cbbef9dc2edc65f2e3cdc"
|
|
40
40
|
}
|