@versini/auth-common 3.3.1 → 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 +14 -1
- package/dist/index.js +54 -46
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -134,4 +134,17 @@ type ScopesGrants = {
|
|
|
134
134
|
*/
|
|
135
135
|
declare const isGranted: (token: string, scopes: ScopesGrants) => Promise<boolean>;
|
|
136
136
|
|
|
137
|
-
|
|
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: "08/
|
|
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",
|
|
@@ -42,11 +42,11 @@ aMwPFOIcJH+rKfFgNcHLcaS5syp7zU1ANwZ+trgR+DifBr8TLVkBynmNeTyhDm2+
|
|
|
42
42
|
l0haqjMk0UoNPPE8iYBWUHQJJE1Dqstj65d6Eh5g64Pao25y4cmYJbKjiblIGEkE
|
|
43
43
|
sjqybA9mARAqh9k/eiIopecWSiffNQTwVQVd2I9ZH3BalhEXHlqFgrjz51kFqg81
|
|
44
44
|
awIDAQAB
|
|
45
|
-
-----END PUBLIC KEY-----`,
|
|
45
|
+
-----END PUBLIC KEY-----`, rt = {
|
|
46
46
|
ACCESS: "5m",
|
|
47
47
|
ID: "90d",
|
|
48
48
|
REFRESH: "90d"
|
|
49
|
-
},
|
|
49
|
+
}, nt = {
|
|
50
50
|
AUTHENTICATE: "authenticate",
|
|
51
51
|
CODE: "code",
|
|
52
52
|
LOGOUT: "logout"
|
|
@@ -232,7 +232,7 @@ const L = (e, ...t) => q("Key must be ", e, ...t);
|
|
|
232
232
|
function z(e, t, ...r) {
|
|
233
233
|
return q(`Key for the ${e} algorithm must be `, t, ...r);
|
|
234
234
|
}
|
|
235
|
-
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) => {
|
|
236
236
|
const t = e.filter(Boolean);
|
|
237
237
|
if (t.length === 0 || t.length === 1)
|
|
238
238
|
return !0;
|
|
@@ -454,13 +454,13 @@ async function be(e, t, r) {
|
|
|
454
454
|
const I = (e) => e == null ? void 0 : e[Symbol.toStringTag], Ce = (e, t) => {
|
|
455
455
|
if (!(t instanceof Uint8Array)) {
|
|
456
456
|
if (!X(t))
|
|
457
|
-
throw new TypeError(z(e, t, ...
|
|
457
|
+
throw new TypeError(z(e, t, ...P, "Uint8Array"));
|
|
458
458
|
if (t.type !== "secret")
|
|
459
459
|
throw new TypeError(`${I(t)} instances for symmetric algorithms must be of type "secret"`);
|
|
460
460
|
}
|
|
461
461
|
}, Te = (e, t, r) => {
|
|
462
462
|
if (!X(t))
|
|
463
|
-
throw new TypeError(z(e, t, ...
|
|
463
|
+
throw new TypeError(z(e, t, ...P));
|
|
464
464
|
if (t.type === "secret")
|
|
465
465
|
throw new TypeError(`${I(t)} instances for asymmetric algorithms must not be of type "secret"`);
|
|
466
466
|
if (t.algorithm && r === "verify" && t.type === "private")
|
|
@@ -495,7 +495,7 @@ const Ie = (e, t) => {
|
|
|
495
495
|
if (t)
|
|
496
496
|
return new Set(t);
|
|
497
497
|
};
|
|
498
|
-
function
|
|
498
|
+
function Re(e, t) {
|
|
499
499
|
const r = `SHA-${e.slice(-3)}`;
|
|
500
500
|
switch (e) {
|
|
501
501
|
case "HS256":
|
|
@@ -520,20 +520,20 @@ function Pe(e, t) {
|
|
|
520
520
|
throw new w(`alg ${e} is not supported either by JOSE or your javascript runtime`);
|
|
521
521
|
}
|
|
522
522
|
}
|
|
523
|
-
async function
|
|
523
|
+
async function Pe(e, t, r) {
|
|
524
524
|
if (t = await we.normalizePublicKey(t, e), G(t))
|
|
525
525
|
return le(t, e, r), t;
|
|
526
526
|
if (t instanceof Uint8Array) {
|
|
527
527
|
if (!e.startsWith("HS"))
|
|
528
|
-
throw new TypeError(L(t, ...
|
|
528
|
+
throw new TypeError(L(t, ...P));
|
|
529
529
|
return O.subtle.importKey("raw", t, { hash: `SHA-${e.slice(-3)}`, name: "HMAC" }, !1, [r]);
|
|
530
530
|
}
|
|
531
|
-
throw new TypeError(L(t, ...
|
|
531
|
+
throw new TypeError(L(t, ...P, "Uint8Array"));
|
|
532
532
|
}
|
|
533
533
|
const Ke = async (e, t, r, n) => {
|
|
534
|
-
const a = await
|
|
534
|
+
const a = await Pe(e, t, "verify");
|
|
535
535
|
pe(e, a);
|
|
536
|
-
const o =
|
|
536
|
+
const o = Re(e, a.algorithm);
|
|
537
537
|
try {
|
|
538
538
|
return await O.subtle.verify(o, a, r, n);
|
|
539
539
|
} catch {
|
|
@@ -752,14 +752,14 @@ function ke(e) {
|
|
|
752
752
|
}
|
|
753
753
|
const Me = async (e) => {
|
|
754
754
|
try {
|
|
755
|
-
const t =
|
|
755
|
+
const t = R.ALG, n = await be(ae, t);
|
|
756
756
|
return await $e(e, n, {
|
|
757
|
-
issuer:
|
|
757
|
+
issuer: R.ISSUER
|
|
758
758
|
});
|
|
759
759
|
} catch {
|
|
760
760
|
return;
|
|
761
761
|
}
|
|
762
|
-
},
|
|
762
|
+
}, at = (e) => {
|
|
763
763
|
try {
|
|
764
764
|
return ke(e);
|
|
765
765
|
} catch {
|
|
@@ -772,24 +772,24 @@ for (var H = 0; H < 256; ++H)
|
|
|
772
772
|
function Be(e, t = 0) {
|
|
773
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();
|
|
774
774
|
}
|
|
775
|
-
var v,
|
|
776
|
-
function
|
|
775
|
+
var v, Fe = new Uint8Array(16);
|
|
776
|
+
function Ye() {
|
|
777
777
|
if (!v && (v = typeof crypto < "u" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto), !v))
|
|
778
778
|
throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
|
|
779
|
-
return v(
|
|
779
|
+
return v(Fe);
|
|
780
780
|
}
|
|
781
781
|
var Ve = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto);
|
|
782
|
-
const
|
|
782
|
+
const F = {
|
|
783
783
|
randomUUID: Ve
|
|
784
784
|
};
|
|
785
|
-
function
|
|
786
|
-
if (
|
|
787
|
-
return
|
|
785
|
+
function Y(e, t, r) {
|
|
786
|
+
if (F.randomUUID && !t && !e)
|
|
787
|
+
return F.randomUUID();
|
|
788
788
|
e = e || {};
|
|
789
|
-
var n = e.random || (e.rng ||
|
|
789
|
+
var n = e.random || (e.rng || Ye)();
|
|
790
790
|
return n[6] = n[6] & 15 | 64, n[8] = n[8] & 63 | 128, Be(n);
|
|
791
791
|
}
|
|
792
|
-
const V = globalThis.crypto, Ge = (e) => `${
|
|
792
|
+
const V = globalThis.crypto, Ge = (e) => `${Y()}${Y()}`.slice(0, e), qe = (e) => btoa(
|
|
793
793
|
[...new Uint8Array(e)].map((t) => String.fromCharCode(t)).join("")
|
|
794
794
|
);
|
|
795
795
|
async function re(e) {
|
|
@@ -800,7 +800,7 @@ async function re(e) {
|
|
|
800
800
|
const t = new TextEncoder().encode(e), r = await V.subtle.digest("SHA-256", t);
|
|
801
801
|
return qe(r).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
802
802
|
}
|
|
803
|
-
async function
|
|
803
|
+
async function ot(e) {
|
|
804
804
|
const t = e || 43;
|
|
805
805
|
if (t < 43 || t > 128)
|
|
806
806
|
throw `Expected a length between 43 and 128. Received ${e}.`;
|
|
@@ -810,7 +810,7 @@ async function at(e) {
|
|
|
810
810
|
code_challenge: n
|
|
811
811
|
};
|
|
812
812
|
}
|
|
813
|
-
async function
|
|
813
|
+
async function it(e, t) {
|
|
814
814
|
return t === await re(e);
|
|
815
815
|
}
|
|
816
816
|
const ze = /^Bearer (.+)$/i, Xe = (e) => {
|
|
@@ -830,32 +830,40 @@ const ze = /^Bearer (.+)$/i, Xe = (e) => {
|
|
|
830
830
|
const t = e == null ? void 0 : e[ne.ACCESS_TOKEN];
|
|
831
831
|
if (typeof t == "string")
|
|
832
832
|
return t;
|
|
833
|
-
},
|
|
833
|
+
}, ct = ({ headers: e, body: t, clientId: r }) => {
|
|
834
834
|
const n = Xe(e), a = Qe(e, r);
|
|
835
835
|
return Ze(t) || a || n || "";
|
|
836
|
-
},
|
|
836
|
+
}, st = async (e, t) => {
|
|
837
837
|
var a;
|
|
838
838
|
const r = await Me(e);
|
|
839
|
-
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]))
|
|
840
840
|
return !1;
|
|
841
|
-
const n = r.payload[
|
|
841
|
+
const n = r.payload[R.SCOPES_KEY];
|
|
842
842
|
return Array.isArray(t) ? t.every((o) => n.includes(o)) : Object.keys(t).some(
|
|
843
843
|
(o) => t[o].every((i) => n.includes(i))
|
|
844
844
|
);
|
|
845
|
-
}
|
|
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) || "";
|
|
846
853
|
export {
|
|
847
|
-
|
|
848
|
-
|
|
854
|
+
nt as API_TYPE,
|
|
855
|
+
et as AUTH_TYPES,
|
|
849
856
|
ne as BODY,
|
|
850
|
-
|
|
851
|
-
|
|
857
|
+
tt as HEADERS,
|
|
858
|
+
R as JWT,
|
|
852
859
|
ae as JWT_PUBLIC_KEY,
|
|
853
|
-
|
|
854
|
-
|
|
860
|
+
rt as TOKEN_EXPIRATION,
|
|
861
|
+
at as decodeToken,
|
|
855
862
|
re as generateCodeChallenge,
|
|
856
|
-
|
|
857
|
-
ct as
|
|
858
|
-
|
|
863
|
+
dt as getSession,
|
|
864
|
+
ct as getToken,
|
|
865
|
+
st as isGranted,
|
|
866
|
+
ot as pkceChallengePair,
|
|
859
867
|
Me as verifyAndExtractToken,
|
|
860
|
-
|
|
868
|
+
it as verifyChallenge
|
|
861
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
|
}
|