@versini/auth-common 3.4.0 → 4.0.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 +2 -1
- package/dist/index.js +38 -37
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -34,9 +34,10 @@ declare const TOKEN_EXPIRATION: {
|
|
|
34
34
|
REFRESH: string;
|
|
35
35
|
};
|
|
36
36
|
declare const API_TYPE: {
|
|
37
|
-
AUTHENTICATE: string;
|
|
38
37
|
CODE: string;
|
|
39
38
|
LOGOUT: string;
|
|
39
|
+
LOGIN: string;
|
|
40
|
+
REFRESH: string;
|
|
40
41
|
};
|
|
41
42
|
|
|
42
43
|
declare const verifyAndExtractToken: (token: string) => Promise<jose.JWTVerifyResult<jose.JWTPayload> | undefined>;
|
package/dist/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
@versini/auth-common
|
|
2
|
+
@versini/auth-common v4.0.0
|
|
3
3
|
© 2024 gizmette.com
|
|
4
4
|
*/
|
|
5
5
|
try {
|
|
6
6
|
window.__VERSINI_AUTH_COMMON__ || (window.__VERSINI_AUTH_COMMON__ = {
|
|
7
|
-
version: "
|
|
8
|
-
buildTime: "08/19/2024 11
|
|
7
|
+
version: "4.0.0",
|
|
8
|
+
buildTime: "08/19/2024 06:11 PM EDT",
|
|
9
9
|
homepage: "https://github.com/aversini/auth-client",
|
|
10
10
|
license: "MIT"
|
|
11
11
|
});
|
|
@@ -22,7 +22,7 @@ const 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",
|
|
@@ -47,10 +47,11 @@ awIDAQAB
|
|
|
47
47
|
ID: "90d",
|
|
48
48
|
REFRESH: "90d"
|
|
49
49
|
}, nt = {
|
|
50
|
-
AUTHENTICATE: "authenticate",
|
|
51
50
|
CODE: "code",
|
|
52
|
-
LOGOUT: "logout"
|
|
53
|
-
|
|
51
|
+
LOGOUT: "logout",
|
|
52
|
+
LOGIN: "login",
|
|
53
|
+
REFRESH: "refresh"
|
|
54
|
+
}, O = crypto, G = (e) => e instanceof CryptoKey, _ = new TextEncoder(), C = new TextDecoder();
|
|
54
55
|
function oe(...e) {
|
|
55
56
|
const t = e.reduce((a, { length: o }) => a + o, 0), r = new Uint8Array(t);
|
|
56
57
|
let n = 0;
|
|
@@ -140,7 +141,7 @@ class se extends A {
|
|
|
140
141
|
function m(e, t = "algorithm.name") {
|
|
141
142
|
return new TypeError(`CryptoKey does not support this operation, its ${t} must be ${e}`);
|
|
142
143
|
}
|
|
143
|
-
function
|
|
144
|
+
function v(e, t) {
|
|
144
145
|
return e.name === t;
|
|
145
146
|
}
|
|
146
147
|
function W(e) {
|
|
@@ -173,7 +174,7 @@ function le(e, t, ...r) {
|
|
|
173
174
|
case "HS256":
|
|
174
175
|
case "HS384":
|
|
175
176
|
case "HS512": {
|
|
176
|
-
if (!
|
|
177
|
+
if (!v(e.algorithm, "HMAC"))
|
|
177
178
|
throw m("HMAC");
|
|
178
179
|
const n = parseInt(t.slice(2), 10);
|
|
179
180
|
if (W(e.algorithm.hash) !== n)
|
|
@@ -183,7 +184,7 @@ function le(e, t, ...r) {
|
|
|
183
184
|
case "RS256":
|
|
184
185
|
case "RS384":
|
|
185
186
|
case "RS512": {
|
|
186
|
-
if (!
|
|
187
|
+
if (!v(e.algorithm, "RSASSA-PKCS1-v1_5"))
|
|
187
188
|
throw m("RSASSA-PKCS1-v1_5");
|
|
188
189
|
const n = parseInt(t.slice(2), 10);
|
|
189
190
|
if (W(e.algorithm.hash) !== n)
|
|
@@ -193,7 +194,7 @@ function le(e, t, ...r) {
|
|
|
193
194
|
case "PS256":
|
|
194
195
|
case "PS384":
|
|
195
196
|
case "PS512": {
|
|
196
|
-
if (!
|
|
197
|
+
if (!v(e.algorithm, "RSA-PSS"))
|
|
197
198
|
throw m("RSA-PSS");
|
|
198
199
|
const n = parseInt(t.slice(2), 10);
|
|
199
200
|
if (W(e.algorithm.hash) !== n)
|
|
@@ -208,7 +209,7 @@ function le(e, t, ...r) {
|
|
|
208
209
|
case "ES256":
|
|
209
210
|
case "ES384":
|
|
210
211
|
case "ES512": {
|
|
211
|
-
if (!
|
|
212
|
+
if (!v(e.algorithm, "ECDSA"))
|
|
212
213
|
throw m("ECDSA");
|
|
213
214
|
const n = de(t);
|
|
214
215
|
if (e.algorithm.namedCurve !== n)
|
|
@@ -451,26 +452,26 @@ async function be(e, t, r) {
|
|
|
451
452
|
throw new TypeError('"spki" must be SPKI formatted string');
|
|
452
453
|
return Ae(e, t);
|
|
453
454
|
}
|
|
454
|
-
const
|
|
455
|
+
const R = (e) => e == null ? void 0 : e[Symbol.toStringTag], Ce = (e, t) => {
|
|
455
456
|
if (!(t instanceof Uint8Array)) {
|
|
456
457
|
if (!X(t))
|
|
457
458
|
throw new TypeError(z(e, t, ...P, "Uint8Array"));
|
|
458
459
|
if (t.type !== "secret")
|
|
459
|
-
throw new TypeError(`${
|
|
460
|
+
throw new TypeError(`${R(t)} instances for symmetric algorithms must be of type "secret"`);
|
|
460
461
|
}
|
|
461
|
-
},
|
|
462
|
+
}, _e = (e, t, r) => {
|
|
462
463
|
if (!X(t))
|
|
463
464
|
throw new TypeError(z(e, t, ...P));
|
|
464
465
|
if (t.type === "secret")
|
|
465
|
-
throw new TypeError(`${
|
|
466
|
+
throw new TypeError(`${R(t)} instances for asymmetric algorithms must not be of type "secret"`);
|
|
466
467
|
if (t.algorithm && r === "verify" && t.type === "private")
|
|
467
|
-
throw new TypeError(`${
|
|
468
|
+
throw new TypeError(`${R(t)} instances for asymmetric algorithm verifying must be of type "public"`);
|
|
468
469
|
if (t.algorithm && r === "encrypt" && t.type === "private")
|
|
469
|
-
throw new TypeError(`${
|
|
470
|
-
},
|
|
471
|
-
e.startsWith("HS") || e === "dir" || e.startsWith("PBES2") || /^A\d{3}(?:GCM)?KW$/.test(e) ? Ce(e, t) :
|
|
470
|
+
throw new TypeError(`${R(t)} instances for asymmetric algorithm encryption must be of type "public"`);
|
|
471
|
+
}, ve = (e, t, r) => {
|
|
472
|
+
e.startsWith("HS") || e === "dir" || e.startsWith("PBES2") || /^A\d{3}(?:GCM)?KW$/.test(e) ? Ce(e, t) : _e(e, t, r);
|
|
472
473
|
};
|
|
473
|
-
function
|
|
474
|
+
function Te(e, t, r, n, a) {
|
|
474
475
|
if (a.crit !== void 0 && (n == null ? void 0 : n.crit) === void 0)
|
|
475
476
|
throw new e('"crit" (Critical) Header Parameter MUST be integrity protected');
|
|
476
477
|
if (!n || n.crit === void 0)
|
|
@@ -489,13 +490,13 @@ function ve(e, t, r, n, a) {
|
|
|
489
490
|
}
|
|
490
491
|
return new Set(n.crit);
|
|
491
492
|
}
|
|
492
|
-
const
|
|
493
|
+
const Re = (e, t) => {
|
|
493
494
|
if (t !== void 0 && (!Array.isArray(t) || t.some((r) => typeof r != "string")))
|
|
494
495
|
throw new TypeError(`"${e}" option must be an array of strings`);
|
|
495
496
|
if (t)
|
|
496
497
|
return new Set(t);
|
|
497
498
|
};
|
|
498
|
-
function
|
|
499
|
+
function Ie(e, t) {
|
|
499
500
|
const r = `SHA-${e.slice(-3)}`;
|
|
500
501
|
switch (e) {
|
|
501
502
|
case "HS256":
|
|
@@ -533,7 +534,7 @@ async function Pe(e, t, r) {
|
|
|
533
534
|
const Ke = async (e, t, r, n) => {
|
|
534
535
|
const a = await Pe(e, t, "verify");
|
|
535
536
|
pe(e, a);
|
|
536
|
-
const o =
|
|
537
|
+
const o = Ie(e, a.algorithm);
|
|
537
538
|
try {
|
|
538
539
|
return await O.subtle.verify(o, a, r, n);
|
|
539
540
|
} catch {
|
|
@@ -566,14 +567,14 @@ async function Oe(e, t, r) {
|
|
|
566
567
|
const a = {
|
|
567
568
|
...n,
|
|
568
569
|
...e.header
|
|
569
|
-
}, o =
|
|
570
|
+
}, o = Te(u, /* @__PURE__ */ new Map([["b64", !0]]), r == null ? void 0 : r.crit, n, a);
|
|
570
571
|
let i = !0;
|
|
571
572
|
if (o.has("b64") && (i = n.b64, typeof i != "boolean"))
|
|
572
573
|
throw new u('The "b64" (base64url-encode payload) Header Parameter must be a boolean');
|
|
573
574
|
const { alg: c } = a;
|
|
574
575
|
if (typeof c != "string" || !c)
|
|
575
576
|
throw new u('JWS "alg" (Algorithm) Header Parameter missing or invalid');
|
|
576
|
-
const s = r &&
|
|
577
|
+
const s = r && Re("algorithms", r.algorithms);
|
|
577
578
|
if (s && !s.has(c))
|
|
578
579
|
throw new ce('"alg" (Algorithm) Header Parameter value not allowed');
|
|
579
580
|
if (i) {
|
|
@@ -582,8 +583,8 @@ async function Oe(e, t, r) {
|
|
|
582
583
|
} else if (typeof e.payload != "string" && !(e.payload instanceof Uint8Array))
|
|
583
584
|
throw new u("JWS Payload must be a string or an Uint8Array instance");
|
|
584
585
|
let p = !1;
|
|
585
|
-
typeof t == "function" && (t = await t(n, e), p = !0),
|
|
586
|
-
const g = oe(
|
|
586
|
+
typeof t == "function" && (t = await t(n, e), p = !0), ve(c, t, "verify");
|
|
587
|
+
const g = oe(_.encode(e.protected ?? ""), _.encode("."), typeof e.payload == "string" ? _.encode(e.payload) : e.payload);
|
|
587
588
|
let f;
|
|
588
589
|
try {
|
|
589
590
|
f = b(e.signature);
|
|
@@ -599,7 +600,7 @@ async function Oe(e, t, r) {
|
|
|
599
600
|
} catch {
|
|
600
601
|
throw new u("Failed to base64url decode the payload");
|
|
601
602
|
}
|
|
602
|
-
else typeof e.payload == "string" ? y =
|
|
603
|
+
else typeof e.payload == "string" ? y = _.encode(e.payload) : y = e.payload;
|
|
603
604
|
const l = { payload: y };
|
|
604
605
|
return e.protected !== void 0 && (l.protectedHeader = n), e.header !== void 0 && (l.unprotectedHeader = e.header), p ? { ...l, key: t } : l;
|
|
605
606
|
}
|
|
@@ -752,9 +753,9 @@ function ke(e) {
|
|
|
752
753
|
}
|
|
753
754
|
const Me = async (e) => {
|
|
754
755
|
try {
|
|
755
|
-
const t =
|
|
756
|
+
const t = I.ALG, n = await be(ae, t);
|
|
756
757
|
return await $e(e, n, {
|
|
757
|
-
issuer:
|
|
758
|
+
issuer: I.ISSUER
|
|
758
759
|
});
|
|
759
760
|
} catch {
|
|
760
761
|
return;
|
|
@@ -772,11 +773,11 @@ for (var H = 0; H < 256; ++H)
|
|
|
772
773
|
function Be(e, t = 0) {
|
|
773
774
|
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();
|
|
774
775
|
}
|
|
775
|
-
var
|
|
776
|
+
var T, Fe = new Uint8Array(16);
|
|
776
777
|
function Ye() {
|
|
777
|
-
if (!
|
|
778
|
+
if (!T && (T = typeof crypto < "u" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto), !T))
|
|
778
779
|
throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
|
|
779
|
-
return
|
|
780
|
+
return T(Fe);
|
|
780
781
|
}
|
|
781
782
|
var Ve = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto);
|
|
782
783
|
const F = {
|
|
@@ -836,9 +837,9 @@ const ze = /^Bearer (.+)$/i, Xe = (e) => {
|
|
|
836
837
|
}, st = async (e, t) => {
|
|
837
838
|
var a;
|
|
838
839
|
const r = await Me(e);
|
|
839
|
-
if (!r || !Array.isArray((a = r.payload) == null ? void 0 : a[
|
|
840
|
+
if (!r || !Array.isArray((a = r.payload) == null ? void 0 : a[I.SCOPES_KEY]))
|
|
840
841
|
return !1;
|
|
841
|
-
const n = r.payload[
|
|
842
|
+
const n = r.payload[I.SCOPES_KEY];
|
|
842
843
|
return Array.isArray(t) ? t.every((o) => n.includes(o)) : Object.keys(t).some(
|
|
843
844
|
(o) => t[o].every((i) => n.includes(i))
|
|
844
845
|
);
|
|
@@ -855,7 +856,7 @@ export {
|
|
|
855
856
|
et as AUTH_TYPES,
|
|
856
857
|
ne as BODY,
|
|
857
858
|
tt as HEADERS,
|
|
858
|
-
|
|
859
|
+
I as JWT,
|
|
859
860
|
ae as JWT_PUBLIC_KEY,
|
|
860
861
|
rt as TOKEN_EXPIRATION,
|
|
861
862
|
at as decodeToken,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@versini/auth-common",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Arno Versini",
|
|
6
6
|
"publishConfig": {
|
|
@@ -33,8 +33,8 @@
|
|
|
33
33
|
"test:coverage": "vitest run --coverage"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"jose": "5.
|
|
36
|
+
"jose": "5.7.0",
|
|
37
37
|
"uuid": "10.0.0"
|
|
38
38
|
},
|
|
39
|
-
"gitHead": "
|
|
39
|
+
"gitHead": "810b2920c2281e78b52ffbe1db7e52f4fefa8cbe"
|
|
40
40
|
}
|