@versini/auth-common 2.3.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 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;
@@ -13,6 +15,10 @@ declare const JWT: {
13
15
  ISSUER: string;
14
16
  };
15
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
+ };
16
22
  declare const verifyAndExtractToken: (token: string, audience: string) => Promise<jose.JWTVerifyResult<jose.JWTPayload> | undefined>;
17
23
 
18
- 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,22 +1,22 @@
1
1
  /*!
2
- @versini/auth-common v2.3.0
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.3.0",
8
- buildTime: "06/24/2024 06:08 PM EDT",
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, b = new TextEncoder(), g = new TextDecoder();
14
+ const P = crypto, D = (e) => e instanceof CryptoKey, A = new TextEncoder(), g = new TextDecoder();
15
15
  function V(...e) {
16
- const t = e.reduce((a, { length: i }) => a + i, 0), n = new Uint8Array(t);
16
+ const t = e.reduce((o, { length: i }) => o + i, 0), n = new Uint8Array(t);
17
17
  let r = 0;
18
- for (const a of e)
19
- n.set(a, r), r += a.length;
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
- }, R = (e) => {
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 {
@@ -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 E extends Error {
36
+ class w extends Error {
37
37
  static get code() {
38
38
  return "ERR_JOSE_GENERIC";
39
39
  }
@@ -42,23 +42,23 @@ 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 E {
45
+ class h extends w {
46
46
  static get code() {
47
47
  return "ERR_JWT_CLAIM_VALIDATION_FAILED";
48
48
  }
49
- constructor(t, n, r = "unspecified", a = "unspecified") {
50
- super(t), this.code = "ERR_JWT_CLAIM_VALIDATION_FAILED", this.claim = r, this.reason = a, this.payload = n;
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
- class O extends E {
53
+ class O extends w {
54
54
  static get code() {
55
55
  return "ERR_JWT_EXPIRED";
56
56
  }
57
- constructor(t, n, r = "unspecified", a = "unspecified") {
58
- super(t), this.code = "ERR_JWT_EXPIRED", this.claim = r, this.reason = a, this.payload = n;
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
- class G extends E {
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 I extends E {
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 I extends E {
74
74
  return "ERR_JOSE_NOT_SUPPORTED";
75
75
  }
76
76
  }
77
- class d extends E {
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 L extends E {
85
+ class k extends w {
86
86
  constructor() {
87
87
  super(...arguments), this.code = "ERR_JWT_INVALID";
88
88
  }
@@ -90,7 +90,7 @@ class L extends E {
90
90
  return "ERR_JWT_INVALID";
91
91
  }
92
92
  }
93
- class q extends E {
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 A(e, t) {
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 (!A(e.algorithm, "HMAC"))
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 (!A(e.algorithm, "RSASSA-PKCS1-v1_5"))
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 (!A(e.algorithm, "RSA-PSS"))
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 (!A(e.algorithm, "ECDSA"))
173
+ if (!b(e.algorithm, "ECDSA"))
174
174
  throw p("ECDSA");
175
175
  const r = Y(t);
176
176
  if (e.algorithm.namedCurve !== r)
@@ -182,31 +182,31 @@ function Q(e, t, ...n) {
182
182
  }
183
183
  z(e, n);
184
184
  }
185
- function U(e, t, ...n) {
185
+ function L(e, t, ...n) {
186
186
  var r;
187
187
  if (n.length > 2) {
188
- const a = n.pop();
189
- e += `one of type ${n.join(", ")}, or ${a}.`;
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) => U("Key must be ", e, ...t);
195
- function $(e, t, ...n) {
196
- return U(`Key for the ${e} algorithm must be `, t, ...n);
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 k = (e) => D(e), S = ["CryptoKey"], X = (...e) => {
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 a = Object.keys(r);
204
+ const o = Object.keys(r);
205
205
  if (!n || n.size === 0) {
206
- n = new Set(a);
206
+ n = new Set(o);
207
207
  continue;
208
208
  }
209
- for (const i of a) {
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 C(e) {
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 a = e.subarray(r, r + t.length);
242
- return a.length !== t.length ? !1 : a.every((i, o) => i === t[o]) || y(e, t, r + 1);
243
- }, W = (e) => {
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";
@@ -259,19 +259,19 @@ const Z = (e, t) => {
259
259
  default:
260
260
  throw new I("Invalid or unsupported EC Key Curve or OKP Key Sub Type");
261
261
  }
262
- }, ee = async (e, t, n, r, a) => {
263
- let i, o;
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)}` }, o = ["verify"];
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)}` }, o = ["verify"];
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
- }, o = ["encrypt", "wrapKey"];
283
+ }, a = ["encrypt", "wrapKey"];
284
284
  break;
285
285
  case "ES256":
286
- i = { name: "ECDSA", namedCurve: "P-256" }, o = ["verify"];
286
+ i = { name: "ECDSA", namedCurve: "P-256" }, a = ["verify"];
287
287
  break;
288
288
  case "ES384":
289
- i = { name: "ECDSA", namedCurve: "P-384" }, o = ["verify"];
289
+ i = { name: "ECDSA", namedCurve: "P-384" }, a = ["verify"];
290
290
  break;
291
291
  case "ES512":
292
- i = { name: "ECDSA", namedCurve: "P-521" }, o = ["verify"];
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 = W(c);
299
- i = s.startsWith("P-") ? { name: "ECDH", namedCurve: s } : { name: s }, o = [];
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: W(c) }, o = ["verify"];
303
+ i = { name: K(c) }, a = ["verify"];
304
304
  break;
305
305
  default:
306
306
  throw new I('Invalid or unsupported "alg" (Algorithm) value');
307
307
  }
308
- return P.subtle.importKey(t, c, i, !1, o);
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 (!k(t))
318
- throw new TypeError($(e, t, ...S, "Uint8Array"));
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
- }, ae = (e, t, n) => {
323
- if (!k(t))
324
- throw new TypeError($(e, t, ...S));
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
- }, oe = (e, t, n) => {
332
- e.startsWith("HS") || e === "dir" || e.startsWith("PBES2") || /^A\d{3}(?:GCM)?KW$/.test(e) ? ne(e, t) : ae(e, t, n);
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, a) {
335
- if (a.crit !== void 0 && (r == null ? void 0 : r.crit) === void 0)
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((o) => typeof o != "string" || o.length === 0))
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 o of r.crit) {
344
- if (!i.has(o))
345
- throw new I(`Extension Header Parameter "${o}" is not recognized`);
346
- if (a[o] === void 0)
347
- throw new e(`Extension Header Parameter "${o}" is missing`);
348
- if (i.get(o) && r[o] === void 0)
349
- throw new e(`Extension Header Parameter "${o}" MUST be integrity protected`);
343
+ for (const a of r.crit) {
344
+ if (!i.has(a))
345
+ throw new I(`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
  }
@@ -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 a = await de(e, t, "verify");
396
- Z(e, a);
397
- const i = se(e, a.algorithm);
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, a, n, r);
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 (!C(e))
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,128 +412,128 @@ 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 && !C(e.header))
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 _ = R(e.protected);
420
+ const _ = C(e.protected);
421
421
  r = JSON.parse(g.decode(_));
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 a = {
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, a);
431
- let o = !0;
432
- if (i.has("b64") && (o = r.b64, typeof o != "boolean"))
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 } = a;
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 (o) {
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), oe(c, t, "verify");
447
- const w = V(b.encode(e.protected ?? ""), b.encode("."), typeof e.payload == "string" ? b.encode(e.payload) : e.payload);
446
+ typeof t == "function" && (t = await t(r, e), l = !0), ae(c, t, "verify");
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
- f = R(e.signature);
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, w))
454
+ if (!await ue(c, t, f, E))
455
455
  throw new q();
456
456
  let m;
457
- if (o)
457
+ if (a)
458
458
  try {
459
- m = R(e.payload);
459
+ m = C(e.payload);
460
460
  } catch {
461
461
  throw new d("Failed to base64url decode the payload");
462
462
  }
463
463
  else
464
- typeof e.payload == "string" ? m = b.encode(e.payload) : m = e.payload;
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
  }
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: a, 2: i, length: o } = e.split(".");
472
- if (o !== 3)
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: a, protected: r, signature: i }, t, n), s = { payload: c.payload, protectedHeader: c.protectedHeader };
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, K = (e) => {
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 a;
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
- a = Math.round(n);
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
- a = Math.round(n * M);
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
- a = Math.round(n * B);
503
+ o = Math.round(n * B);
504
504
  break;
505
505
  case "day":
506
506
  case "days":
507
507
  case "d":
508
- a = Math.round(n * v);
508
+ o = Math.round(n * v);
509
509
  break;
510
510
  case "week":
511
511
  case "weeks":
512
512
  case "w":
513
- a = Math.round(n * pe);
513
+ o = Math.round(n * pe);
514
514
  break;
515
515
  default:
516
- a = Math.round(n * me);
516
+ o = Math.round(n * me);
517
517
  break;
518
518
  }
519
- return t[1] === "-" || t[4] === "ago" ? -a : a;
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 = {}) => {
519
+ return t[1] === "-" || t[4] === "ago" ? -o : o;
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));
524
524
  } catch {
525
525
  }
526
- if (!C(r))
527
- throw new L("JWT Claims Set must be a top-level JSON object");
528
- const { typ: a } = n;
529
- if (a && (typeof e.typ != "string" || H(e.typ) !== H(a)))
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" || N(e.typ) !== N(o)))
530
530
  throw new h('unexpected "typ" JWT header value', r, "typ", "check_failed");
531
- const { requiredClaims: i = [], issuer: o, 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"), o !== void 0 && w.push("iss");
533
- for (const u of new Set(w.reverse()))
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
- if (o && !(Array.isArray(o) ? o : [o]).includes(r.iss))
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 = K(n.clockTolerance);
545
+ f = W(n.clockTolerance);
546
546
  break;
547
547
  case "number":
548
548
  f = n.clockTolerance;
@@ -569,7 +569,7 @@ 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, _ = typeof l == "number" ? l : K(l);
572
+ const u = m - r.iat, _ = typeof l == "number" ? l : W(l);
573
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)
@@ -577,24 +577,26 @@ const le = (e) => Math.floor(e.getTime() / 1e3), M = 60, B = M * 60, v = B * 24,
577
577
  }
578
578
  return r;
579
579
  };
580
- async function Ee(e, t, n) {
581
- var o;
580
+ async function we(e, t, n) {
581
+ var a;
582
582
  const r = await he(e, t, n);
583
- if ((o = r.protectedHeader.crit) != null && o.includes("b64") && r.protectedHeader.b64 === !1)
584
- throw new L("JWTs MUST NOT use unencoded payload");
585
- const i = { payload: we(r.protectedHeader, r.payload, n), protectedHeader: r.protectedHeader };
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
+ 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 Ae = {
589
- ID_TOKEN: "id_token"
588
+ const be = {
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
- }, N = {
594
+ }, H = {
593
595
  ALG: "RS256",
594
596
  USER_ID_KEY: "_id",
595
597
  TOKEN_ID_KEY: "__raw",
596
598
  ISSUER: "gizmette.com"
597
- }, be = `-----BEGIN PUBLIC KEY-----
599
+ }, Ae = `-----BEGIN PUBLIC KEY-----
598
600
  MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAsF6i3Jd9fY/3COqCw/m7
599
601
  w5PKyTYLGAI2I6SIIdpe6i6DOCbEkmDz7LdVsBqwNtVi8gvWYIj+8ol6rU3qu1v5
600
602
  i1Jd45GSK4kzkVdgCmQZbM5ak0KI99q5wsrAIzUd+LRJ2HRvWtr5IYdsIiXaQjle
@@ -602,11 +604,14 @@ aMwPFOIcJH+rKfFgNcHLcaS5syp7zU1ANwZ+trgR+DifBr8TLVkBynmNeTyhDm2+
602
604
  l0haqjMk0UoNPPE8iYBWUHQJJE1Dqstj65d6Eh5g64Pao25y4cmYJbKjiblIGEkE
603
605
  sjqybA9mARAqh9k/eiIopecWSiffNQTwVQVd2I9ZH3BalhEXHlqFgrjz51kFqg81
604
606
  awIDAQAB
605
- -----END PUBLIC KEY-----`, Ie = async (e, t) => {
607
+ -----END PUBLIC KEY-----`, Ie = {
608
+ ACCESS: "5m",
609
+ ID: "90d"
610
+ }, _e = async (e, t) => {
606
611
  try {
607
- const n = N.ALG, a = await re(be, n);
608
- return await Ee(e, a, {
609
- issuer: N.ISSUER,
612
+ const n = H.ALG, o = await re(Ae, n);
613
+ return await we(e, o, {
614
+ issuer: H.ISSUER,
610
615
  audience: t
611
616
  });
612
617
  } catch {
@@ -614,9 +619,10 @@ awIDAQAB
614
619
  }
615
620
  };
616
621
  export {
617
- Ae as AUTH_TYPES,
622
+ be as AUTH_TYPES,
618
623
  ge as HEADERS,
619
- N as JWT,
620
- be as JWT_PUBLIC_KEY,
621
- Ie as verifyAndExtractToken
624
+ H as JWT,
625
+ Ae as JWT_PUBLIC_KEY,
626
+ Ie as TOKEN_EXPIRATION,
627
+ _e as verifyAndExtractToken
622
628
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@versini/auth-common",
3
- "version": "2.3.0",
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": "3dd474c4a7e9b9595df1ff4a2c16a18dff8fe193"
35
+ "gitHead": "25c60a5226b6f9d95aa3a3fcdbbc8448181e937a"
36
36
  }