@versini/auth-common 3.3.0 → 3.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 +15 -1
- package/dist/index.js +79 -70
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -24,6 +24,7 @@ declare const JWT: {
|
|
|
24
24
|
EXPIRES_AT_KEY: string;
|
|
25
25
|
CREATED_AT_KEY: string;
|
|
26
26
|
SCOPES_KEY: string;
|
|
27
|
+
CLIENT_ID_KEY: string;
|
|
27
28
|
ISSUER: string;
|
|
28
29
|
};
|
|
29
30
|
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-----";
|
|
@@ -133,4 +134,17 @@ type ScopesGrants = {
|
|
|
133
134
|
*/
|
|
134
135
|
declare const isGranted: (token: string, scopes: ScopesGrants) => Promise<boolean>;
|
|
135
136
|
|
|
136
|
-
|
|
137
|
+
/**
|
|
138
|
+
* Get a Session Id from a request.
|
|
139
|
+
*
|
|
140
|
+
* @param headers An object containing the request headers, usually `req.headers`.
|
|
141
|
+
* @param clientId The client ID to use.
|
|
142
|
+
*
|
|
143
|
+
*/
|
|
144
|
+
type GetSessionProps = {
|
|
145
|
+
clientId: string;
|
|
146
|
+
headers: HeadersLike;
|
|
147
|
+
};
|
|
148
|
+
declare const getSession: ({ headers, clientId }: GetSessionProps) => string;
|
|
149
|
+
|
|
150
|
+
export { API_TYPE, AUTH_TYPES, BODY, type BodyLike, HEADERS, type HeadersLike, JWT, JWT_PUBLIC_KEY, type ScopesGrants, TOKEN_EXPIRATION, decodeToken, generateCodeChallenge, getSession, getToken, isGranted, pkceChallengePair, verifyAndExtractToken, verifyChallenge };
|
package/dist/index.js
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
@versini/auth-common v3.
|
|
2
|
+
@versini/auth-common v3.4.0
|
|
3
3
|
© 2024 gizmette.com
|
|
4
4
|
*/
|
|
5
5
|
try {
|
|
6
6
|
window.__VERSINI_AUTH_COMMON__ || (window.__VERSINI_AUTH_COMMON__ = {
|
|
7
|
-
version: "3.
|
|
8
|
-
buildTime: "
|
|
7
|
+
version: "3.4.0",
|
|
8
|
+
buildTime: "08/19/2024 11:57 AM EDT",
|
|
9
9
|
homepage: "https://github.com/aversini/auth-client",
|
|
10
10
|
license: "MIT"
|
|
11
11
|
});
|
|
12
12
|
} catch {
|
|
13
13
|
}
|
|
14
|
-
const
|
|
14
|
+
const et = {
|
|
15
15
|
ID_TOKEN: "id_token",
|
|
16
16
|
ACCESS_TOKEN: "token",
|
|
17
17
|
ID_AND_ACCESS_TOKEN: "id_token token",
|
|
18
18
|
CODE: "code",
|
|
19
19
|
REFRESH_TOKEN: "refresh_token",
|
|
20
20
|
PASSKEY: "passkey"
|
|
21
|
-
},
|
|
21
|
+
}, tt = {
|
|
22
22
|
CLIENT_ID: "X-Auth-ClientId"
|
|
23
23
|
}, ne = {
|
|
24
24
|
ACCESS_TOKEN: "access_token"
|
|
25
|
-
},
|
|
25
|
+
}, R = {
|
|
26
26
|
ALG: "RS256",
|
|
27
27
|
USER_ID_KEY: "sub",
|
|
28
28
|
TOKEN_ID_KEY: "__raw",
|
|
@@ -32,6 +32,7 @@ const je = {
|
|
|
32
32
|
EXPIRES_AT_KEY: "exp",
|
|
33
33
|
CREATED_AT_KEY: "iat",
|
|
34
34
|
SCOPES_KEY: "scopes",
|
|
35
|
+
CLIENT_ID_KEY: "aud",
|
|
35
36
|
ISSUER: "gizmette.com"
|
|
36
37
|
}, ae = `-----BEGIN PUBLIC KEY-----
|
|
37
38
|
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAsF6i3Jd9fY/3COqCw/m7
|
|
@@ -41,11 +42,11 @@ aMwPFOIcJH+rKfFgNcHLcaS5syp7zU1ANwZ+trgR+DifBr8TLVkBynmNeTyhDm2+
|
|
|
41
42
|
l0haqjMk0UoNPPE8iYBWUHQJJE1Dqstj65d6Eh5g64Pao25y4cmYJbKjiblIGEkE
|
|
42
43
|
sjqybA9mARAqh9k/eiIopecWSiffNQTwVQVd2I9ZH3BalhEXHlqFgrjz51kFqg81
|
|
43
44
|
awIDAQAB
|
|
44
|
-
-----END PUBLIC KEY-----`,
|
|
45
|
+
-----END PUBLIC KEY-----`, rt = {
|
|
45
46
|
ACCESS: "5m",
|
|
46
47
|
ID: "90d",
|
|
47
48
|
REFRESH: "90d"
|
|
48
|
-
},
|
|
49
|
+
}, nt = {
|
|
49
50
|
AUTHENTICATE: "authenticate",
|
|
50
51
|
CODE: "code",
|
|
51
52
|
LOGOUT: "logout"
|
|
@@ -139,7 +140,7 @@ class se extends A {
|
|
|
139
140
|
function m(e, t = "algorithm.name") {
|
|
140
141
|
return new TypeError(`CryptoKey does not support this operation, its ${t} must be ${e}`);
|
|
141
142
|
}
|
|
142
|
-
function
|
|
143
|
+
function _(e, t) {
|
|
143
144
|
return e.name === t;
|
|
144
145
|
}
|
|
145
146
|
function W(e) {
|
|
@@ -172,7 +173,7 @@ function le(e, t, ...r) {
|
|
|
172
173
|
case "HS256":
|
|
173
174
|
case "HS384":
|
|
174
175
|
case "HS512": {
|
|
175
|
-
if (!
|
|
176
|
+
if (!_(e.algorithm, "HMAC"))
|
|
176
177
|
throw m("HMAC");
|
|
177
178
|
const n = parseInt(t.slice(2), 10);
|
|
178
179
|
if (W(e.algorithm.hash) !== n)
|
|
@@ -182,7 +183,7 @@ function le(e, t, ...r) {
|
|
|
182
183
|
case "RS256":
|
|
183
184
|
case "RS384":
|
|
184
185
|
case "RS512": {
|
|
185
|
-
if (!
|
|
186
|
+
if (!_(e.algorithm, "RSASSA-PKCS1-v1_5"))
|
|
186
187
|
throw m("RSASSA-PKCS1-v1_5");
|
|
187
188
|
const n = parseInt(t.slice(2), 10);
|
|
188
189
|
if (W(e.algorithm.hash) !== n)
|
|
@@ -192,7 +193,7 @@ function le(e, t, ...r) {
|
|
|
192
193
|
case "PS256":
|
|
193
194
|
case "PS384":
|
|
194
195
|
case "PS512": {
|
|
195
|
-
if (!
|
|
196
|
+
if (!_(e.algorithm, "RSA-PSS"))
|
|
196
197
|
throw m("RSA-PSS");
|
|
197
198
|
const n = parseInt(t.slice(2), 10);
|
|
198
199
|
if (W(e.algorithm.hash) !== n)
|
|
@@ -207,7 +208,7 @@ function le(e, t, ...r) {
|
|
|
207
208
|
case "ES256":
|
|
208
209
|
case "ES384":
|
|
209
210
|
case "ES512": {
|
|
210
|
-
if (!
|
|
211
|
+
if (!_(e.algorithm, "ECDSA"))
|
|
211
212
|
throw m("ECDSA");
|
|
212
213
|
const n = de(t);
|
|
213
214
|
if (e.algorithm.namedCurve !== n)
|
|
@@ -231,7 +232,7 @@ const L = (e, ...t) => q("Key must be ", e, ...t);
|
|
|
231
232
|
function z(e, t, ...r) {
|
|
232
233
|
return q(`Key for the ${e} algorithm must be `, t, ...r);
|
|
233
234
|
}
|
|
234
|
-
const X = (e) => G(e) ? !0 : (e == null ? void 0 : e[Symbol.toStringTag]) === "KeyObject",
|
|
235
|
+
const X = (e) => G(e) ? !0 : (e == null ? void 0 : e[Symbol.toStringTag]) === "KeyObject", P = ["CryptoKey"], fe = (...e) => {
|
|
235
236
|
const t = e.filter(Boolean);
|
|
236
237
|
if (t.length === 0 || t.length === 1)
|
|
237
238
|
return !0;
|
|
@@ -352,7 +353,7 @@ const Se = async (e) => {
|
|
|
352
353
|
], a = { ...e };
|
|
353
354
|
return delete a.alg, delete a.use, O.subtle.importKey("jwk", a, ...n);
|
|
354
355
|
}, Q = (e) => b(e);
|
|
355
|
-
let
|
|
356
|
+
let D, J;
|
|
356
357
|
const Z = (e) => (e == null ? void 0 : e[Symbol.toStringTag]) === "KeyObject", j = async (e, t, r, n) => {
|
|
357
358
|
let a = e.get(t);
|
|
358
359
|
if (a != null && a[n])
|
|
@@ -362,13 +363,13 @@ const Z = (e) => (e == null ? void 0 : e[Symbol.toStringTag]) === "KeyObject", j
|
|
|
362
363
|
}, ye = (e, t) => {
|
|
363
364
|
if (Z(e)) {
|
|
364
365
|
let r = e.export({ format: "jwk" });
|
|
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) : (
|
|
366
|
+
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));
|
|
366
367
|
}
|
|
367
368
|
return e;
|
|
368
369
|
}, Ee = (e, t) => {
|
|
369
370
|
if (Z(e)) {
|
|
370
371
|
let r = e.export({ format: "jwk" });
|
|
371
|
-
return r.k ? Q(r.k) : (
|
|
372
|
+
return r.k ? Q(r.k) : (D || (D = /* @__PURE__ */ new WeakMap()), j(D, e, r, t));
|
|
372
373
|
}
|
|
373
374
|
return e;
|
|
374
375
|
}, we = { normalizePublicKey: ye, normalizePrivateKey: Ee }, E = (e, t, r = 0) => {
|
|
@@ -450,26 +451,26 @@ async function be(e, t, r) {
|
|
|
450
451
|
throw new TypeError('"spki" must be SPKI formatted string');
|
|
451
452
|
return Ae(e, t);
|
|
452
453
|
}
|
|
453
|
-
const
|
|
454
|
+
const I = (e) => e == null ? void 0 : e[Symbol.toStringTag], Ce = (e, t) => {
|
|
454
455
|
if (!(t instanceof Uint8Array)) {
|
|
455
456
|
if (!X(t))
|
|
456
|
-
throw new TypeError(z(e, t, ...
|
|
457
|
+
throw new TypeError(z(e, t, ...P, "Uint8Array"));
|
|
457
458
|
if (t.type !== "secret")
|
|
458
|
-
throw new TypeError(`${
|
|
459
|
+
throw new TypeError(`${I(t)} instances for symmetric algorithms must be of type "secret"`);
|
|
459
460
|
}
|
|
460
461
|
}, Te = (e, t, r) => {
|
|
461
462
|
if (!X(t))
|
|
462
|
-
throw new TypeError(z(e, t, ...
|
|
463
|
+
throw new TypeError(z(e, t, ...P));
|
|
463
464
|
if (t.type === "secret")
|
|
464
|
-
throw new TypeError(`${
|
|
465
|
+
throw new TypeError(`${I(t)} instances for asymmetric algorithms must not be of type "secret"`);
|
|
465
466
|
if (t.algorithm && r === "verify" && t.type === "private")
|
|
466
|
-
throw new TypeError(`${
|
|
467
|
+
throw new TypeError(`${I(t)} instances for asymmetric algorithm verifying must be of type "public"`);
|
|
467
468
|
if (t.algorithm && r === "encrypt" && t.type === "private")
|
|
468
|
-
throw new TypeError(`${
|
|
469
|
-
},
|
|
469
|
+
throw new TypeError(`${I(t)} instances for asymmetric algorithm encryption must be of type "public"`);
|
|
470
|
+
}, _e = (e, t, r) => {
|
|
470
471
|
e.startsWith("HS") || e === "dir" || e.startsWith("PBES2") || /^A\d{3}(?:GCM)?KW$/.test(e) ? Ce(e, t) : Te(e, t, r);
|
|
471
472
|
};
|
|
472
|
-
function
|
|
473
|
+
function ve(e, t, r, n, a) {
|
|
473
474
|
if (a.crit !== void 0 && (n == null ? void 0 : n.crit) === void 0)
|
|
474
475
|
throw new e('"crit" (Critical) Header Parameter MUST be integrity protected');
|
|
475
476
|
if (!n || n.crit === void 0)
|
|
@@ -488,13 +489,13 @@ function _e(e, t, r, n, a) {
|
|
|
488
489
|
}
|
|
489
490
|
return new Set(n.crit);
|
|
490
491
|
}
|
|
491
|
-
const
|
|
492
|
+
const Ie = (e, t) => {
|
|
492
493
|
if (t !== void 0 && (!Array.isArray(t) || t.some((r) => typeof r != "string")))
|
|
493
494
|
throw new TypeError(`"${e}" option must be an array of strings`);
|
|
494
495
|
if (t)
|
|
495
496
|
return new Set(t);
|
|
496
497
|
};
|
|
497
|
-
function
|
|
498
|
+
function Re(e, t) {
|
|
498
499
|
const r = `SHA-${e.slice(-3)}`;
|
|
499
500
|
switch (e) {
|
|
500
501
|
case "HS256":
|
|
@@ -519,20 +520,20 @@ function Ie(e, t) {
|
|
|
519
520
|
throw new w(`alg ${e} is not supported either by JOSE or your javascript runtime`);
|
|
520
521
|
}
|
|
521
522
|
}
|
|
522
|
-
async function
|
|
523
|
+
async function Pe(e, t, r) {
|
|
523
524
|
if (t = await we.normalizePublicKey(t, e), G(t))
|
|
524
525
|
return le(t, e, r), t;
|
|
525
526
|
if (t instanceof Uint8Array) {
|
|
526
527
|
if (!e.startsWith("HS"))
|
|
527
|
-
throw new TypeError(L(t, ...
|
|
528
|
+
throw new TypeError(L(t, ...P));
|
|
528
529
|
return O.subtle.importKey("raw", t, { hash: `SHA-${e.slice(-3)}`, name: "HMAC" }, !1, [r]);
|
|
529
530
|
}
|
|
530
|
-
throw new TypeError(L(t, ...
|
|
531
|
+
throw new TypeError(L(t, ...P, "Uint8Array"));
|
|
531
532
|
}
|
|
532
533
|
const Ke = async (e, t, r, n) => {
|
|
533
|
-
const a = await
|
|
534
|
+
const a = await Pe(e, t, "verify");
|
|
534
535
|
pe(e, a);
|
|
535
|
-
const o =
|
|
536
|
+
const o = Re(e, a.algorithm);
|
|
536
537
|
try {
|
|
537
538
|
return await O.subtle.verify(o, a, r, n);
|
|
538
539
|
} catch {
|
|
@@ -565,14 +566,14 @@ async function Oe(e, t, r) {
|
|
|
565
566
|
const a = {
|
|
566
567
|
...n,
|
|
567
568
|
...e.header
|
|
568
|
-
}, o =
|
|
569
|
+
}, o = ve(u, /* @__PURE__ */ new Map([["b64", !0]]), r == null ? void 0 : r.crit, n, a);
|
|
569
570
|
let i = !0;
|
|
570
571
|
if (o.has("b64") && (i = n.b64, typeof i != "boolean"))
|
|
571
572
|
throw new u('The "b64" (base64url-encode payload) Header Parameter must be a boolean');
|
|
572
573
|
const { alg: c } = a;
|
|
573
574
|
if (typeof c != "string" || !c)
|
|
574
575
|
throw new u('JWS "alg" (Algorithm) Header Parameter missing or invalid');
|
|
575
|
-
const s = r &&
|
|
576
|
+
const s = r && Ie("algorithms", r.algorithms);
|
|
576
577
|
if (s && !s.has(c))
|
|
577
578
|
throw new ce('"alg" (Algorithm) Header Parameter value not allowed');
|
|
578
579
|
if (i) {
|
|
@@ -581,7 +582,7 @@ async function Oe(e, t, r) {
|
|
|
581
582
|
} else if (typeof e.payload != "string" && !(e.payload instanceof Uint8Array))
|
|
582
583
|
throw new u("JWS Payload must be a string or an Uint8Array instance");
|
|
583
584
|
let p = !1;
|
|
584
|
-
typeof t == "function" && (t = await t(n, e), p = !0),
|
|
585
|
+
typeof t == "function" && (t = await t(n, e), p = !0), _e(c, t, "verify");
|
|
585
586
|
const g = oe(T.encode(e.protected ?? ""), T.encode("."), typeof e.payload == "string" ? T.encode(e.payload) : e.payload);
|
|
586
587
|
let f;
|
|
587
588
|
try {
|
|
@@ -611,7 +612,7 @@ async function xe(e, t, r) {
|
|
|
611
612
|
const c = await Oe({ payload: a, protected: n, signature: o }, t, r), s = { payload: c.payload, protectedHeader: c.protectedHeader };
|
|
612
613
|
return typeof t == "function" ? { ...s, key: c.key } : s;
|
|
613
614
|
}
|
|
614
|
-
const We = (e) => Math.floor(e.getTime() / 1e3), ee = 60, te = ee * 60, N = te * 24,
|
|
615
|
+
const We = (e) => Math.floor(e.getTime() / 1e3), ee = 60, te = ee * 60, N = te * 24, De = N * 7, Je = N * 365.25, He = /^(\+|\-)? ?(\d+|\d+\.\d+) ?(seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)(?: (ago|from now))?$/i, M = (e) => {
|
|
615
616
|
const t = He.exec(e);
|
|
616
617
|
if (!t || t[4] && t[1])
|
|
617
618
|
throw new TypeError("Invalid time period format");
|
|
@@ -647,10 +648,10 @@ const We = (e) => Math.floor(e.getTime() / 1e3), ee = 60, te = ee * 60, N = te *
|
|
|
647
648
|
case "week":
|
|
648
649
|
case "weeks":
|
|
649
650
|
case "w":
|
|
650
|
-
a = Math.round(r *
|
|
651
|
+
a = Math.round(r * De);
|
|
651
652
|
break;
|
|
652
653
|
default:
|
|
653
|
-
a = Math.round(r *
|
|
654
|
+
a = Math.round(r * Je);
|
|
654
655
|
break;
|
|
655
656
|
}
|
|
656
657
|
return t[1] === "-" || t[4] === "ago" ? -a : a;
|
|
@@ -751,14 +752,14 @@ function ke(e) {
|
|
|
751
752
|
}
|
|
752
753
|
const Me = async (e) => {
|
|
753
754
|
try {
|
|
754
|
-
const t =
|
|
755
|
+
const t = R.ALG, n = await be(ae, t);
|
|
755
756
|
return await $e(e, n, {
|
|
756
|
-
issuer:
|
|
757
|
+
issuer: R.ISSUER
|
|
757
758
|
});
|
|
758
759
|
} catch {
|
|
759
760
|
return;
|
|
760
761
|
}
|
|
761
|
-
},
|
|
762
|
+
}, at = (e) => {
|
|
762
763
|
try {
|
|
763
764
|
return ke(e);
|
|
764
765
|
} catch {
|
|
@@ -771,35 +772,35 @@ for (var H = 0; H < 256; ++H)
|
|
|
771
772
|
function Be(e, t = 0) {
|
|
772
773
|
return (d[e[t + 0]] + d[e[t + 1]] + d[e[t + 2]] + d[e[t + 3]] + "-" + d[e[t + 4]] + d[e[t + 5]] + "-" + d[e[t + 6]] + d[e[t + 7]] + "-" + d[e[t + 8]] + d[e[t + 9]] + "-" + d[e[t + 10]] + d[e[t + 11]] + d[e[t + 12]] + d[e[t + 13]] + d[e[t + 14]] + d[e[t + 15]]).toLowerCase();
|
|
773
774
|
}
|
|
774
|
-
var
|
|
775
|
-
function
|
|
776
|
-
if (!
|
|
775
|
+
var v, Fe = new Uint8Array(16);
|
|
776
|
+
function Ye() {
|
|
777
|
+
if (!v && (v = typeof crypto < "u" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto), !v))
|
|
777
778
|
throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
|
|
778
|
-
return
|
|
779
|
+
return v(Fe);
|
|
779
780
|
}
|
|
780
|
-
var
|
|
781
|
+
var Ve = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto);
|
|
781
782
|
const F = {
|
|
782
|
-
randomUUID:
|
|
783
|
+
randomUUID: Ve
|
|
783
784
|
};
|
|
784
|
-
function
|
|
785
|
+
function Y(e, t, r) {
|
|
785
786
|
if (F.randomUUID && !t && !e)
|
|
786
787
|
return F.randomUUID();
|
|
787
788
|
e = e || {};
|
|
788
|
-
var n = e.random || (e.rng ||
|
|
789
|
+
var n = e.random || (e.rng || Ye)();
|
|
789
790
|
return n[6] = n[6] & 15 | 64, n[8] = n[8] & 63 | 128, Be(n);
|
|
790
791
|
}
|
|
791
|
-
const
|
|
792
|
+
const V = globalThis.crypto, Ge = (e) => `${Y()}${Y()}`.slice(0, e), qe = (e) => btoa(
|
|
792
793
|
[...new Uint8Array(e)].map((t) => String.fromCharCode(t)).join("")
|
|
793
794
|
);
|
|
794
795
|
async function re(e) {
|
|
795
|
-
if (!
|
|
796
|
+
if (!V.subtle)
|
|
796
797
|
throw new Error(
|
|
797
798
|
"crypto.subtle is available only in secure contexts (HTTPS)."
|
|
798
799
|
);
|
|
799
|
-
const t = new TextEncoder().encode(e), r = await
|
|
800
|
+
const t = new TextEncoder().encode(e), r = await V.subtle.digest("SHA-256", t);
|
|
800
801
|
return qe(r).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
801
802
|
}
|
|
802
|
-
async function
|
|
803
|
+
async function ot(e) {
|
|
803
804
|
const t = e || 43;
|
|
804
805
|
if (t < 43 || t > 128)
|
|
805
806
|
throw `Expected a length between 43 and 128. Received ${e}.`;
|
|
@@ -809,7 +810,7 @@ async function at(e) {
|
|
|
809
810
|
code_challenge: n
|
|
810
811
|
};
|
|
811
812
|
}
|
|
812
|
-
async function
|
|
813
|
+
async function it(e, t) {
|
|
813
814
|
return t === await re(e);
|
|
814
815
|
}
|
|
815
816
|
const ze = /^Bearer (.+)$/i, Xe = (e) => {
|
|
@@ -829,32 +830,40 @@ const ze = /^Bearer (.+)$/i, Xe = (e) => {
|
|
|
829
830
|
const t = e == null ? void 0 : e[ne.ACCESS_TOKEN];
|
|
830
831
|
if (typeof t == "string")
|
|
831
832
|
return t;
|
|
832
|
-
},
|
|
833
|
+
}, ct = ({ headers: e, body: t, clientId: r }) => {
|
|
833
834
|
const n = Xe(e), a = Qe(e, r);
|
|
834
835
|
return Ze(t) || a || n || "";
|
|
835
|
-
},
|
|
836
|
+
}, st = async (e, t) => {
|
|
836
837
|
var a;
|
|
837
838
|
const r = await Me(e);
|
|
838
|
-
if (!r || !Array.isArray((a = r.payload) == null ? void 0 : a[
|
|
839
|
+
if (!r || !Array.isArray((a = r.payload) == null ? void 0 : a[R.SCOPES_KEY]))
|
|
839
840
|
return !1;
|
|
840
|
-
const n = r.payload[
|
|
841
|
+
const n = r.payload[R.SCOPES_KEY];
|
|
841
842
|
return Array.isArray(t) ? t.every((o) => n.includes(o)) : Object.keys(t).some(
|
|
842
843
|
(o) => t[o].every((i) => n.includes(i))
|
|
843
844
|
);
|
|
844
|
-
}
|
|
845
|
+
}, je = (e, t) => {
|
|
846
|
+
const r = e == null ? void 0 : e.cookie;
|
|
847
|
+
if (typeof r != "string")
|
|
848
|
+
return;
|
|
849
|
+
const n = new RegExp(`auth.${t}.session=(.+?)(?:;|$)`), a = r.match(n);
|
|
850
|
+
if (a)
|
|
851
|
+
return a[1];
|
|
852
|
+
}, dt = ({ headers: e, clientId: t }) => je(e, t) || "";
|
|
845
853
|
export {
|
|
846
|
-
|
|
847
|
-
|
|
854
|
+
nt as API_TYPE,
|
|
855
|
+
et as AUTH_TYPES,
|
|
848
856
|
ne as BODY,
|
|
849
|
-
|
|
850
|
-
|
|
857
|
+
tt as HEADERS,
|
|
858
|
+
R as JWT,
|
|
851
859
|
ae as JWT_PUBLIC_KEY,
|
|
852
|
-
|
|
853
|
-
|
|
860
|
+
rt as TOKEN_EXPIRATION,
|
|
861
|
+
at as decodeToken,
|
|
854
862
|
re as generateCodeChallenge,
|
|
855
|
-
|
|
856
|
-
ct as
|
|
857
|
-
|
|
863
|
+
dt as getSession,
|
|
864
|
+
ct as getToken,
|
|
865
|
+
st as isGranted,
|
|
866
|
+
ot as pkceChallengePair,
|
|
858
867
|
Me as verifyAndExtractToken,
|
|
859
|
-
|
|
868
|
+
it as verifyChallenge
|
|
860
869
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@versini/auth-common",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.4.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": "
|
|
39
|
+
"gitHead": "fc7db509578caa068384544279e347f089720ebe"
|
|
40
40
|
}
|