@versini/auth-common 2.2.0 → 2.4.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 -0
- package/dist/index.js +110 -107
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -2,6 +2,8 @@ import * as jose from 'jose';
|
|
|
2
2
|
|
|
3
3
|
declare const AUTH_TYPES: {
|
|
4
4
|
ID_TOKEN: string;
|
|
5
|
+
ACCESS_TOKEN: string;
|
|
6
|
+
ID_AND_ACCESS_TOKEN: string;
|
|
5
7
|
};
|
|
6
8
|
declare const HEADERS: {
|
|
7
9
|
CLIENT_ID: string;
|
|
@@ -9,6 +11,7 @@ declare const HEADERS: {
|
|
|
9
11
|
declare const JWT: {
|
|
10
12
|
ALG: string;
|
|
11
13
|
USER_ID_KEY: string;
|
|
14
|
+
TOKEN_ID_KEY: string;
|
|
12
15
|
ISSUER: string;
|
|
13
16
|
};
|
|
14
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-----";
|
package/dist/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
@versini/auth-common v2.
|
|
2
|
+
@versini/auth-common v2.4.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/
|
|
7
|
+
version: "2.4.0",
|
|
8
|
+
buildTime: "06/25/2024 03:57 PM EDT",
|
|
9
9
|
homepage: "https://github.com/aversini/auth-client",
|
|
10
10
|
license: "MIT"
|
|
11
11
|
});
|
|
@@ -13,10 +13,10 @@ try {
|
|
|
13
13
|
}
|
|
14
14
|
const P = crypto, D = (e) => e instanceof CryptoKey, b = new TextEncoder(), g = new TextDecoder();
|
|
15
15
|
function V(...e) {
|
|
16
|
-
const t = e.reduce((
|
|
16
|
+
const t = e.reduce((o, { length: i }) => o + i, 0), n = new Uint8Array(t);
|
|
17
17
|
let r = 0;
|
|
18
|
-
for (const
|
|
19
|
-
n.set(
|
|
18
|
+
for (const o of e)
|
|
19
|
+
n.set(o, r), r += o.length;
|
|
20
20
|
return n;
|
|
21
21
|
}
|
|
22
22
|
const F = (e) => {
|
|
@@ -24,7 +24,7 @@ const F = (e) => {
|
|
|
24
24
|
for (let r = 0; r < t.length; r++)
|
|
25
25
|
n[r] = t.charCodeAt(r);
|
|
26
26
|
return n;
|
|
27
|
-
},
|
|
27
|
+
}, C = (e) => {
|
|
28
28
|
let t = e;
|
|
29
29
|
t instanceof Uint8Array && (t = g.decode(t)), t = t.replace(/-/g, "+").replace(/_/g, "/").replace(/\s/g, "");
|
|
30
30
|
try {
|
|
@@ -46,16 +46,16 @@ class h extends E {
|
|
|
46
46
|
static get code() {
|
|
47
47
|
return "ERR_JWT_CLAIM_VALIDATION_FAILED";
|
|
48
48
|
}
|
|
49
|
-
constructor(t, n, r = "unspecified",
|
|
50
|
-
super(t), this.code = "ERR_JWT_CLAIM_VALIDATION_FAILED", this.claim = r, this.reason =
|
|
49
|
+
constructor(t, n, r = "unspecified", o = "unspecified") {
|
|
50
|
+
super(t), this.code = "ERR_JWT_CLAIM_VALIDATION_FAILED", this.claim = r, this.reason = o, this.payload = n;
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
53
|
class O extends E {
|
|
54
54
|
static get code() {
|
|
55
55
|
return "ERR_JWT_EXPIRED";
|
|
56
56
|
}
|
|
57
|
-
constructor(t, n, r = "unspecified",
|
|
58
|
-
super(t), this.code = "ERR_JWT_EXPIRED", this.claim = r, this.reason =
|
|
57
|
+
constructor(t, n, r = "unspecified", o = "unspecified") {
|
|
58
|
+
super(t), this.code = "ERR_JWT_EXPIRED", this.claim = r, this.reason = o, this.payload = n;
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
61
|
class G extends E {
|
|
@@ -66,7 +66,7 @@ class G extends E {
|
|
|
66
66
|
return "ERR_JOSE_ALG_NOT_ALLOWED";
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
|
-
class
|
|
69
|
+
class _ extends E {
|
|
70
70
|
constructor() {
|
|
71
71
|
super(...arguments), this.code = "ERR_JOSE_NOT_SUPPORTED";
|
|
72
72
|
}
|
|
@@ -82,7 +82,7 @@ class d extends E {
|
|
|
82
82
|
return "ERR_JWS_INVALID";
|
|
83
83
|
}
|
|
84
84
|
}
|
|
85
|
-
class
|
|
85
|
+
class k extends E {
|
|
86
86
|
constructor() {
|
|
87
87
|
super(...arguments), this.code = "ERR_JWT_INVALID";
|
|
88
88
|
}
|
|
@@ -182,31 +182,31 @@ function Q(e, t, ...n) {
|
|
|
182
182
|
}
|
|
183
183
|
z(e, n);
|
|
184
184
|
}
|
|
185
|
-
function
|
|
185
|
+
function L(e, t, ...n) {
|
|
186
186
|
var r;
|
|
187
187
|
if (n.length > 2) {
|
|
188
|
-
const
|
|
189
|
-
e += `one of type ${n.join(", ")}, or ${
|
|
188
|
+
const o = n.pop();
|
|
189
|
+
e += `one of type ${n.join(", ")}, or ${o}.`;
|
|
190
190
|
} else
|
|
191
191
|
n.length === 2 ? e += `one of type ${n[0]} or ${n[1]}.` : e += `of type ${n[0]}.`;
|
|
192
192
|
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;
|
|
193
193
|
}
|
|
194
|
-
const J = (e, ...t) =>
|
|
195
|
-
function
|
|
196
|
-
return
|
|
194
|
+
const J = (e, ...t) => L("Key must be ", e, ...t);
|
|
195
|
+
function U(e, t, ...n) {
|
|
196
|
+
return L(`Key for the ${e} algorithm must be `, t, ...n);
|
|
197
197
|
}
|
|
198
|
-
const
|
|
198
|
+
const $ = (e) => D(e), S = ["CryptoKey"], X = (...e) => {
|
|
199
199
|
const t = e.filter(Boolean);
|
|
200
200
|
if (t.length === 0 || t.length === 1)
|
|
201
201
|
return !0;
|
|
202
202
|
let n;
|
|
203
203
|
for (const r of t) {
|
|
204
|
-
const
|
|
204
|
+
const o = Object.keys(r);
|
|
205
205
|
if (!n || n.size === 0) {
|
|
206
|
-
n = new Set(
|
|
206
|
+
n = new Set(o);
|
|
207
207
|
continue;
|
|
208
208
|
}
|
|
209
|
-
for (const i of
|
|
209
|
+
for (const i of o) {
|
|
210
210
|
if (n.has(i))
|
|
211
211
|
return !1;
|
|
212
212
|
n.add(i);
|
|
@@ -217,7 +217,7 @@ const k = (e) => D(e), S = ["CryptoKey"], X = (...e) => {
|
|
|
217
217
|
function j(e) {
|
|
218
218
|
return typeof e == "object" && e !== null;
|
|
219
219
|
}
|
|
220
|
-
function
|
|
220
|
+
function R(e) {
|
|
221
221
|
if (!j(e) || Object.prototype.toString.call(e) !== "[object Object]")
|
|
222
222
|
return !1;
|
|
223
223
|
if (Object.getPrototypeOf(e) === null)
|
|
@@ -238,9 +238,9 @@ const Z = (e, t) => {
|
|
|
238
238
|
const r = e.indexOf(t[0], n);
|
|
239
239
|
if (r === -1)
|
|
240
240
|
return !1;
|
|
241
|
-
const
|
|
242
|
-
return
|
|
243
|
-
},
|
|
241
|
+
const o = e.subarray(r, r + t.length);
|
|
242
|
+
return o.length !== t.length ? !1 : o.every((i, a) => i === t[a]) || y(e, t, r + 1);
|
|
243
|
+
}, K = (e) => {
|
|
244
244
|
switch (!0) {
|
|
245
245
|
case y(e, [42, 134, 72, 206, 61, 3, 1, 7]):
|
|
246
246
|
return "P-256";
|
|
@@ -257,21 +257,21 @@ 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 _("Invalid or unsupported EC Key Curve or OKP Key Sub Type");
|
|
261
261
|
}
|
|
262
|
-
}, ee = async (e, t, n, r,
|
|
263
|
-
let i,
|
|
262
|
+
}, ee = async (e, t, n, r, o) => {
|
|
263
|
+
let i, a;
|
|
264
264
|
const c = new Uint8Array(atob(n.replace(e, "")).split("").map((s) => s.charCodeAt(0)));
|
|
265
265
|
switch (r) {
|
|
266
266
|
case "PS256":
|
|
267
267
|
case "PS384":
|
|
268
268
|
case "PS512":
|
|
269
|
-
i = { name: "RSA-PSS", hash: `SHA-${r.slice(-3)}` },
|
|
269
|
+
i = { name: "RSA-PSS", hash: `SHA-${r.slice(-3)}` }, a = ["verify"];
|
|
270
270
|
break;
|
|
271
271
|
case "RS256":
|
|
272
272
|
case "RS384":
|
|
273
273
|
case "RS512":
|
|
274
|
-
i = { name: "RSASSA-PKCS1-v1_5", hash: `SHA-${r.slice(-3)}` },
|
|
274
|
+
i = { name: "RSASSA-PKCS1-v1_5", hash: `SHA-${r.slice(-3)}` }, a = ["verify"];
|
|
275
275
|
break;
|
|
276
276
|
case "RSA-OAEP":
|
|
277
277
|
case "RSA-OAEP-256":
|
|
@@ -280,32 +280,32 @@ const Z = (e, t) => {
|
|
|
280
280
|
i = {
|
|
281
281
|
name: "RSA-OAEP",
|
|
282
282
|
hash: `SHA-${parseInt(r.slice(-3), 10) || 1}`
|
|
283
|
-
},
|
|
283
|
+
}, a = ["encrypt", "wrapKey"];
|
|
284
284
|
break;
|
|
285
285
|
case "ES256":
|
|
286
|
-
i = { name: "ECDSA", namedCurve: "P-256" },
|
|
286
|
+
i = { name: "ECDSA", namedCurve: "P-256" }, a = ["verify"];
|
|
287
287
|
break;
|
|
288
288
|
case "ES384":
|
|
289
|
-
i = { name: "ECDSA", namedCurve: "P-384" },
|
|
289
|
+
i = { name: "ECDSA", namedCurve: "P-384" }, a = ["verify"];
|
|
290
290
|
break;
|
|
291
291
|
case "ES512":
|
|
292
|
-
i = { name: "ECDSA", namedCurve: "P-521" },
|
|
292
|
+
i = { name: "ECDSA", namedCurve: "P-521" }, a = ["verify"];
|
|
293
293
|
break;
|
|
294
294
|
case "ECDH-ES":
|
|
295
295
|
case "ECDH-ES+A128KW":
|
|
296
296
|
case "ECDH-ES+A192KW":
|
|
297
297
|
case "ECDH-ES+A256KW": {
|
|
298
|
-
const s =
|
|
299
|
-
i = s.startsWith("P-") ? { name: "ECDH", namedCurve: s } : { name: s },
|
|
298
|
+
const s = K(c);
|
|
299
|
+
i = s.startsWith("P-") ? { name: "ECDH", namedCurve: s } : { name: s }, a = [];
|
|
300
300
|
break;
|
|
301
301
|
}
|
|
302
302
|
case "EdDSA":
|
|
303
|
-
i = { name:
|
|
303
|
+
i = { name: K(c) }, a = ["verify"];
|
|
304
304
|
break;
|
|
305
305
|
default:
|
|
306
|
-
throw new
|
|
306
|
+
throw new _('Invalid or unsupported "alg" (Algorithm) value');
|
|
307
307
|
}
|
|
308
|
-
return P.subtle.importKey(t, c, i, !1,
|
|
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);
|
|
310
310
|
async function re(e, t, n) {
|
|
311
311
|
if (e.indexOf("-----BEGIN PUBLIC KEY-----") !== 0)
|
|
@@ -314,39 +314,39 @@ async function re(e, t, n) {
|
|
|
314
314
|
}
|
|
315
315
|
const ne = (e, t) => {
|
|
316
316
|
if (!(t instanceof Uint8Array)) {
|
|
317
|
-
if (
|
|
318
|
-
throw new TypeError(
|
|
317
|
+
if (!$(t))
|
|
318
|
+
throw new TypeError(U(e, t, ...S, "Uint8Array"));
|
|
319
319
|
if (t.type !== "secret")
|
|
320
320
|
throw new TypeError(`${S.join(" or ")} instances for symmetric algorithms must be of type "secret"`);
|
|
321
321
|
}
|
|
322
|
-
},
|
|
323
|
-
if (
|
|
324
|
-
throw new TypeError(
|
|
322
|
+
}, oe = (e, t, n) => {
|
|
323
|
+
if (!$(t))
|
|
324
|
+
throw new TypeError(U(e, t, ...S));
|
|
325
325
|
if (t.type === "secret")
|
|
326
326
|
throw new TypeError(`${S.join(" or ")} instances for asymmetric algorithms must not be of type "secret"`);
|
|
327
327
|
if (t.algorithm && n === "verify" && t.type === "private")
|
|
328
328
|
throw new TypeError(`${S.join(" or ")} instances for asymmetric algorithm verifying must be of type "public"`);
|
|
329
329
|
if (t.algorithm && n === "encrypt" && t.type === "private")
|
|
330
330
|
throw new TypeError(`${S.join(" or ")} instances for asymmetric algorithm encryption must be of type "public"`);
|
|
331
|
-
},
|
|
332
|
-
e.startsWith("HS") || e === "dir" || e.startsWith("PBES2") || /^A\d{3}(?:GCM)?KW$/.test(e) ? ne(e, t) :
|
|
331
|
+
}, ae = (e, t, n) => {
|
|
332
|
+
e.startsWith("HS") || e === "dir" || e.startsWith("PBES2") || /^A\d{3}(?:GCM)?KW$/.test(e) ? ne(e, t) : oe(e, t, n);
|
|
333
333
|
};
|
|
334
|
-
function ie(e, t, n, r,
|
|
335
|
-
if (
|
|
334
|
+
function ie(e, t, n, r, o) {
|
|
335
|
+
if (o.crit !== void 0 && (r == null ? void 0 : r.crit) === void 0)
|
|
336
336
|
throw new e('"crit" (Critical) Header Parameter MUST be integrity protected');
|
|
337
337
|
if (!r || r.crit === void 0)
|
|
338
338
|
return /* @__PURE__ */ new Set();
|
|
339
|
-
if (!Array.isArray(r.crit) || r.crit.length === 0 || r.crit.some((
|
|
339
|
+
if (!Array.isArray(r.crit) || r.crit.length === 0 || r.crit.some((a) => typeof a != "string" || a.length === 0))
|
|
340
340
|
throw new e('"crit" (Critical) Header Parameter MUST be an array of non-empty strings when present');
|
|
341
341
|
let i;
|
|
342
342
|
n !== void 0 ? i = new Map([...Object.entries(n), ...t.entries()]) : i = t;
|
|
343
|
-
for (const
|
|
344
|
-
if (!i.has(
|
|
345
|
-
throw new
|
|
346
|
-
if (a
|
|
347
|
-
throw new e(`Extension Header Parameter "${
|
|
348
|
-
if (i.get(
|
|
349
|
-
throw new e(`Extension Header Parameter "${
|
|
343
|
+
for (const a of r.crit) {
|
|
344
|
+
if (!i.has(a))
|
|
345
|
+
throw new _(`Extension Header Parameter "${a}" is not recognized`);
|
|
346
|
+
if (o[a] === void 0)
|
|
347
|
+
throw new e(`Extension Header Parameter "${a}" is missing`);
|
|
348
|
+
if (i.get(a) && r[a] === void 0)
|
|
349
|
+
throw new e(`Extension Header Parameter "${a}" MUST be integrity protected`);
|
|
350
350
|
}
|
|
351
351
|
return new Set(r.crit);
|
|
352
352
|
}
|
|
@@ -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 _(`alg ${e} is not supported either by JOSE or your javascript runtime`);
|
|
382
382
|
}
|
|
383
383
|
}
|
|
384
384
|
function de(e, t, n) {
|
|
@@ -392,17 +392,17 @@ function de(e, t, n) {
|
|
|
392
392
|
throw new TypeError(J(t, ...S, "Uint8Array"));
|
|
393
393
|
}
|
|
394
394
|
const ue = async (e, t, n, r) => {
|
|
395
|
-
const
|
|
396
|
-
Z(e,
|
|
397
|
-
const i = se(e,
|
|
395
|
+
const o = await de(e, t, "verify");
|
|
396
|
+
Z(e, o);
|
|
397
|
+
const i = se(e, o.algorithm);
|
|
398
398
|
try {
|
|
399
|
-
return await P.subtle.verify(i,
|
|
399
|
+
return await P.subtle.verify(i, o, n, r);
|
|
400
400
|
} catch {
|
|
401
401
|
return !1;
|
|
402
402
|
}
|
|
403
403
|
};
|
|
404
404
|
async function fe(e, t, n) {
|
|
405
|
-
if (!
|
|
405
|
+
if (!R(e))
|
|
406
406
|
throw new d("Flattened JWS must be an object");
|
|
407
407
|
if (e.protected === void 0 && e.header === void 0)
|
|
408
408
|
throw new d('Flattened JWS must have either of the "protected" or "header" members');
|
|
@@ -412,51 +412,51 @@ async function fe(e, t, n) {
|
|
|
412
412
|
throw new d("JWS Payload missing");
|
|
413
413
|
if (typeof e.signature != "string")
|
|
414
414
|
throw new d("JWS Signature missing or incorrect type");
|
|
415
|
-
if (e.header !== void 0 && !
|
|
415
|
+
if (e.header !== void 0 && !R(e.header))
|
|
416
416
|
throw new d("JWS Unprotected Header incorrect type");
|
|
417
417
|
let r = {};
|
|
418
418
|
if (e.protected)
|
|
419
419
|
try {
|
|
420
|
-
const
|
|
421
|
-
r = JSON.parse(g.decode(
|
|
420
|
+
const I = C(e.protected);
|
|
421
|
+
r = JSON.parse(g.decode(I));
|
|
422
422
|
} catch {
|
|
423
423
|
throw new d("JWS Protected Header is invalid");
|
|
424
424
|
}
|
|
425
425
|
if (!X(r, e.header))
|
|
426
426
|
throw new d("JWS Protected and JWS Unprotected Header Parameter names must be disjoint");
|
|
427
|
-
const
|
|
427
|
+
const o = {
|
|
428
428
|
...r,
|
|
429
429
|
...e.header
|
|
430
|
-
}, i = ie(d, /* @__PURE__ */ new Map([["b64", !0]]), n == null ? void 0 : n.crit, r,
|
|
431
|
-
let
|
|
432
|
-
if (i.has("b64") && (
|
|
430
|
+
}, i = ie(d, /* @__PURE__ */ new Map([["b64", !0]]), n == null ? void 0 : n.crit, r, o);
|
|
431
|
+
let a = !0;
|
|
432
|
+
if (i.has("b64") && (a = r.b64, typeof a != "boolean"))
|
|
433
433
|
throw new d('The "b64" (base64url-encode payload) Header Parameter must be a boolean');
|
|
434
|
-
const { alg: c } =
|
|
434
|
+
const { alg: c } = o;
|
|
435
435
|
if (typeof c != "string" || !c)
|
|
436
436
|
throw new d('JWS "alg" (Algorithm) Header Parameter missing or invalid');
|
|
437
437
|
const s = n && ce("algorithms", n.algorithms);
|
|
438
438
|
if (s && !s.has(c))
|
|
439
439
|
throw new G('"alg" (Algorithm) Header Parameter value not allowed');
|
|
440
|
-
if (
|
|
440
|
+
if (a) {
|
|
441
441
|
if (typeof e.payload != "string")
|
|
442
442
|
throw new d("JWS Payload must be a string");
|
|
443
443
|
} else if (typeof e.payload != "string" && !(e.payload instanceof Uint8Array))
|
|
444
444
|
throw new d("JWS Payload must be a string or an Uint8Array instance");
|
|
445
445
|
let l = !1;
|
|
446
|
-
typeof t == "function" && (t = await t(r, e), l = !0),
|
|
446
|
+
typeof t == "function" && (t = await t(r, e), l = !0), ae(c, t, "verify");
|
|
447
447
|
const w = V(b.encode(e.protected ?? ""), b.encode("."), typeof e.payload == "string" ? b.encode(e.payload) : e.payload);
|
|
448
448
|
let f;
|
|
449
449
|
try {
|
|
450
|
-
f =
|
|
450
|
+
f = C(e.signature);
|
|
451
451
|
} catch {
|
|
452
452
|
throw new d("Failed to base64url decode the signature");
|
|
453
453
|
}
|
|
454
454
|
if (!await ue(c, t, f, w))
|
|
455
455
|
throw new q();
|
|
456
456
|
let m;
|
|
457
|
-
if (
|
|
457
|
+
if (a)
|
|
458
458
|
try {
|
|
459
|
-
m =
|
|
459
|
+
m = C(e.payload);
|
|
460
460
|
} catch {
|
|
461
461
|
throw new d("Failed to base64url decode the payload");
|
|
462
462
|
}
|
|
@@ -468,72 +468,72 @@ async function fe(e, t, n) {
|
|
|
468
468
|
async function he(e, t, n) {
|
|
469
469
|
if (e instanceof Uint8Array && (e = g.decode(e)), typeof e != "string")
|
|
470
470
|
throw new d("Compact JWS must be a string or Uint8Array");
|
|
471
|
-
const { 0: r, 1:
|
|
472
|
-
if (
|
|
471
|
+
const { 0: r, 1: o, 2: i, length: a } = e.split(".");
|
|
472
|
+
if (a !== 3)
|
|
473
473
|
throw new d("Invalid Compact JWS");
|
|
474
|
-
const c = await fe({ payload:
|
|
474
|
+
const c = await fe({ payload: o, protected: r, signature: i }, t, n), s = { payload: c.payload, protectedHeader: c.protectedHeader };
|
|
475
475
|
return typeof t == "function" ? { ...s, key: c.key } : s;
|
|
476
476
|
}
|
|
477
|
-
const le = (e) => Math.floor(e.getTime() / 1e3), M = 60, B = M * 60, v = B * 24, pe = v * 7, me = v * 365.25, ye = /^(\+|\-)? ?(\d+|\d+\.\d+) ?(seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)(?: (ago|from now))?$/i,
|
|
477
|
+
const le = (e) => Math.floor(e.getTime() / 1e3), M = 60, B = M * 60, v = B * 24, pe = v * 7, me = v * 365.25, ye = /^(\+|\-)? ?(\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) => {
|
|
478
478
|
const t = ye.exec(e);
|
|
479
479
|
if (!t || t[4] && t[1])
|
|
480
480
|
throw new TypeError("Invalid time period format");
|
|
481
481
|
const n = parseFloat(t[2]), r = t[3].toLowerCase();
|
|
482
|
-
let
|
|
482
|
+
let o;
|
|
483
483
|
switch (r) {
|
|
484
484
|
case "sec":
|
|
485
485
|
case "secs":
|
|
486
486
|
case "second":
|
|
487
487
|
case "seconds":
|
|
488
488
|
case "s":
|
|
489
|
-
|
|
489
|
+
o = Math.round(n);
|
|
490
490
|
break;
|
|
491
491
|
case "minute":
|
|
492
492
|
case "minutes":
|
|
493
493
|
case "min":
|
|
494
494
|
case "mins":
|
|
495
495
|
case "m":
|
|
496
|
-
|
|
496
|
+
o = Math.round(n * M);
|
|
497
497
|
break;
|
|
498
498
|
case "hour":
|
|
499
499
|
case "hours":
|
|
500
500
|
case "hr":
|
|
501
501
|
case "hrs":
|
|
502
502
|
case "h":
|
|
503
|
-
|
|
503
|
+
o = Math.round(n * B);
|
|
504
504
|
break;
|
|
505
505
|
case "day":
|
|
506
506
|
case "days":
|
|
507
507
|
case "d":
|
|
508
|
-
|
|
508
|
+
o = Math.round(n * v);
|
|
509
509
|
break;
|
|
510
510
|
case "week":
|
|
511
511
|
case "weeks":
|
|
512
512
|
case "w":
|
|
513
|
-
|
|
513
|
+
o = Math.round(n * pe);
|
|
514
514
|
break;
|
|
515
515
|
default:
|
|
516
|
-
|
|
516
|
+
o = Math.round(n * me);
|
|
517
517
|
break;
|
|
518
518
|
}
|
|
519
|
-
return t[1] === "-" || t[4] === "ago" ? -
|
|
519
|
+
return t[1] === "-" || t[4] === "ago" ? -o : o;
|
|
520
520
|
}, H = (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, we = (e, t, n = {}) => {
|
|
521
521
|
let r;
|
|
522
522
|
try {
|
|
523
523
|
r = JSON.parse(g.decode(t));
|
|
524
524
|
} catch {
|
|
525
525
|
}
|
|
526
|
-
if (!
|
|
527
|
-
throw new
|
|
528
|
-
const { typ:
|
|
529
|
-
if (
|
|
526
|
+
if (!R(r))
|
|
527
|
+
throw new k("JWT Claims Set must be a top-level JSON object");
|
|
528
|
+
const { typ: o } = n;
|
|
529
|
+
if (o && (typeof e.typ != "string" || H(e.typ) !== H(o)))
|
|
530
530
|
throw new h('unexpected "typ" JWT header value', r, "typ", "check_failed");
|
|
531
|
-
const { requiredClaims: i = [], issuer:
|
|
532
|
-
l !== void 0 && w.push("iat"), s !== void 0 && w.push("aud"), c !== void 0 && w.push("sub"),
|
|
531
|
+
const { requiredClaims: i = [], issuer: a, subject: c, audience: s, maxTokenAge: l } = n, w = [...i];
|
|
532
|
+
l !== void 0 && w.push("iat"), s !== void 0 && w.push("aud"), c !== void 0 && w.push("sub"), a !== void 0 && w.push("iss");
|
|
533
533
|
for (const u of new Set(w.reverse()))
|
|
534
534
|
if (!(u in r))
|
|
535
535
|
throw new h(`missing required "${u}" claim`, r, u, "missing");
|
|
536
|
-
if (
|
|
536
|
+
if (a && !(Array.isArray(a) ? a : [a]).includes(r.iss))
|
|
537
537
|
throw new h('unexpected "iss" claim value', r, "iss", "check_failed");
|
|
538
538
|
if (c && r.sub !== c)
|
|
539
539
|
throw new h('unexpected "sub" claim value', r, "sub", "check_failed");
|
|
@@ -542,7 +542,7 @@ const le = (e) => Math.floor(e.getTime() / 1e3), M = 60, B = M * 60, v = B * 24,
|
|
|
542
542
|
let f;
|
|
543
543
|
switch (typeof n.clockTolerance) {
|
|
544
544
|
case "string":
|
|
545
|
-
f =
|
|
545
|
+
f = W(n.clockTolerance);
|
|
546
546
|
break;
|
|
547
547
|
case "number":
|
|
548
548
|
f = n.clockTolerance;
|
|
@@ -569,8 +569,8 @@ 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, I = typeof l == "number" ? l : W(l);
|
|
573
|
+
if (u - f > I)
|
|
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");
|
|
@@ -578,20 +578,23 @@ const le = (e) => Math.floor(e.getTime() / 1e3), M = 60, B = M * 60, v = B * 24,
|
|
|
578
578
|
return r;
|
|
579
579
|
};
|
|
580
580
|
async function Ee(e, t, n) {
|
|
581
|
-
var
|
|
581
|
+
var a;
|
|
582
582
|
const r = await he(e, t, n);
|
|
583
|
-
if ((
|
|
584
|
-
throw new
|
|
583
|
+
if ((a = r.protectedHeader.crit) != null && a.includes("b64") && r.protectedHeader.b64 === !1)
|
|
584
|
+
throw new k("JWTs MUST NOT use unencoded payload");
|
|
585
585
|
const i = { payload: we(r.protectedHeader, r.payload, n), protectedHeader: r.protectedHeader };
|
|
586
586
|
return typeof t == "function" ? { ...i, key: r.key } : i;
|
|
587
587
|
}
|
|
588
588
|
const Ae = {
|
|
589
|
-
ID_TOKEN: "id_token"
|
|
589
|
+
ID_TOKEN: "id_token",
|
|
590
|
+
ACCESS_TOKEN: "token",
|
|
591
|
+
ID_AND_ACCESS_TOKEN: "id_token token"
|
|
590
592
|
}, ge = {
|
|
591
593
|
CLIENT_ID: "X-Auth-ClientId"
|
|
592
594
|
}, N = {
|
|
593
595
|
ALG: "RS256",
|
|
594
596
|
USER_ID_KEY: "_id",
|
|
597
|
+
TOKEN_ID_KEY: "__raw",
|
|
595
598
|
ISSUER: "gizmette.com"
|
|
596
599
|
}, be = `-----BEGIN PUBLIC KEY-----
|
|
597
600
|
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAsF6i3Jd9fY/3COqCw/m7
|
|
@@ -601,10 +604,10 @@ aMwPFOIcJH+rKfFgNcHLcaS5syp7zU1ANwZ+trgR+DifBr8TLVkBynmNeTyhDm2+
|
|
|
601
604
|
l0haqjMk0UoNPPE8iYBWUHQJJE1Dqstj65d6Eh5g64Pao25y4cmYJbKjiblIGEkE
|
|
602
605
|
sjqybA9mARAqh9k/eiIopecWSiffNQTwVQVd2I9ZH3BalhEXHlqFgrjz51kFqg81
|
|
603
606
|
awIDAQAB
|
|
604
|
-
-----END PUBLIC KEY-----`,
|
|
607
|
+
-----END PUBLIC KEY-----`, _e = async (e, t) => {
|
|
605
608
|
try {
|
|
606
|
-
const n = N.ALG,
|
|
607
|
-
return await Ee(e,
|
|
609
|
+
const n = N.ALG, o = await re(be, n);
|
|
610
|
+
return await Ee(e, o, {
|
|
608
611
|
issuer: N.ISSUER,
|
|
609
612
|
audience: t
|
|
610
613
|
});
|
|
@@ -617,5 +620,5 @@ export {
|
|
|
617
620
|
ge as HEADERS,
|
|
618
621
|
N as JWT,
|
|
619
622
|
be as JWT_PUBLIC_KEY,
|
|
620
|
-
|
|
623
|
+
_e as verifyAndExtractToken
|
|
621
624
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@versini/auth-common",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.4.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": "86fb8a035b0df8272887b158f678c408f7be3940"
|
|
36
36
|
}
|