@versini/auth-common 3.0.0 → 3.1.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
@@ -21,6 +21,9 @@ declare const JWT: {
21
21
  NONCE_KEY: string;
22
22
  USERNAME_KEY: string;
23
23
  AUTH_TYPE_KEY: string;
24
+ EXPIRES_AT_KEY: string;
25
+ CREATED_AT_KEY: string;
26
+ SCOPES_KEY: string;
24
27
  ISSUER: string;
25
28
  };
26
29
  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 v3.0.0
2
+ @versini/auth-common v3.1.0
3
3
  © 2024 gizmette.com
4
4
  */
5
5
  try {
6
6
  window.__VERSINI_AUTH_COMMON__ || (window.__VERSINI_AUTH_COMMON__ = {
7
- version: "3.0.0",
8
- buildTime: "07/19/2024 09:13 AM EDT",
7
+ version: "3.1.0",
8
+ buildTime: "07/21/2024 02:46 PM EDT",
9
9
  homepage: "https://github.com/aversini/auth-client",
10
10
  license: "MIT"
11
11
  });
@@ -29,6 +29,9 @@ const Ze = {
29
29
  NONCE_KEY: "_nonce",
30
30
  USERNAME_KEY: "username",
31
31
  AUTH_TYPE_KEY: "auth_type",
32
+ EXPIRES_AT_KEY: "exp",
33
+ CREATED_AT_KEY: "iat",
34
+ SCOPES_KEY: "scopes",
32
35
  ISSUER: "gizmette.com"
33
36
  }, ae = `-----BEGIN PUBLIC KEY-----
34
37
  MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAsF6i3Jd9fY/3COqCw/m7
@@ -46,7 +49,7 @@ awIDAQAB
46
49
  AUTHENTICATE: "authenticate",
47
50
  CODE: "code",
48
51
  LOGOUT: "logout"
49
- }, K = crypto, q = (e) => e instanceof CryptoKey, v = new TextEncoder(), C = new TextDecoder();
52
+ }, K = crypto, q = (e) => e instanceof CryptoKey, T = new TextEncoder(), C = new TextDecoder();
50
53
  function oe(...e) {
51
54
  const t = e.reduce((a, { length: i }) => a + i, 0), r = new Uint8Array(t);
52
55
  let n = 0;
@@ -136,7 +139,7 @@ class se extends A {
136
139
  function m(e, t = "algorithm.name") {
137
140
  return new TypeError(`CryptoKey does not support this operation, its ${t} must be ${e}`);
138
141
  }
139
- function T(e, t) {
142
+ function v(e, t) {
140
143
  return e.name === t;
141
144
  }
142
145
  function x(e) {
@@ -169,7 +172,7 @@ function le(e, t, ...r) {
169
172
  case "HS256":
170
173
  case "HS384":
171
174
  case "HS512": {
172
- if (!T(e.algorithm, "HMAC"))
175
+ if (!v(e.algorithm, "HMAC"))
173
176
  throw m("HMAC");
174
177
  const n = parseInt(t.slice(2), 10);
175
178
  if (x(e.algorithm.hash) !== n)
@@ -179,7 +182,7 @@ function le(e, t, ...r) {
179
182
  case "RS256":
180
183
  case "RS384":
181
184
  case "RS512": {
182
- if (!T(e.algorithm, "RSASSA-PKCS1-v1_5"))
185
+ if (!v(e.algorithm, "RSASSA-PKCS1-v1_5"))
183
186
  throw m("RSASSA-PKCS1-v1_5");
184
187
  const n = parseInt(t.slice(2), 10);
185
188
  if (x(e.algorithm.hash) !== n)
@@ -189,7 +192,7 @@ function le(e, t, ...r) {
189
192
  case "PS256":
190
193
  case "PS384":
191
194
  case "PS512": {
192
- if (!T(e.algorithm, "RSA-PSS"))
195
+ if (!v(e.algorithm, "RSA-PSS"))
193
196
  throw m("RSA-PSS");
194
197
  const n = parseInt(t.slice(2), 10);
195
198
  if (x(e.algorithm.hash) !== n)
@@ -204,7 +207,7 @@ function le(e, t, ...r) {
204
207
  case "ES256":
205
208
  case "ES384":
206
209
  case "ES512": {
207
- if (!T(e.algorithm, "ECDSA"))
210
+ if (!v(e.algorithm, "ECDSA"))
208
211
  throw m("ECDSA");
209
212
  const n = de(t);
210
213
  if (e.algorithm.namedCurve !== n)
@@ -228,7 +231,7 @@ const L = (e, ...t) => z("Key must be ", e, ...t);
228
231
  function G(e, t, ...r) {
229
232
  return z(`Key for the ${e} algorithm must be `, t, ...r);
230
233
  }
231
- const Q = (e) => q(e) ? !0 : (e == null ? void 0 : e[Symbol.toStringTag]) === "KeyObject", R = ["CryptoKey"], fe = (...e) => {
234
+ const X = (e) => q(e) ? !0 : (e == null ? void 0 : e[Symbol.toStringTag]) === "KeyObject", R = ["CryptoKey"], fe = (...e) => {
232
235
  const t = e.filter(Boolean);
233
236
  if (t.length === 0 || t.length === 1)
234
237
  return !0;
@@ -348,7 +351,7 @@ const Se = async (e) => {
348
351
  e.key_ops ?? r
349
352
  ], a = { ...e };
350
353
  return delete a.alg, delete a.use, K.subtle.importKey("jwk", a, ...n);
351
- }, X = (e) => b(e);
354
+ }, Q = (e) => b(e);
352
355
  let W, J;
353
356
  const Z = (e) => (e == null ? void 0 : e[Symbol.toStringTag]) === "KeyObject", j = async (e, t, r, n) => {
354
357
  let a = e.get(t);
@@ -359,13 +362,13 @@ const Z = (e) => (e == null ? void 0 : e[Symbol.toStringTag]) === "KeyObject", j
359
362
  }, ye = (e, t) => {
360
363
  if (Z(e)) {
361
364
  let r = e.export({ format: "jwk" });
362
- return delete r.d, delete r.dp, delete r.dq, delete r.p, delete r.q, delete r.qi, r.k ? X(r.k) : (J || (J = /* @__PURE__ */ new WeakMap()), j(J, e, r, t));
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) : (J || (J = /* @__PURE__ */ new WeakMap()), j(J, e, r, t));
363
366
  }
364
367
  return e;
365
368
  }, Ee = (e, t) => {
366
369
  if (Z(e)) {
367
370
  let r = e.export({ format: "jwk" });
368
- return r.k ? X(r.k) : (W || (W = /* @__PURE__ */ new WeakMap()), j(W, e, r, t));
371
+ return r.k ? Q(r.k) : (W || (W = /* @__PURE__ */ new WeakMap()), j(W, e, r, t));
369
372
  }
370
373
  return e;
371
374
  }, we = { normalizePublicKey: ye, normalizePrivateKey: Ee }, E = (e, t, r = 0) => {
@@ -449,13 +452,13 @@ async function be(e, t, r) {
449
452
  }
450
453
  const I = (e) => e == null ? void 0 : e[Symbol.toStringTag], Ce = (e, t) => {
451
454
  if (!(t instanceof Uint8Array)) {
452
- if (!Q(t))
455
+ if (!X(t))
453
456
  throw new TypeError(G(e, t, ...R, "Uint8Array"));
454
457
  if (t.type !== "secret")
455
458
  throw new TypeError(`${I(t)} instances for symmetric algorithms must be of type "secret"`);
456
459
  }
457
- }, ve = (e, t, r) => {
458
- if (!Q(t))
460
+ }, Te = (e, t, r) => {
461
+ if (!X(t))
459
462
  throw new TypeError(G(e, t, ...R));
460
463
  if (t.type === "secret")
461
464
  throw new TypeError(`${I(t)} instances for asymmetric algorithms must not be of type "secret"`);
@@ -463,8 +466,8 @@ const I = (e) => e == null ? void 0 : e[Symbol.toStringTag], Ce = (e, t) => {
463
466
  throw new TypeError(`${I(t)} instances for asymmetric algorithm verifying must be of type "public"`);
464
467
  if (t.algorithm && r === "encrypt" && t.type === "private")
465
468
  throw new TypeError(`${I(t)} instances for asymmetric algorithm encryption must be of type "public"`);
466
- }, Te = (e, t, r) => {
467
- e.startsWith("HS") || e === "dir" || e.startsWith("PBES2") || /^A\d{3}(?:GCM)?KW$/.test(e) ? Ce(e, t) : ve(e, t, r);
469
+ }, ve = (e, t, r) => {
470
+ e.startsWith("HS") || e === "dir" || e.startsWith("PBES2") || /^A\d{3}(?:GCM)?KW$/.test(e) ? Ce(e, t) : Te(e, t, r);
468
471
  };
469
472
  function _e(e, t, r, n, a) {
470
473
  if (a.crit !== void 0 && (n == null ? void 0 : n.crit) === void 0)
@@ -578,8 +581,8 @@ async function Oe(e, t, r) {
578
581
  } else if (typeof e.payload != "string" && !(e.payload instanceof Uint8Array))
579
582
  throw new u("JWS Payload must be a string or an Uint8Array instance");
580
583
  let p = !1;
581
- typeof t == "function" && (t = await t(n, e), p = !0), Te(c, t, "verify");
582
- const g = oe(v.encode(e.protected ?? ""), v.encode("."), typeof e.payload == "string" ? v.encode(e.payload) : e.payload);
584
+ typeof t == "function" && (t = await t(n, e), p = !0), ve(c, t, "verify");
585
+ const g = oe(T.encode(e.protected ?? ""), T.encode("."), typeof e.payload == "string" ? T.encode(e.payload) : e.payload);
583
586
  let f;
584
587
  try {
585
588
  f = b(e.signature);
@@ -595,7 +598,7 @@ async function Oe(e, t, r) {
595
598
  } catch {
596
599
  throw new u("Failed to base64url decode the payload");
597
600
  }
598
- else typeof e.payload == "string" ? y = v.encode(e.payload) : y = e.payload;
601
+ else typeof e.payload == "string" ? y = T.encode(e.payload) : y = e.payload;
599
602
  const l = { payload: y };
600
603
  return e.protected !== void 0 && (l.protectedHeader = n), e.header !== void 0 && (l.unprotectedHeader = e.header), p ? { ...l, key: t } : l;
601
604
  }
@@ -810,25 +813,25 @@ async function ot(e, t) {
810
813
  return t === await re(e);
811
814
  }
812
815
  const ze = /^Bearer (.+)$/i, Ge = (e) => {
813
- if (typeof e.authorization != "string")
816
+ if (typeof (e == null ? void 0 : e.authorization) != "string")
814
817
  return;
815
818
  const t = e.authorization.match(ze);
816
819
  if (t)
817
820
  return t[1];
818
- }, Qe = (e, t) => {
819
- const r = e.cookie, n = new RegExp(`auth.${t}=(.+?)(?:;|$)`);
821
+ }, Xe = (e, t) => {
822
+ const r = e == null ? void 0 : e.cookie;
820
823
  if (typeof r != "string")
821
824
  return;
822
- const a = r.match(n);
825
+ const n = new RegExp(`auth.${t}=(.+?)(?:;|$)`), a = r.match(n);
823
826
  if (a)
824
827
  return a[1];
825
- }, Xe = (e) => {
828
+ }, Qe = (e) => {
826
829
  const t = e == null ? void 0 : e[ne.ACCESS_TOKEN];
827
830
  if (typeof t == "string")
828
831
  return t;
829
832
  }, it = ({ headers: e, body: t, clientId: r }) => {
830
- const n = Ge(e), a = Qe(e, r);
831
- return Xe(t) || a || n || "";
833
+ const n = Ge(e), a = Xe(e, r);
834
+ return Qe(t) || a || n || "";
832
835
  };
833
836
  export {
834
837
  tt as API_TYPE,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@versini/auth-common",
3
- "version": "3.0.0",
3
+ "version": "3.1.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": "ce92ce0065a9faf54d5c498ff63a195b249043af"
39
+ "gitHead": "cb10c89f218f72ec549147c737cad75ad1e7e6bb"
40
40
  }