@versini/auth-common 2.4.0 → 2.5.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 +5 -1
- package/dist/index.js +49 -45
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -15,6 +15,10 @@ declare const JWT: {
|
|
|
15
15
|
ISSUER: string;
|
|
16
16
|
};
|
|
17
17
|
declare const JWT_PUBLIC_KEY = "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAsF6i3Jd9fY/3COqCw/m7\nw5PKyTYLGAI2I6SIIdpe6i6DOCbEkmDz7LdVsBqwNtVi8gvWYIj+8ol6rU3qu1v5\ni1Jd45GSK4kzkVdgCmQZbM5ak0KI99q5wsrAIzUd+LRJ2HRvWtr5IYdsIiXaQjle\naMwPFOIcJH+rKfFgNcHLcaS5syp7zU1ANwZ+trgR+DifBr8TLVkBynmNeTyhDm2+\nl0haqjMk0UoNPPE8iYBWUHQJJE1Dqstj65d6Eh5g64Pao25y4cmYJbKjiblIGEkE\nsjqybA9mARAqh9k/eiIopecWSiffNQTwVQVd2I9ZH3BalhEXHlqFgrjz51kFqg81\nawIDAQAB\n-----END PUBLIC KEY-----";
|
|
18
|
+
declare const TOKEN_EXPIRATION: {
|
|
19
|
+
ACCESS: string;
|
|
20
|
+
ID: string;
|
|
21
|
+
};
|
|
18
22
|
declare const verifyAndExtractToken: (token: string, audience: string) => Promise<jose.JWTVerifyResult<jose.JWTPayload> | undefined>;
|
|
19
23
|
|
|
20
|
-
export { AUTH_TYPES, HEADERS, JWT, JWT_PUBLIC_KEY, verifyAndExtractToken };
|
|
24
|
+
export { AUTH_TYPES, HEADERS, JWT, JWT_PUBLIC_KEY, TOKEN_EXPIRATION, verifyAndExtractToken };
|
package/dist/index.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
@versini/auth-common v2.
|
|
2
|
+
@versini/auth-common v2.5.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/25/2024
|
|
7
|
+
version: "2.5.0",
|
|
8
|
+
buildTime: "06/25/2024 05:52 PM EDT",
|
|
9
9
|
homepage: "https://github.com/aversini/auth-client",
|
|
10
10
|
license: "MIT"
|
|
11
11
|
});
|
|
12
12
|
} catch {
|
|
13
13
|
}
|
|
14
|
-
const P = crypto, D = (e) => e instanceof CryptoKey,
|
|
14
|
+
const P = crypto, D = (e) => e instanceof CryptoKey, A = new TextEncoder(), g = new TextDecoder();
|
|
15
15
|
function V(...e) {
|
|
16
16
|
const t = e.reduce((o, { length: i }) => o + i, 0), n = new Uint8Array(t);
|
|
17
17
|
let r = 0;
|
|
@@ -33,7 +33,7 @@ const F = (e) => {
|
|
|
33
33
|
throw new TypeError("The input to be decoded is not correctly encoded.");
|
|
34
34
|
}
|
|
35
35
|
};
|
|
36
|
-
class
|
|
36
|
+
class w extends Error {
|
|
37
37
|
static get code() {
|
|
38
38
|
return "ERR_JOSE_GENERIC";
|
|
39
39
|
}
|
|
@@ -42,7 +42,7 @@ class E extends Error {
|
|
|
42
42
|
super(t), this.code = "ERR_JOSE_GENERIC", this.name = this.constructor.name, (n = Error.captureStackTrace) == null || n.call(Error, this, this.constructor);
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
|
-
class h extends
|
|
45
|
+
class h extends w {
|
|
46
46
|
static get code() {
|
|
47
47
|
return "ERR_JWT_CLAIM_VALIDATION_FAILED";
|
|
48
48
|
}
|
|
@@ -50,7 +50,7 @@ class h extends E {
|
|
|
50
50
|
super(t), this.code = "ERR_JWT_CLAIM_VALIDATION_FAILED", this.claim = r, this.reason = o, this.payload = n;
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
|
-
class O extends
|
|
53
|
+
class O extends w {
|
|
54
54
|
static get code() {
|
|
55
55
|
return "ERR_JWT_EXPIRED";
|
|
56
56
|
}
|
|
@@ -58,7 +58,7 @@ class O extends E {
|
|
|
58
58
|
super(t), this.code = "ERR_JWT_EXPIRED", this.claim = r, this.reason = o, this.payload = n;
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
|
-
class G extends
|
|
61
|
+
class G extends w {
|
|
62
62
|
constructor() {
|
|
63
63
|
super(...arguments), this.code = "ERR_JOSE_ALG_NOT_ALLOWED";
|
|
64
64
|
}
|
|
@@ -66,7 +66,7 @@ class G extends E {
|
|
|
66
66
|
return "ERR_JOSE_ALG_NOT_ALLOWED";
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
|
-
class
|
|
69
|
+
class I extends w {
|
|
70
70
|
constructor() {
|
|
71
71
|
super(...arguments), this.code = "ERR_JOSE_NOT_SUPPORTED";
|
|
72
72
|
}
|
|
@@ -74,7 +74,7 @@ class _ extends E {
|
|
|
74
74
|
return "ERR_JOSE_NOT_SUPPORTED";
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
|
-
class d extends
|
|
77
|
+
class d extends w {
|
|
78
78
|
constructor() {
|
|
79
79
|
super(...arguments), this.code = "ERR_JWS_INVALID";
|
|
80
80
|
}
|
|
@@ -82,7 +82,7 @@ class d extends E {
|
|
|
82
82
|
return "ERR_JWS_INVALID";
|
|
83
83
|
}
|
|
84
84
|
}
|
|
85
|
-
class k extends
|
|
85
|
+
class k extends w {
|
|
86
86
|
constructor() {
|
|
87
87
|
super(...arguments), this.code = "ERR_JWT_INVALID";
|
|
88
88
|
}
|
|
@@ -90,7 +90,7 @@ class k extends E {
|
|
|
90
90
|
return "ERR_JWT_INVALID";
|
|
91
91
|
}
|
|
92
92
|
}
|
|
93
|
-
class q extends
|
|
93
|
+
class q extends w {
|
|
94
94
|
constructor() {
|
|
95
95
|
super(...arguments), this.code = "ERR_JWS_SIGNATURE_VERIFICATION_FAILED", this.message = "signature verification failed";
|
|
96
96
|
}
|
|
@@ -101,7 +101,7 @@ class q extends E {
|
|
|
101
101
|
function p(e, t = "algorithm.name") {
|
|
102
102
|
return new TypeError(`CryptoKey does not support this operation, its ${t} must be ${e}`);
|
|
103
103
|
}
|
|
104
|
-
function
|
|
104
|
+
function b(e, t) {
|
|
105
105
|
return e.name === t;
|
|
106
106
|
}
|
|
107
107
|
function T(e) {
|
|
@@ -135,7 +135,7 @@ function Q(e, t, ...n) {
|
|
|
135
135
|
case "HS256":
|
|
136
136
|
case "HS384":
|
|
137
137
|
case "HS512": {
|
|
138
|
-
if (!
|
|
138
|
+
if (!b(e.algorithm, "HMAC"))
|
|
139
139
|
throw p("HMAC");
|
|
140
140
|
const r = parseInt(t.slice(2), 10);
|
|
141
141
|
if (T(e.algorithm.hash) !== r)
|
|
@@ -145,7 +145,7 @@ function Q(e, t, ...n) {
|
|
|
145
145
|
case "RS256":
|
|
146
146
|
case "RS384":
|
|
147
147
|
case "RS512": {
|
|
148
|
-
if (!
|
|
148
|
+
if (!b(e.algorithm, "RSASSA-PKCS1-v1_5"))
|
|
149
149
|
throw p("RSASSA-PKCS1-v1_5");
|
|
150
150
|
const r = parseInt(t.slice(2), 10);
|
|
151
151
|
if (T(e.algorithm.hash) !== r)
|
|
@@ -155,7 +155,7 @@ function Q(e, t, ...n) {
|
|
|
155
155
|
case "PS256":
|
|
156
156
|
case "PS384":
|
|
157
157
|
case "PS512": {
|
|
158
|
-
if (!
|
|
158
|
+
if (!b(e.algorithm, "RSA-PSS"))
|
|
159
159
|
throw p("RSA-PSS");
|
|
160
160
|
const r = parseInt(t.slice(2), 10);
|
|
161
161
|
if (T(e.algorithm.hash) !== r)
|
|
@@ -170,7 +170,7 @@ function Q(e, t, ...n) {
|
|
|
170
170
|
case "ES256":
|
|
171
171
|
case "ES384":
|
|
172
172
|
case "ES512": {
|
|
173
|
-
if (!
|
|
173
|
+
if (!b(e.algorithm, "ECDSA"))
|
|
174
174
|
throw p("ECDSA");
|
|
175
175
|
const r = Y(t);
|
|
176
176
|
if (e.algorithm.namedCurve !== r)
|
|
@@ -257,7 +257,7 @@ const Z = (e, t) => {
|
|
|
257
257
|
case y(e, [43, 101, 113]):
|
|
258
258
|
return "Ed448";
|
|
259
259
|
default:
|
|
260
|
-
throw new
|
|
260
|
+
throw new I("Invalid or unsupported EC Key Curve or OKP Key Sub Type");
|
|
261
261
|
}
|
|
262
262
|
}, ee = async (e, t, n, r, o) => {
|
|
263
263
|
let i, a;
|
|
@@ -303,7 +303,7 @@ const Z = (e, t) => {
|
|
|
303
303
|
i = { name: K(c) }, a = ["verify"];
|
|
304
304
|
break;
|
|
305
305
|
default:
|
|
306
|
-
throw new
|
|
306
|
+
throw new I('Invalid or unsupported "alg" (Algorithm) value');
|
|
307
307
|
}
|
|
308
308
|
return P.subtle.importKey(t, c, i, !1, a);
|
|
309
309
|
}, te = (e, t, n) => ee(/(?:-----(?:BEGIN|END) PUBLIC KEY-----|\s)/g, "spki", e, t);
|
|
@@ -342,7 +342,7 @@ function ie(e, t, n, r, o) {
|
|
|
342
342
|
n !== void 0 ? i = new Map([...Object.entries(n), ...t.entries()]) : i = t;
|
|
343
343
|
for (const a of r.crit) {
|
|
344
344
|
if (!i.has(a))
|
|
345
|
-
throw new
|
|
345
|
+
throw new I(`Extension Header Parameter "${a}" is not recognized`);
|
|
346
346
|
if (o[a] === void 0)
|
|
347
347
|
throw new e(`Extension Header Parameter "${a}" is missing`);
|
|
348
348
|
if (i.get(a) && r[a] === void 0)
|
|
@@ -378,7 +378,7 @@ function se(e, t) {
|
|
|
378
378
|
case "EdDSA":
|
|
379
379
|
return { name: t.name };
|
|
380
380
|
default:
|
|
381
|
-
throw new
|
|
381
|
+
throw new I(`alg ${e} is not supported either by JOSE or your javascript runtime`);
|
|
382
382
|
}
|
|
383
383
|
}
|
|
384
384
|
function de(e, t, n) {
|
|
@@ -417,8 +417,8 @@ async function fe(e, t, n) {
|
|
|
417
417
|
let r = {};
|
|
418
418
|
if (e.protected)
|
|
419
419
|
try {
|
|
420
|
-
const
|
|
421
|
-
r = JSON.parse(g.decode(
|
|
420
|
+
const _ = C(e.protected);
|
|
421
|
+
r = JSON.parse(g.decode(_));
|
|
422
422
|
} catch {
|
|
423
423
|
throw new d("JWS Protected Header is invalid");
|
|
424
424
|
}
|
|
@@ -444,14 +444,14 @@ async function fe(e, t, n) {
|
|
|
444
444
|
throw new d("JWS Payload must be a string or an Uint8Array instance");
|
|
445
445
|
let l = !1;
|
|
446
446
|
typeof t == "function" && (t = await t(r, e), l = !0), ae(c, t, "verify");
|
|
447
|
-
const
|
|
447
|
+
const E = V(A.encode(e.protected ?? ""), A.encode("."), typeof e.payload == "string" ? A.encode(e.payload) : e.payload);
|
|
448
448
|
let f;
|
|
449
449
|
try {
|
|
450
450
|
f = C(e.signature);
|
|
451
451
|
} catch {
|
|
452
452
|
throw new d("Failed to base64url decode the signature");
|
|
453
453
|
}
|
|
454
|
-
if (!await ue(c, t, f,
|
|
454
|
+
if (!await ue(c, t, f, E))
|
|
455
455
|
throw new q();
|
|
456
456
|
let m;
|
|
457
457
|
if (a)
|
|
@@ -461,7 +461,7 @@ async function fe(e, t, n) {
|
|
|
461
461
|
throw new d("Failed to base64url decode the payload");
|
|
462
462
|
}
|
|
463
463
|
else
|
|
464
|
-
typeof e.payload == "string" ? m =
|
|
464
|
+
typeof e.payload == "string" ? m = A.encode(e.payload) : m = e.payload;
|
|
465
465
|
const u = { payload: m };
|
|
466
466
|
return e.protected !== void 0 && (u.protectedHeader = r), e.header !== void 0 && (u.unprotectedHeader = e.header), l ? { ...u, key: t } : u;
|
|
467
467
|
}
|
|
@@ -517,7 +517,7 @@ const le = (e) => Math.floor(e.getTime() / 1e3), M = 60, B = M * 60, v = B * 24,
|
|
|
517
517
|
break;
|
|
518
518
|
}
|
|
519
519
|
return t[1] === "-" || t[4] === "ago" ? -o : o;
|
|
520
|
-
},
|
|
520
|
+
}, N = (e) => e.toLowerCase().replace(/^application\//, ""), Se = (e, t) => typeof e == "string" ? t.includes(e) : Array.isArray(e) ? t.some(Set.prototype.has.bind(new Set(e))) : !1, Ee = (e, t, n = {}) => {
|
|
521
521
|
let r;
|
|
522
522
|
try {
|
|
523
523
|
r = JSON.parse(g.decode(t));
|
|
@@ -526,11 +526,11 @@ const le = (e) => Math.floor(e.getTime() / 1e3), M = 60, B = M * 60, v = B * 24,
|
|
|
526
526
|
if (!R(r))
|
|
527
527
|
throw new k("JWT Claims Set must be a top-level JSON object");
|
|
528
528
|
const { typ: o } = n;
|
|
529
|
-
if (o && (typeof e.typ != "string" ||
|
|
529
|
+
if (o && (typeof e.typ != "string" || N(e.typ) !== N(o)))
|
|
530
530
|
throw new h('unexpected "typ" JWT header value', r, "typ", "check_failed");
|
|
531
|
-
const { requiredClaims: i = [], issuer: a, subject: c, audience: s, maxTokenAge: l } = n,
|
|
532
|
-
l !== void 0 &&
|
|
533
|
-
for (const u of new Set(
|
|
531
|
+
const { requiredClaims: i = [], issuer: a, subject: c, audience: s, maxTokenAge: l } = n, E = [...i];
|
|
532
|
+
l !== void 0 && E.push("iat"), s !== void 0 && E.push("aud"), c !== void 0 && E.push("sub"), a !== void 0 && E.push("iss");
|
|
533
|
+
for (const u of new Set(E.reverse()))
|
|
534
534
|
if (!(u in r))
|
|
535
535
|
throw new h(`missing required "${u}" claim`, r, u, "missing");
|
|
536
536
|
if (a && !(Array.isArray(a) ? a : [a]).includes(r.iss))
|
|
@@ -569,34 +569,34 @@ const le = (e) => Math.floor(e.getTime() / 1e3), M = 60, B = M * 60, v = B * 24,
|
|
|
569
569
|
throw new O('"exp" claim timestamp check failed', r, "exp", "check_failed");
|
|
570
570
|
}
|
|
571
571
|
if (l) {
|
|
572
|
-
const u = m - r.iat,
|
|
573
|
-
if (u - f >
|
|
572
|
+
const u = m - r.iat, _ = typeof l == "number" ? l : W(l);
|
|
573
|
+
if (u - f > _)
|
|
574
574
|
throw new O('"iat" claim timestamp check failed (too far in the past)', r, "iat", "check_failed");
|
|
575
575
|
if (u < 0 - f)
|
|
576
576
|
throw new h('"iat" claim timestamp check failed (it should be in the past)', r, "iat", "check_failed");
|
|
577
577
|
}
|
|
578
578
|
return r;
|
|
579
579
|
};
|
|
580
|
-
async function
|
|
580
|
+
async function we(e, t, n) {
|
|
581
581
|
var a;
|
|
582
582
|
const r = await he(e, t, n);
|
|
583
583
|
if ((a = r.protectedHeader.crit) != null && a.includes("b64") && r.protectedHeader.b64 === !1)
|
|
584
584
|
throw new k("JWTs MUST NOT use unencoded payload");
|
|
585
|
-
const i = { payload:
|
|
585
|
+
const i = { payload: Ee(r.protectedHeader, r.payload, n), protectedHeader: r.protectedHeader };
|
|
586
586
|
return typeof t == "function" ? { ...i, key: r.key } : i;
|
|
587
587
|
}
|
|
588
|
-
const
|
|
588
|
+
const be = {
|
|
589
589
|
ID_TOKEN: "id_token",
|
|
590
590
|
ACCESS_TOKEN: "token",
|
|
591
591
|
ID_AND_ACCESS_TOKEN: "id_token token"
|
|
592
592
|
}, ge = {
|
|
593
593
|
CLIENT_ID: "X-Auth-ClientId"
|
|
594
|
-
},
|
|
594
|
+
}, H = {
|
|
595
595
|
ALG: "RS256",
|
|
596
596
|
USER_ID_KEY: "_id",
|
|
597
597
|
TOKEN_ID_KEY: "__raw",
|
|
598
598
|
ISSUER: "gizmette.com"
|
|
599
|
-
},
|
|
599
|
+
}, Ae = `-----BEGIN PUBLIC KEY-----
|
|
600
600
|
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAsF6i3Jd9fY/3COqCw/m7
|
|
601
601
|
w5PKyTYLGAI2I6SIIdpe6i6DOCbEkmDz7LdVsBqwNtVi8gvWYIj+8ol6rU3qu1v5
|
|
602
602
|
i1Jd45GSK4kzkVdgCmQZbM5ak0KI99q5wsrAIzUd+LRJ2HRvWtr5IYdsIiXaQjle
|
|
@@ -604,11 +604,14 @@ aMwPFOIcJH+rKfFgNcHLcaS5syp7zU1ANwZ+trgR+DifBr8TLVkBynmNeTyhDm2+
|
|
|
604
604
|
l0haqjMk0UoNPPE8iYBWUHQJJE1Dqstj65d6Eh5g64Pao25y4cmYJbKjiblIGEkE
|
|
605
605
|
sjqybA9mARAqh9k/eiIopecWSiffNQTwVQVd2I9ZH3BalhEXHlqFgrjz51kFqg81
|
|
606
606
|
awIDAQAB
|
|
607
|
-
-----END PUBLIC KEY-----`,
|
|
607
|
+
-----END PUBLIC KEY-----`, Ie = {
|
|
608
|
+
ACCESS: "5m",
|
|
609
|
+
ID: "90d"
|
|
610
|
+
}, _e = async (e, t) => {
|
|
608
611
|
try {
|
|
609
|
-
const n =
|
|
610
|
-
return await
|
|
611
|
-
issuer:
|
|
612
|
+
const n = H.ALG, o = await re(Ae, n);
|
|
613
|
+
return await we(e, o, {
|
|
614
|
+
issuer: H.ISSUER,
|
|
612
615
|
audience: t
|
|
613
616
|
});
|
|
614
617
|
} catch {
|
|
@@ -616,9 +619,10 @@ awIDAQAB
|
|
|
616
619
|
}
|
|
617
620
|
};
|
|
618
621
|
export {
|
|
619
|
-
|
|
622
|
+
be as AUTH_TYPES,
|
|
620
623
|
ge as HEADERS,
|
|
621
|
-
|
|
622
|
-
|
|
624
|
+
H as JWT,
|
|
625
|
+
Ae as JWT_PUBLIC_KEY,
|
|
626
|
+
Ie as TOKEN_EXPIRATION,
|
|
623
627
|
_e as verifyAndExtractToken
|
|
624
628
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@versini/auth-common",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.5.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Arno Versini",
|
|
6
6
|
"publishConfig": {
|
|
@@ -32,5 +32,5 @@
|
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"jose": "5.4.1"
|
|
34
34
|
},
|
|
35
|
-
"gitHead": "
|
|
35
|
+
"gitHead": "25c60a5226b6f9d95aa3a3fcdbbc8448181e937a"
|
|
36
36
|
}
|