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