@versini/auth-common 4.2.1 → 4.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 +37 -2
- package/dist/index.js +187 -172
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -7,9 +7,11 @@ declare const AUTH_TYPES: {
|
|
|
7
7
|
CODE: string;
|
|
8
8
|
REFRESH_TOKEN: string;
|
|
9
9
|
PASSKEY: string;
|
|
10
|
+
AUTH0: string;
|
|
10
11
|
};
|
|
11
12
|
declare const HEADERS: {
|
|
12
13
|
CLIENT_ID: string;
|
|
14
|
+
AUTH_TYPE: string;
|
|
13
15
|
};
|
|
14
16
|
declare const BODY: {
|
|
15
17
|
ACCESS_TOKEN: string;
|
|
@@ -101,7 +103,7 @@ type ScopesGrants = {
|
|
|
101
103
|
[key: string]: string[];
|
|
102
104
|
} | string[];
|
|
103
105
|
/**
|
|
104
|
-
* Checks if the given token grants the required scopes.
|
|
106
|
+
* Checks if the given encoded access token grants the required scopes.
|
|
105
107
|
*
|
|
106
108
|
* This function verifies the provided token and extracts its payload.
|
|
107
109
|
* It then checks if the token contains the required scopes. The scopes can be provided
|
|
@@ -135,6 +137,39 @@ type ScopesGrants = {
|
|
|
135
137
|
* console.log(res); // true if the token has either "read" and "write" scopes or "read" scope
|
|
136
138
|
*/
|
|
137
139
|
declare const isGranted: (token: string, scopes: ScopesGrants) => Promise<boolean>;
|
|
140
|
+
/**
|
|
141
|
+
* Checks if the given non-encoded id token grants the required scopes.
|
|
142
|
+
*
|
|
143
|
+
* This function does not verify the token, it simply extracts its payload.
|
|
144
|
+
* It then checks if the token contains the required scopes. The scopes can be provided
|
|
145
|
+
* either as an array of strings or as a map of string arrays. When the scopes are provided
|
|
146
|
+
* as a map, the function checks if the token contains at least one of the scopes in each
|
|
147
|
+
* of the map's values (OR operation).
|
|
148
|
+
*
|
|
149
|
+
*
|
|
150
|
+
* @function isGrantedSync
|
|
151
|
+
* @param {string} token - The token to be checked for scopes.
|
|
152
|
+
* @param {ScopesGrants} scopes - The required scopes. This can be an array of strings
|
|
153
|
+
* representing the scopes or a map where the keys are strings
|
|
154
|
+
* and the values are arrays of strings representing the scopes.
|
|
155
|
+
* @returns {boolean} - A boolean indicating whether the token grants the required scopes.
|
|
156
|
+
*
|
|
157
|
+
* @example
|
|
158
|
+
* Example with an array of scopes (AND operation)
|
|
159
|
+
* const scopesArray = ["read", "write"];
|
|
160
|
+
* const res = isGranted(token, scopesArray);
|
|
161
|
+
* console.log(res); // true only if the token has both "read" and "write" scopes
|
|
162
|
+
*
|
|
163
|
+
* @example
|
|
164
|
+
* Example with a map of scopes (OR operation)
|
|
165
|
+
* const scopesMap = {
|
|
166
|
+
* "admin": ["read", "write"],
|
|
167
|
+
* "user": ["read"]
|
|
168
|
+
* };
|
|
169
|
+
* const res = isGranted(token, scopesMap);
|
|
170
|
+
* console.log(res); // true if the token has either "read" and "write" scopes or "read" scope
|
|
171
|
+
*/
|
|
172
|
+
declare const isGrantedSync: (token: string, scopes: ScopesGrants) => boolean;
|
|
138
173
|
|
|
139
174
|
/**
|
|
140
175
|
* Get a Session Id from a request.
|
|
@@ -149,4 +184,4 @@ type GetSessionProps = {
|
|
|
149
184
|
};
|
|
150
185
|
declare const getSession: ({ headers, clientId }: GetSessionProps) => string;
|
|
151
186
|
|
|
152
|
-
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 };
|
|
187
|
+
export { API_TYPE, AUTH_TYPES, BODY, type BodyLike, HEADERS, type HeadersLike, JWT, JWT_PUBLIC_KEY, type ScopesGrants, TOKEN_EXPIRATION, decodeToken, generateCodeChallenge, getSession, getToken, isGranted, isGrantedSync, pkceChallengePair, verifyAndExtractToken, verifyChallenge };
|
package/dist/index.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
1
|
+
var ne = Object.defineProperty;
|
|
2
|
+
var ae = (e, t, r) => t in e ? ne(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
|
|
3
|
+
var u = (e, t, r) => ae(e, typeof t != "symbol" ? t + "" : t, r);
|
|
4
4
|
/*!
|
|
5
|
-
@versini/auth-common v4.
|
|
5
|
+
@versini/auth-common v4.4.0
|
|
6
6
|
© 2025 gizmette.com
|
|
7
7
|
*/
|
|
8
8
|
try {
|
|
9
9
|
window.__VERSINI_AUTH_COMMON__ || (window.__VERSINI_AUTH_COMMON__ = {
|
|
10
|
-
version: "4.
|
|
11
|
-
buildTime: "
|
|
10
|
+
version: "4.4.0",
|
|
11
|
+
buildTime: "06/02/2025 05:45 PM EDT",
|
|
12
12
|
homepage: "https://github.com/aversini/auth-client",
|
|
13
13
|
license: "MIT"
|
|
14
14
|
});
|
|
@@ -20,12 +20,14 @@ const nt = {
|
|
|
20
20
|
ID_AND_ACCESS_TOKEN: "id_token token",
|
|
21
21
|
CODE: "code",
|
|
22
22
|
REFRESH_TOKEN: "refresh_token",
|
|
23
|
-
PASSKEY: "passkey"
|
|
23
|
+
PASSKEY: "passkey",
|
|
24
|
+
AUTH0: "auth0"
|
|
24
25
|
}, at = {
|
|
25
|
-
CLIENT_ID: "X-Auth-ClientId"
|
|
26
|
-
|
|
26
|
+
CLIENT_ID: "X-Auth-ClientId",
|
|
27
|
+
AUTH_TYPE: "X-Auth-Type"
|
|
28
|
+
}, ie = {
|
|
27
29
|
ACCESS_TOKEN: "access_token"
|
|
28
|
-
},
|
|
30
|
+
}, K = {
|
|
29
31
|
ALG: "RS256",
|
|
30
32
|
USER_ID_KEY: "sub",
|
|
31
33
|
USERNAME_KEY: "username",
|
|
@@ -38,7 +40,7 @@ const nt = {
|
|
|
38
40
|
SCOPES_KEY: "scopes",
|
|
39
41
|
CLIENT_ID_KEY: "aud",
|
|
40
42
|
ISSUER: "gizmette.com"
|
|
41
|
-
},
|
|
43
|
+
}, oe = `-----BEGIN PUBLIC KEY-----
|
|
42
44
|
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAsF6i3Jd9fY/3COqCw/m7
|
|
43
45
|
w5PKyTYLGAI2I6SIIdpe6i6DOCbEkmDz7LdVsBqwNtVi8gvWYIj+8ol6rU3qu1v5
|
|
44
46
|
i1Jd45GSK4kzkVdgCmQZbM5ak0KI99q5wsrAIzUd+LRJ2HRvWtr5IYdsIiXaQjle
|
|
@@ -55,15 +57,15 @@ awIDAQAB
|
|
|
55
57
|
LOGOUT: "logout",
|
|
56
58
|
LOGIN: "login",
|
|
57
59
|
REFRESH: "refresh"
|
|
58
|
-
},
|
|
59
|
-
function
|
|
60
|
+
}, O = new TextEncoder(), T = new TextDecoder();
|
|
61
|
+
function se(...e) {
|
|
60
62
|
const t = e.reduce((a, { length: i }) => a + i, 0), r = new Uint8Array(t);
|
|
61
63
|
let n = 0;
|
|
62
64
|
for (const a of e)
|
|
63
65
|
r.set(a, n), n += a.length;
|
|
64
66
|
return r;
|
|
65
67
|
}
|
|
66
|
-
function
|
|
68
|
+
function ce(e) {
|
|
67
69
|
if (Uint8Array.fromBase64)
|
|
68
70
|
return Uint8Array.fromBase64(e);
|
|
69
71
|
const t = atob(e), r = new Uint8Array(t.length);
|
|
@@ -71,15 +73,15 @@ function se(e) {
|
|
|
71
73
|
r[n] = t.charCodeAt(n);
|
|
72
74
|
return r;
|
|
73
75
|
}
|
|
74
|
-
function
|
|
76
|
+
function P(e) {
|
|
75
77
|
if (Uint8Array.fromBase64)
|
|
76
|
-
return Uint8Array.fromBase64(typeof e == "string" ? e :
|
|
78
|
+
return Uint8Array.fromBase64(typeof e == "string" ? e : T.decode(e), {
|
|
77
79
|
alphabet: "base64url"
|
|
78
80
|
});
|
|
79
81
|
let t = e;
|
|
80
|
-
t instanceof Uint8Array && (t =
|
|
82
|
+
t instanceof Uint8Array && (t = T.decode(t)), t = t.replace(/-/g, "+").replace(/_/g, "/").replace(/\s/g, "");
|
|
81
83
|
try {
|
|
82
|
-
return
|
|
84
|
+
return ce(t);
|
|
83
85
|
} catch {
|
|
84
86
|
throw new TypeError("The input to be decoded is not correctly encoded.");
|
|
85
87
|
}
|
|
@@ -88,78 +90,78 @@ class w extends Error {
|
|
|
88
90
|
constructor(r, n) {
|
|
89
91
|
var a;
|
|
90
92
|
super(r, n);
|
|
91
|
-
|
|
93
|
+
u(this, "code", "ERR_JOSE_GENERIC");
|
|
92
94
|
this.name = this.constructor.name, (a = Error.captureStackTrace) == null || a.call(Error, this, this.constructor);
|
|
93
95
|
}
|
|
94
96
|
}
|
|
95
|
-
|
|
97
|
+
u(w, "code", "ERR_JOSE_GENERIC");
|
|
96
98
|
class h extends w {
|
|
97
99
|
constructor(r, n, a = "unspecified", i = "unspecified") {
|
|
98
100
|
super(r, { cause: { claim: a, reason: i, payload: n } });
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
101
|
+
u(this, "code", "ERR_JWT_CLAIM_VALIDATION_FAILED");
|
|
102
|
+
u(this, "claim");
|
|
103
|
+
u(this, "reason");
|
|
104
|
+
u(this, "payload");
|
|
103
105
|
this.claim = a, this.reason = i, this.payload = n;
|
|
104
106
|
}
|
|
105
107
|
}
|
|
106
|
-
|
|
108
|
+
u(h, "code", "ERR_JWT_CLAIM_VALIDATION_FAILED");
|
|
107
109
|
class J extends w {
|
|
108
110
|
constructor(r, n, a = "unspecified", i = "unspecified") {
|
|
109
111
|
super(r, { cause: { claim: a, reason: i, payload: n } });
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
112
|
+
u(this, "code", "ERR_JWT_EXPIRED");
|
|
113
|
+
u(this, "claim");
|
|
114
|
+
u(this, "reason");
|
|
115
|
+
u(this, "payload");
|
|
114
116
|
this.claim = a, this.reason = i, this.payload = n;
|
|
115
117
|
}
|
|
116
118
|
}
|
|
117
|
-
|
|
119
|
+
u(J, "code", "ERR_JWT_EXPIRED");
|
|
118
120
|
class F extends w {
|
|
119
121
|
constructor() {
|
|
120
122
|
super(...arguments);
|
|
121
|
-
|
|
123
|
+
u(this, "code", "ERR_JOSE_ALG_NOT_ALLOWED");
|
|
122
124
|
}
|
|
123
125
|
}
|
|
124
|
-
|
|
126
|
+
u(F, "code", "ERR_JOSE_ALG_NOT_ALLOWED");
|
|
125
127
|
class E extends w {
|
|
126
128
|
constructor() {
|
|
127
129
|
super(...arguments);
|
|
128
|
-
|
|
130
|
+
u(this, "code", "ERR_JOSE_NOT_SUPPORTED");
|
|
129
131
|
}
|
|
130
132
|
}
|
|
131
|
-
|
|
132
|
-
class
|
|
133
|
+
u(E, "code", "ERR_JOSE_NOT_SUPPORTED");
|
|
134
|
+
class d extends w {
|
|
133
135
|
constructor() {
|
|
134
136
|
super(...arguments);
|
|
135
|
-
|
|
137
|
+
u(this, "code", "ERR_JWS_INVALID");
|
|
136
138
|
}
|
|
137
139
|
}
|
|
138
|
-
d
|
|
140
|
+
u(d, "code", "ERR_JWS_INVALID");
|
|
139
141
|
class y extends w {
|
|
140
142
|
constructor() {
|
|
141
143
|
super(...arguments);
|
|
142
|
-
|
|
144
|
+
u(this, "code", "ERR_JWT_INVALID");
|
|
143
145
|
}
|
|
144
146
|
}
|
|
145
|
-
|
|
147
|
+
u(y, "code", "ERR_JWT_INVALID");
|
|
146
148
|
class V extends w {
|
|
147
149
|
constructor(r = "signature verification failed", n) {
|
|
148
150
|
super(r, n);
|
|
149
|
-
|
|
151
|
+
u(this, "code", "ERR_JWS_SIGNATURE_VERIFICATION_FAILED");
|
|
150
152
|
}
|
|
151
153
|
}
|
|
152
|
-
|
|
154
|
+
u(V, "code", "ERR_JWS_SIGNATURE_VERIFICATION_FAILED");
|
|
153
155
|
function S(e, t = "algorithm.name") {
|
|
154
156
|
return new TypeError(`CryptoKey does not support this operation, its ${t} must be ${e}`);
|
|
155
157
|
}
|
|
156
|
-
function
|
|
158
|
+
function v(e, t) {
|
|
157
159
|
return e.name === t;
|
|
158
160
|
}
|
|
159
161
|
function D(e) {
|
|
160
162
|
return parseInt(e.name.slice(4), 10);
|
|
161
163
|
}
|
|
162
|
-
function
|
|
164
|
+
function ue(e) {
|
|
163
165
|
switch (e) {
|
|
164
166
|
case "ES256":
|
|
165
167
|
return "P-256";
|
|
@@ -175,12 +177,12 @@ function de(e, t) {
|
|
|
175
177
|
if (!e.usages.includes(t))
|
|
176
178
|
throw new TypeError(`CryptoKey does not support this operation, its usages must include ${t}.`);
|
|
177
179
|
}
|
|
178
|
-
function
|
|
180
|
+
function fe(e, t, r) {
|
|
179
181
|
switch (t) {
|
|
180
182
|
case "HS256":
|
|
181
183
|
case "HS384":
|
|
182
184
|
case "HS512": {
|
|
183
|
-
if (!
|
|
185
|
+
if (!v(e.algorithm, "HMAC"))
|
|
184
186
|
throw S("HMAC");
|
|
185
187
|
const n = parseInt(t.slice(2), 10);
|
|
186
188
|
if (D(e.algorithm.hash) !== n)
|
|
@@ -190,7 +192,7 @@ function ue(e, t, r) {
|
|
|
190
192
|
case "RS256":
|
|
191
193
|
case "RS384":
|
|
192
194
|
case "RS512": {
|
|
193
|
-
if (!
|
|
195
|
+
if (!v(e.algorithm, "RSASSA-PKCS1-v1_5"))
|
|
194
196
|
throw S("RSASSA-PKCS1-v1_5");
|
|
195
197
|
const n = parseInt(t.slice(2), 10);
|
|
196
198
|
if (D(e.algorithm.hash) !== n)
|
|
@@ -200,7 +202,7 @@ function ue(e, t, r) {
|
|
|
200
202
|
case "PS256":
|
|
201
203
|
case "PS384":
|
|
202
204
|
case "PS512": {
|
|
203
|
-
if (!
|
|
205
|
+
if (!v(e.algorithm, "RSA-PSS"))
|
|
204
206
|
throw S("RSA-PSS");
|
|
205
207
|
const n = parseInt(t.slice(2), 10);
|
|
206
208
|
if (D(e.algorithm.hash) !== n)
|
|
@@ -209,16 +211,16 @@ function ue(e, t, r) {
|
|
|
209
211
|
}
|
|
210
212
|
case "Ed25519":
|
|
211
213
|
case "EdDSA": {
|
|
212
|
-
if (!
|
|
214
|
+
if (!v(e.algorithm, "Ed25519"))
|
|
213
215
|
throw S("Ed25519");
|
|
214
216
|
break;
|
|
215
217
|
}
|
|
216
218
|
case "ES256":
|
|
217
219
|
case "ES384":
|
|
218
220
|
case "ES512": {
|
|
219
|
-
if (!
|
|
221
|
+
if (!v(e.algorithm, "ECDSA"))
|
|
220
222
|
throw S("ECDSA");
|
|
221
|
-
const n =
|
|
223
|
+
const n = ue(t);
|
|
222
224
|
if (e.algorithm.namedCurve !== n)
|
|
223
225
|
throw S(n, "algorithm.namedCurve");
|
|
224
226
|
break;
|
|
@@ -236,17 +238,17 @@ function G(e, t, ...r) {
|
|
|
236
238
|
} else r.length === 2 ? e += `one of type ${r[0]} or ${r[1]}.` : e += `of type ${r[0]}.`;
|
|
237
239
|
return t == null ? e += ` Received ${t}` : typeof t == "function" && t.name ? e += ` Received function ${t.name}` : typeof t == "object" && t != null && (n = t.constructor) != null && n.name && (e += ` Received an instance of ${t.constructor.name}`), e;
|
|
238
240
|
}
|
|
239
|
-
const
|
|
241
|
+
const le = (e, ...t) => G("Key must be ", e, ...t);
|
|
240
242
|
function q(e, t, ...r) {
|
|
241
243
|
return G(`Key for the ${e} algorithm must be `, t, ...r);
|
|
242
244
|
}
|
|
243
245
|
function z(e) {
|
|
244
246
|
return (e == null ? void 0 : e[Symbol.toStringTag]) === "CryptoKey";
|
|
245
247
|
}
|
|
246
|
-
function
|
|
248
|
+
function X(e) {
|
|
247
249
|
return (e == null ? void 0 : e[Symbol.toStringTag]) === "KeyObject";
|
|
248
250
|
}
|
|
249
|
-
const
|
|
251
|
+
const Q = (e) => z(e) || X(e), he = (...e) => {
|
|
250
252
|
const t = e.filter(Boolean);
|
|
251
253
|
if (t.length === 0 || t.length === 1)
|
|
252
254
|
return !0;
|
|
@@ -265,11 +267,11 @@ const X = (e) => z(e) || Q(e), le = (...e) => {
|
|
|
265
267
|
}
|
|
266
268
|
return !0;
|
|
267
269
|
};
|
|
268
|
-
function
|
|
270
|
+
function pe(e) {
|
|
269
271
|
return typeof e == "object" && e !== null;
|
|
270
272
|
}
|
|
271
|
-
const
|
|
272
|
-
if (!
|
|
273
|
+
const _ = (e) => {
|
|
274
|
+
if (!pe(e) || Object.prototype.toString.call(e) !== "[object Object]")
|
|
273
275
|
return !1;
|
|
274
276
|
if (Object.getPrototypeOf(e) === null)
|
|
275
277
|
return !0;
|
|
@@ -277,7 +279,7 @@ const P = (e) => {
|
|
|
277
279
|
for (; Object.getPrototypeOf(t) !== null; )
|
|
278
280
|
t = Object.getPrototypeOf(t);
|
|
279
281
|
return Object.getPrototypeOf(e) === t;
|
|
280
|
-
},
|
|
282
|
+
}, ye = (e, t) => {
|
|
281
283
|
if (e.startsWith("RS") || e.startsWith("PS")) {
|
|
282
284
|
const { modulusLength: r } = t.algorithm;
|
|
283
285
|
if (typeof r != "number" || r < 2048)
|
|
@@ -290,7 +292,7 @@ const P = (e) => {
|
|
|
290
292
|
return !1;
|
|
291
293
|
const a = e.subarray(n, n + t.length);
|
|
292
294
|
return a.length !== t.length ? !1 : a.every((i, o) => i === t[o]) || W(e, t, n + 1);
|
|
293
|
-
},
|
|
295
|
+
}, me = (e) => {
|
|
294
296
|
switch (!0) {
|
|
295
297
|
case W(e, [42, 134, 72, 206, 61, 3, 1, 7]):
|
|
296
298
|
return "P-256";
|
|
@@ -301,7 +303,7 @@ const P = (e) => {
|
|
|
301
303
|
default:
|
|
302
304
|
return;
|
|
303
305
|
}
|
|
304
|
-
},
|
|
306
|
+
}, Se = async (e, t, r, n, a) => {
|
|
305
307
|
let i, o;
|
|
306
308
|
const c = new Uint8Array(atob(r.replace(e, "")).split("").map((s) => s.charCodeAt(0)));
|
|
307
309
|
switch (n) {
|
|
@@ -337,7 +339,7 @@ const P = (e) => {
|
|
|
337
339
|
case "ECDH-ES+A128KW":
|
|
338
340
|
case "ECDH-ES+A192KW":
|
|
339
341
|
case "ECDH-ES+A256KW": {
|
|
340
|
-
const s =
|
|
342
|
+
const s = me(c);
|
|
341
343
|
i = s != null && s.startsWith("P-") ? { name: "ECDH", namedCurve: s } : { name: "X25519" }, o = [];
|
|
342
344
|
break;
|
|
343
345
|
}
|
|
@@ -349,8 +351,8 @@ const P = (e) => {
|
|
|
349
351
|
throw new E('Invalid or unsupported "alg" (Algorithm) value');
|
|
350
352
|
}
|
|
351
353
|
return crypto.subtle.importKey(t, c, i, !0, o);
|
|
352
|
-
},
|
|
353
|
-
function
|
|
354
|
+
}, Ee = (e, t, r) => Se(/(?:-----(?:BEGIN|END) PUBLIC KEY-----|\s)/g, "spki", e, t);
|
|
355
|
+
function we(e) {
|
|
354
356
|
let t, r;
|
|
355
357
|
switch (e.kty) {
|
|
356
358
|
case "RSA": {
|
|
@@ -423,18 +425,18 @@ function Ee(e) {
|
|
|
423
425
|
}
|
|
424
426
|
return { algorithm: t, keyUsages: r };
|
|
425
427
|
}
|
|
426
|
-
const
|
|
428
|
+
const Ae = async (e) => {
|
|
427
429
|
if (!e.alg)
|
|
428
430
|
throw new TypeError('"alg" argument is required when "jwk.alg" is not present');
|
|
429
|
-
const { algorithm: t, keyUsages: r } =
|
|
431
|
+
const { algorithm: t, keyUsages: r } = we(e), n = { ...e };
|
|
430
432
|
return delete n.alg, delete n.use, crypto.subtle.importKey("jwk", n, t, e.ext ?? !e.d, e.key_ops ?? r);
|
|
431
433
|
};
|
|
432
|
-
async function
|
|
434
|
+
async function be(e, t, r) {
|
|
433
435
|
if (e.indexOf("-----BEGIN PUBLIC KEY-----") !== 0)
|
|
434
436
|
throw new TypeError('"spki" must be SPKI formatted string');
|
|
435
|
-
return
|
|
437
|
+
return Ee(e, t);
|
|
436
438
|
}
|
|
437
|
-
const
|
|
439
|
+
const ge = (e, t, r, n, a) => {
|
|
438
440
|
if (a.crit !== void 0 && (n == null ? void 0 : n.crit) === void 0)
|
|
439
441
|
throw new e('"crit" (Critical) Header Parameter MUST be integrity protected');
|
|
440
442
|
if (!n || n.crit === void 0)
|
|
@@ -452,22 +454,22 @@ const be = (e, t, r, n, a) => {
|
|
|
452
454
|
throw new e(`Extension Header Parameter "${o}" MUST be integrity protected`);
|
|
453
455
|
}
|
|
454
456
|
return new Set(n.crit);
|
|
455
|
-
},
|
|
457
|
+
}, Ce = (e, t) => {
|
|
456
458
|
if (t !== void 0 && (!Array.isArray(t) || t.some((r) => typeof r != "string")))
|
|
457
459
|
throw new TypeError(`"${e}" option must be an array of strings`);
|
|
458
460
|
if (t)
|
|
459
461
|
return new Set(t);
|
|
460
462
|
};
|
|
461
463
|
function N(e) {
|
|
462
|
-
return
|
|
464
|
+
return _(e) && typeof e.kty == "string";
|
|
463
465
|
}
|
|
464
|
-
function
|
|
466
|
+
function Ke(e) {
|
|
465
467
|
return e.kty !== "oct" && typeof e.d == "string";
|
|
466
468
|
}
|
|
467
|
-
function
|
|
469
|
+
function Te(e) {
|
|
468
470
|
return e.kty !== "oct" && typeof e.d > "u";
|
|
469
471
|
}
|
|
470
|
-
function
|
|
472
|
+
function ve(e) {
|
|
471
473
|
return e.kty === "oct" && typeof e.k == "string";
|
|
472
474
|
}
|
|
473
475
|
let C;
|
|
@@ -476,9 +478,9 @@ const $ = async (e, t, r, n = !1) => {
|
|
|
476
478
|
let a = C.get(e);
|
|
477
479
|
if (a != null && a[r])
|
|
478
480
|
return a[r];
|
|
479
|
-
const i = await
|
|
481
|
+
const i = await Ae({ ...t, alg: r });
|
|
480
482
|
return n && Object.freeze(e), a ? a[r] = i : C.set(e, { [r]: i }), i;
|
|
481
|
-
},
|
|
483
|
+
}, Pe = (e, t) => {
|
|
482
484
|
var o;
|
|
483
485
|
C || (C = /* @__PURE__ */ new WeakMap());
|
|
484
486
|
let r = C.get(e);
|
|
@@ -564,15 +566,15 @@ const $ = async (e, t, r, n = !1) => {
|
|
|
564
566
|
if (!i)
|
|
565
567
|
throw new TypeError("given KeyObject instance cannot be used for this algorithm");
|
|
566
568
|
return r ? r[t] = i : C.set(e, { [t]: i }), i;
|
|
567
|
-
},
|
|
569
|
+
}, _e = async (e, t) => {
|
|
568
570
|
if (e instanceof Uint8Array || z(e))
|
|
569
571
|
return e;
|
|
570
|
-
if (
|
|
572
|
+
if (X(e)) {
|
|
571
573
|
if (e.type === "secret")
|
|
572
574
|
return e.export();
|
|
573
575
|
if ("toCryptoKey" in e && typeof e.toCryptoKey == "function")
|
|
574
576
|
try {
|
|
575
|
-
return
|
|
577
|
+
return Pe(e, t);
|
|
576
578
|
} catch (n) {
|
|
577
579
|
if (n instanceof TypeError)
|
|
578
580
|
throw n;
|
|
@@ -581,7 +583,7 @@ const $ = async (e, t, r, n = !1) => {
|
|
|
581
583
|
return $(e, r, t);
|
|
582
584
|
}
|
|
583
585
|
if (N(e))
|
|
584
|
-
return e.k ?
|
|
586
|
+
return e.k ? P(e.k) : $(e, e, t, !0);
|
|
585
587
|
throw new Error("unreachable");
|
|
586
588
|
}, g = (e) => e == null ? void 0 : e[Symbol.toStringTag], x = (e, t, r) => {
|
|
587
589
|
var n, a;
|
|
@@ -627,33 +629,33 @@ const $ = async (e, t, r, n = !1) => {
|
|
|
627
629
|
throw new TypeError(`Invalid key for this operation, its "key_ops" must include "${i}" when present`);
|
|
628
630
|
}
|
|
629
631
|
return !0;
|
|
630
|
-
},
|
|
632
|
+
}, Re = (e, t, r) => {
|
|
631
633
|
if (!(t instanceof Uint8Array)) {
|
|
632
634
|
if (N(t)) {
|
|
633
|
-
if (
|
|
635
|
+
if (ve(t) && x(e, t, r))
|
|
634
636
|
return;
|
|
635
637
|
throw new TypeError('JSON Web Key for symmetric algorithms must have JWK "kty" (Key Type) equal to "oct" and the JWK "k" (Key Value) present');
|
|
636
638
|
}
|
|
637
|
-
if (!
|
|
639
|
+
if (!Q(t))
|
|
638
640
|
throw new TypeError(q(e, t, "CryptoKey", "KeyObject", "JSON Web Key", "Uint8Array"));
|
|
639
641
|
if (t.type !== "secret")
|
|
640
642
|
throw new TypeError(`${g(t)} instances for symmetric algorithms must be of type "secret"`);
|
|
641
643
|
}
|
|
642
|
-
},
|
|
644
|
+
}, Ie = (e, t, r) => {
|
|
643
645
|
if (N(t))
|
|
644
646
|
switch (r) {
|
|
645
647
|
case "decrypt":
|
|
646
648
|
case "sign":
|
|
647
|
-
if (
|
|
649
|
+
if (Ke(t) && x(e, t, r))
|
|
648
650
|
return;
|
|
649
651
|
throw new TypeError("JSON Web Key for this operation be a private JWK");
|
|
650
652
|
case "encrypt":
|
|
651
653
|
case "verify":
|
|
652
|
-
if (
|
|
654
|
+
if (Te(t) && x(e, t, r))
|
|
653
655
|
return;
|
|
654
656
|
throw new TypeError("JSON Web Key for this operation be a public JWK");
|
|
655
657
|
}
|
|
656
|
-
if (!
|
|
658
|
+
if (!Q(t))
|
|
657
659
|
throw new TypeError(q(e, t, "CryptoKey", "KeyObject", "JSON Web Key"));
|
|
658
660
|
if (t.type === "secret")
|
|
659
661
|
throw new TypeError(`${g(t)} instances for asymmetric algorithms must not be of type "secret"`);
|
|
@@ -671,8 +673,8 @@ const $ = async (e, t, r, n = !1) => {
|
|
|
671
673
|
case "encrypt":
|
|
672
674
|
throw new TypeError(`${g(t)} instances for asymmetric algorithm encryption must be of type "public"`);
|
|
673
675
|
}
|
|
674
|
-
},
|
|
675
|
-
e.startsWith("HS") || e === "dir" || e.startsWith("PBES2") || /^A(?:128|192|256)(?:GCM)?(?:KW)?$/.test(e) || /^A(?:128|192|256)CBC-HS(?:256|384|512)$/.test(e) ?
|
|
676
|
+
}, Oe = (e, t, r) => {
|
|
677
|
+
e.startsWith("HS") || e === "dir" || e.startsWith("PBES2") || /^A(?:128|192|256)(?:GCM)?(?:KW)?$/.test(e) || /^A(?:128|192|256)CBC-HS(?:256|384|512)$/.test(e) ? Re(e, t, r) : Ie(e, t, r);
|
|
676
678
|
}, We = (e, t) => {
|
|
677
679
|
const r = `SHA-${e.slice(-3)}`;
|
|
678
680
|
switch (e) {
|
|
@@ -698,16 +700,16 @@ const $ = async (e, t, r, n = !1) => {
|
|
|
698
700
|
default:
|
|
699
701
|
throw new E(`alg ${e} is not supported either by JOSE or your javascript runtime`);
|
|
700
702
|
}
|
|
701
|
-
},
|
|
703
|
+
}, De = async (e, t, r) => {
|
|
702
704
|
if (t instanceof Uint8Array) {
|
|
703
705
|
if (!e.startsWith("HS"))
|
|
704
|
-
throw new TypeError(
|
|
706
|
+
throw new TypeError(le(t, "CryptoKey", "KeyObject", "JSON Web Key"));
|
|
705
707
|
return crypto.subtle.importKey("raw", t, { hash: `SHA-${e.slice(-3)}`, name: "HMAC" }, !1, [r]);
|
|
706
708
|
}
|
|
707
|
-
return
|
|
708
|
-
},
|
|
709
|
-
const a = await
|
|
710
|
-
|
|
709
|
+
return fe(t, e, r), t;
|
|
710
|
+
}, He = async (e, t, r, n) => {
|
|
711
|
+
const a = await De(e, t, "verify");
|
|
712
|
+
ye(e, a);
|
|
711
713
|
const i = We(e, a.algorithm);
|
|
712
714
|
try {
|
|
713
715
|
return await crypto.subtle.verify(i, a, r, n);
|
|
@@ -715,81 +717,81 @@ const $ = async (e, t, r, n = !1) => {
|
|
|
715
717
|
return !1;
|
|
716
718
|
}
|
|
717
719
|
};
|
|
718
|
-
async function
|
|
719
|
-
if (!
|
|
720
|
-
throw new
|
|
720
|
+
async function Je(e, t, r) {
|
|
721
|
+
if (!_(e))
|
|
722
|
+
throw new d("Flattened JWS must be an object");
|
|
721
723
|
if (e.protected === void 0 && e.header === void 0)
|
|
722
|
-
throw new
|
|
724
|
+
throw new d('Flattened JWS must have either of the "protected" or "header" members');
|
|
723
725
|
if (e.protected !== void 0 && typeof e.protected != "string")
|
|
724
|
-
throw new
|
|
726
|
+
throw new d("JWS Protected Header incorrect type");
|
|
725
727
|
if (e.payload === void 0)
|
|
726
|
-
throw new
|
|
728
|
+
throw new d("JWS Payload missing");
|
|
727
729
|
if (typeof e.signature != "string")
|
|
728
|
-
throw new
|
|
729
|
-
if (e.header !== void 0 && !
|
|
730
|
-
throw new
|
|
730
|
+
throw new d("JWS Signature missing or incorrect type");
|
|
731
|
+
if (e.header !== void 0 && !_(e.header))
|
|
732
|
+
throw new d("JWS Unprotected Header incorrect type");
|
|
731
733
|
let n = {};
|
|
732
734
|
if (e.protected)
|
|
733
735
|
try {
|
|
734
|
-
const
|
|
735
|
-
n = JSON.parse(
|
|
736
|
+
const re = P(e.protected);
|
|
737
|
+
n = JSON.parse(T.decode(re));
|
|
736
738
|
} catch {
|
|
737
|
-
throw new
|
|
739
|
+
throw new d("JWS Protected Header is invalid");
|
|
738
740
|
}
|
|
739
|
-
if (!
|
|
740
|
-
throw new
|
|
741
|
+
if (!he(n, e.header))
|
|
742
|
+
throw new d("JWS Protected and JWS Unprotected Header Parameter names must be disjoint");
|
|
741
743
|
const a = {
|
|
742
744
|
...n,
|
|
743
745
|
...e.header
|
|
744
|
-
}, i =
|
|
746
|
+
}, i = ge(d, /* @__PURE__ */ new Map([["b64", !0]]), r == null ? void 0 : r.crit, n, a);
|
|
745
747
|
let o = !0;
|
|
746
748
|
if (i.has("b64") && (o = n.b64, typeof o != "boolean"))
|
|
747
|
-
throw new
|
|
749
|
+
throw new d('The "b64" (base64url-encode payload) Header Parameter must be a boolean');
|
|
748
750
|
const { alg: c } = a;
|
|
749
751
|
if (typeof c != "string" || !c)
|
|
750
|
-
throw new
|
|
751
|
-
const s = r &&
|
|
752
|
+
throw new d('JWS "alg" (Algorithm) Header Parameter missing or invalid');
|
|
753
|
+
const s = r && Ce("algorithms", r.algorithms);
|
|
752
754
|
if (s && !s.has(c))
|
|
753
755
|
throw new F('"alg" (Algorithm) Header Parameter value not allowed');
|
|
754
756
|
if (o) {
|
|
755
757
|
if (typeof e.payload != "string")
|
|
756
|
-
throw new
|
|
758
|
+
throw new d("JWS Payload must be a string");
|
|
757
759
|
} else if (typeof e.payload != "string" && !(e.payload instanceof Uint8Array))
|
|
758
|
-
throw new
|
|
760
|
+
throw new d("JWS Payload must be a string or an Uint8Array instance");
|
|
759
761
|
let m = !1;
|
|
760
|
-
typeof t == "function" && (t = await t(n, e), m = !0),
|
|
761
|
-
const A =
|
|
762
|
+
typeof t == "function" && (t = await t(n, e), m = !0), Oe(c, t, "verify");
|
|
763
|
+
const A = se(O.encode(e.protected ?? ""), O.encode("."), typeof e.payload == "string" ? O.encode(e.payload) : e.payload);
|
|
762
764
|
let p;
|
|
763
765
|
try {
|
|
764
|
-
p =
|
|
766
|
+
p = P(e.signature);
|
|
765
767
|
} catch {
|
|
766
|
-
throw new
|
|
768
|
+
throw new d("Failed to base64url decode the signature");
|
|
767
769
|
}
|
|
768
|
-
const
|
|
769
|
-
if (!await
|
|
770
|
+
const R = await _e(t, c);
|
|
771
|
+
if (!await He(c, R, p, A))
|
|
770
772
|
throw new V();
|
|
771
773
|
let l;
|
|
772
774
|
if (o)
|
|
773
775
|
try {
|
|
774
|
-
l =
|
|
776
|
+
l = P(e.payload);
|
|
775
777
|
} catch {
|
|
776
|
-
throw new
|
|
778
|
+
throw new d("Failed to base64url decode the payload");
|
|
777
779
|
}
|
|
778
|
-
else typeof e.payload == "string" ? l =
|
|
780
|
+
else typeof e.payload == "string" ? l = O.encode(e.payload) : l = e.payload;
|
|
779
781
|
const b = { payload: l };
|
|
780
|
-
return e.protected !== void 0 && (b.protectedHeader = n), e.header !== void 0 && (b.unprotectedHeader = e.header), m ? { ...b, key:
|
|
782
|
+
return e.protected !== void 0 && (b.protectedHeader = n), e.header !== void 0 && (b.unprotectedHeader = e.header), m ? { ...b, key: R } : b;
|
|
781
783
|
}
|
|
782
|
-
async function
|
|
783
|
-
if (e instanceof Uint8Array && (e =
|
|
784
|
-
throw new
|
|
784
|
+
async function xe(e, t, r) {
|
|
785
|
+
if (e instanceof Uint8Array && (e = T.decode(e)), typeof e != "string")
|
|
786
|
+
throw new d("Compact JWS must be a string or Uint8Array");
|
|
785
787
|
const { 0: n, 1: a, 2: i, length: o } = e.split(".");
|
|
786
788
|
if (o !== 3)
|
|
787
|
-
throw new
|
|
788
|
-
const c = await
|
|
789
|
+
throw new d("Invalid Compact JWS");
|
|
790
|
+
const c = await Je({ payload: a, protected: n, signature: i }, t, r), s = { payload: c.payload, protectedHeader: c.protectedHeader };
|
|
789
791
|
return typeof t == "function" ? { ...s, key: c.key } : s;
|
|
790
792
|
}
|
|
791
|
-
const
|
|
792
|
-
const t =
|
|
793
|
+
const Ne = (e) => Math.floor(e.getTime() / 1e3), Z = 60, j = Z * 60, U = j * 24, Ue = U * 7, $e = U * 365.25, Le = /^(\+|\-)? ?(\d+|\d+\.\d+) ?(seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)(?: (ago|from now))?$/i, L = (e) => {
|
|
794
|
+
const t = Le.exec(e);
|
|
793
795
|
if (!t || t[4] && t[1])
|
|
794
796
|
throw new TypeError("Invalid time period format");
|
|
795
797
|
const r = parseFloat(t[2]), n = t[3].toLowerCase();
|
|
@@ -824,21 +826,21 @@ const xe = (e) => Math.floor(e.getTime() / 1e3), Z = 60, j = Z * 60, U = j * 24,
|
|
|
824
826
|
case "week":
|
|
825
827
|
case "weeks":
|
|
826
828
|
case "w":
|
|
827
|
-
a = Math.round(r *
|
|
829
|
+
a = Math.round(r * Ue);
|
|
828
830
|
break;
|
|
829
831
|
default:
|
|
830
|
-
a = Math.round(r *
|
|
832
|
+
a = Math.round(r * $e);
|
|
831
833
|
break;
|
|
832
834
|
}
|
|
833
835
|
return t[1] === "-" || t[4] === "ago" ? -a : a;
|
|
834
|
-
}, B = (e) => e.toLowerCase().replace(/^application\//, ""),
|
|
835
|
-
function
|
|
836
|
+
}, B = (e) => e.toLowerCase().replace(/^application\//, ""), Be = (e, t) => typeof e == "string" ? t.includes(e) : Array.isArray(e) ? t.some(Set.prototype.has.bind(new Set(e))) : !1;
|
|
837
|
+
function Me(e, t, r = {}) {
|
|
836
838
|
let n;
|
|
837
839
|
try {
|
|
838
|
-
n = JSON.parse(
|
|
840
|
+
n = JSON.parse(T.decode(t));
|
|
839
841
|
} catch {
|
|
840
842
|
}
|
|
841
|
-
if (!
|
|
843
|
+
if (!_(n))
|
|
842
844
|
throw new y("JWT Claims Set must be a top-level JSON object");
|
|
843
845
|
const { typ: a } = r;
|
|
844
846
|
if (a && (typeof e.typ != "string" || B(e.typ) !== B(a)))
|
|
@@ -852,7 +854,7 @@ function Be(e, t, r = {}) {
|
|
|
852
854
|
throw new h('unexpected "iss" claim value', n, "iss", "check_failed");
|
|
853
855
|
if (c && n.sub !== c)
|
|
854
856
|
throw new h('unexpected "sub" claim value', n, "sub", "check_failed");
|
|
855
|
-
if (s && !
|
|
857
|
+
if (s && !Be(n.aud, typeof s == "string" ? [s] : s))
|
|
856
858
|
throw new h('unexpected "aud" claim value', n, "aud", "check_failed");
|
|
857
859
|
let p;
|
|
858
860
|
switch (typeof r.clockTolerance) {
|
|
@@ -868,23 +870,23 @@ function Be(e, t, r = {}) {
|
|
|
868
870
|
default:
|
|
869
871
|
throw new TypeError("Invalid clockTolerance option type");
|
|
870
872
|
}
|
|
871
|
-
const { currentDate:
|
|
873
|
+
const { currentDate: R } = r, I = Ne(R || /* @__PURE__ */ new Date());
|
|
872
874
|
if ((n.iat !== void 0 || m) && typeof n.iat != "number")
|
|
873
875
|
throw new h('"iat" claim must be a number', n, "iat", "invalid");
|
|
874
876
|
if (n.nbf !== void 0) {
|
|
875
877
|
if (typeof n.nbf != "number")
|
|
876
878
|
throw new h('"nbf" claim must be a number', n, "nbf", "invalid");
|
|
877
|
-
if (n.nbf >
|
|
879
|
+
if (n.nbf > I + p)
|
|
878
880
|
throw new h('"nbf" claim timestamp check failed', n, "nbf", "check_failed");
|
|
879
881
|
}
|
|
880
882
|
if (n.exp !== void 0) {
|
|
881
883
|
if (typeof n.exp != "number")
|
|
882
884
|
throw new h('"exp" claim must be a number', n, "exp", "invalid");
|
|
883
|
-
if (n.exp <=
|
|
885
|
+
if (n.exp <= I - p)
|
|
884
886
|
throw new J('"exp" claim timestamp check failed', n, "exp", "check_failed");
|
|
885
887
|
}
|
|
886
888
|
if (m) {
|
|
887
|
-
const l =
|
|
889
|
+
const l = I - n.iat, b = typeof m == "number" ? m : L(m);
|
|
888
890
|
if (l - p > b)
|
|
889
891
|
throw new J('"iat" claim timestamp check failed (too far in the past)', n, "iat", "check_failed");
|
|
890
892
|
if (l < 0 - p)
|
|
@@ -892,15 +894,15 @@ function Be(e, t, r = {}) {
|
|
|
892
894
|
}
|
|
893
895
|
return n;
|
|
894
896
|
}
|
|
895
|
-
async function
|
|
897
|
+
async function ke(e, t, r) {
|
|
896
898
|
var o;
|
|
897
|
-
const n = await
|
|
899
|
+
const n = await xe(e, t, r);
|
|
898
900
|
if ((o = n.protectedHeader.crit) != null && o.includes("b64") && n.protectedHeader.b64 === !1)
|
|
899
901
|
throw new y("JWTs MUST NOT use unencoded payload");
|
|
900
|
-
const i = { payload:
|
|
902
|
+
const i = { payload: Me(n.protectedHeader, n.payload, r), protectedHeader: n.protectedHeader };
|
|
901
903
|
return typeof t == "function" ? { ...i, key: n.key } : i;
|
|
902
904
|
}
|
|
903
|
-
function
|
|
905
|
+
function ee(e) {
|
|
904
906
|
if (typeof e != "string")
|
|
905
907
|
throw new y("JWTs must use Compact JWS serialization, JWT must be a string");
|
|
906
908
|
const { 1: t, length: r } = e.split(".");
|
|
@@ -912,32 +914,32 @@ function ke(e) {
|
|
|
912
914
|
throw new y("JWTs must contain a payload");
|
|
913
915
|
let n;
|
|
914
916
|
try {
|
|
915
|
-
n =
|
|
917
|
+
n = P(t);
|
|
916
918
|
} catch {
|
|
917
919
|
throw new y("Failed to base64url decode the payload");
|
|
918
920
|
}
|
|
919
921
|
let a;
|
|
920
922
|
try {
|
|
921
|
-
a = JSON.parse(
|
|
923
|
+
a = JSON.parse(T.decode(n));
|
|
922
924
|
} catch {
|
|
923
925
|
throw new y("Failed to parse the decoded payload as JSON");
|
|
924
926
|
}
|
|
925
|
-
if (!
|
|
927
|
+
if (!_(a))
|
|
926
928
|
throw new y("Invalid JWT Claims Set");
|
|
927
929
|
return a;
|
|
928
930
|
}
|
|
929
931
|
const Ye = async (e) => {
|
|
930
932
|
try {
|
|
931
|
-
const t =
|
|
932
|
-
return await
|
|
933
|
-
issuer:
|
|
933
|
+
const t = K.ALG, n = await be(oe, t);
|
|
934
|
+
return await ke(e, n, {
|
|
935
|
+
issuer: K.ISSUER
|
|
934
936
|
});
|
|
935
937
|
} catch {
|
|
936
938
|
return;
|
|
937
939
|
}
|
|
938
940
|
}, st = (e) => {
|
|
939
941
|
try {
|
|
940
|
-
return
|
|
942
|
+
return ee(e);
|
|
941
943
|
} catch {
|
|
942
944
|
return;
|
|
943
945
|
}
|
|
@@ -968,34 +970,34 @@ function k(e, t, r) {
|
|
|
968
970
|
throw new Error("Random bytes length must be >= 16");
|
|
969
971
|
return n[6] = n[6] & 15 | 64, n[8] = n[8] & 63 | 128, Fe(n);
|
|
970
972
|
}
|
|
971
|
-
const Y = globalThis.crypto, ze = (e) => `${k()}${k()}`.slice(0, e),
|
|
973
|
+
const Y = globalThis.crypto, ze = (e) => `${k()}${k()}`.slice(0, e), Xe = (e) => btoa(
|
|
972
974
|
[...new Uint8Array(e)].map((t) => String.fromCharCode(t)).join("")
|
|
973
975
|
);
|
|
974
|
-
async function
|
|
976
|
+
async function te(e) {
|
|
975
977
|
if (!Y.subtle)
|
|
976
978
|
throw new Error(
|
|
977
979
|
"crypto.subtle is available only in secure contexts (HTTPS)."
|
|
978
980
|
);
|
|
979
981
|
const t = new TextEncoder().encode(e), r = await Y.subtle.digest("SHA-256", t);
|
|
980
|
-
return
|
|
982
|
+
return Xe(r).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
981
983
|
}
|
|
982
984
|
async function ct(e) {
|
|
983
985
|
const t = e || 43;
|
|
984
986
|
if (t < 43 || t > 128)
|
|
985
987
|
throw `Expected a length between 43 and 128. Received ${e}.`;
|
|
986
|
-
const r = ze(t), n = await
|
|
988
|
+
const r = ze(t), n = await te(r);
|
|
987
989
|
return {
|
|
988
990
|
code_verifier: r,
|
|
989
991
|
code_challenge: n
|
|
990
992
|
};
|
|
991
993
|
}
|
|
992
|
-
async function
|
|
993
|
-
return t === await
|
|
994
|
+
async function ut(e, t) {
|
|
995
|
+
return t === await te(e);
|
|
994
996
|
}
|
|
995
|
-
const
|
|
997
|
+
const Qe = /^Bearer (.+)$/i, Ze = (e) => {
|
|
996
998
|
if (typeof (e == null ? void 0 : e.authorization) != "string")
|
|
997
999
|
return;
|
|
998
|
-
const t = e.authorization.match(
|
|
1000
|
+
const t = e.authorization.match(Qe);
|
|
999
1001
|
if (t)
|
|
1000
1002
|
return t[1];
|
|
1001
1003
|
}, je = (e, t) => {
|
|
@@ -1006,21 +1008,33 @@ const Xe = /^Bearer (.+)$/i, Ze = (e) => {
|
|
|
1006
1008
|
if (a)
|
|
1007
1009
|
return a[1];
|
|
1008
1010
|
}, et = (e) => {
|
|
1009
|
-
const t = e == null ? void 0 : e[
|
|
1011
|
+
const t = e == null ? void 0 : e[ie.ACCESS_TOKEN];
|
|
1010
1012
|
if (typeof t == "string")
|
|
1011
1013
|
return t;
|
|
1012
|
-
},
|
|
1014
|
+
}, dt = ({ headers: e, body: t, clientId: r }) => {
|
|
1013
1015
|
const n = Ze(e), a = je(e, r);
|
|
1014
1016
|
return et(t) || a || n || "";
|
|
1015
1017
|
}, ft = async (e, t) => {
|
|
1016
1018
|
var a;
|
|
1017
1019
|
const r = await Ye(e);
|
|
1018
|
-
if (!r || !Array.isArray((a = r.payload) == null ? void 0 : a[
|
|
1020
|
+
if (!r || !Array.isArray((a = r.payload) == null ? void 0 : a[K.SCOPES_KEY]))
|
|
1019
1021
|
return !1;
|
|
1020
|
-
const n = r.payload[
|
|
1022
|
+
const n = r.payload[K.SCOPES_KEY];
|
|
1021
1023
|
return Array.isArray(t) ? t.every((i) => n.includes(i)) : Object.keys(t).some(
|
|
1022
1024
|
(i) => t[i].every((o) => n.includes(o))
|
|
1023
1025
|
);
|
|
1026
|
+
}, lt = (e, t) => {
|
|
1027
|
+
try {
|
|
1028
|
+
const r = ee(e);
|
|
1029
|
+
if (!r || !Array.isArray(r[K.SCOPES_KEY]))
|
|
1030
|
+
return !1;
|
|
1031
|
+
const n = r[K.SCOPES_KEY];
|
|
1032
|
+
return Array.isArray(t) ? t.every((a) => n.includes(a)) : Object.keys(t).some(
|
|
1033
|
+
(a) => t[a].every((i) => n.includes(i))
|
|
1034
|
+
);
|
|
1035
|
+
} catch {
|
|
1036
|
+
return !1;
|
|
1037
|
+
}
|
|
1024
1038
|
}, tt = (e, t) => {
|
|
1025
1039
|
const r = e == null ? void 0 : e.cookie;
|
|
1026
1040
|
if (typeof r != "string")
|
|
@@ -1028,21 +1042,22 @@ const Xe = /^Bearer (.+)$/i, Ze = (e) => {
|
|
|
1028
1042
|
const n = new RegExp(`auth.${t}.session=(.+?)(?:;|$)`), a = r.match(n);
|
|
1029
1043
|
if (a)
|
|
1030
1044
|
return a[1];
|
|
1031
|
-
},
|
|
1045
|
+
}, ht = ({ headers: e, clientId: t }) => tt(e, t) || "";
|
|
1032
1046
|
export {
|
|
1033
1047
|
ot as API_TYPE,
|
|
1034
1048
|
nt as AUTH_TYPES,
|
|
1035
|
-
|
|
1049
|
+
ie as BODY,
|
|
1036
1050
|
at as HEADERS,
|
|
1037
|
-
|
|
1038
|
-
|
|
1051
|
+
K as JWT,
|
|
1052
|
+
oe as JWT_PUBLIC_KEY,
|
|
1039
1053
|
it as TOKEN_EXPIRATION,
|
|
1040
1054
|
st as decodeToken,
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1055
|
+
te as generateCodeChallenge,
|
|
1056
|
+
ht as getSession,
|
|
1057
|
+
dt as getToken,
|
|
1044
1058
|
ft as isGranted,
|
|
1059
|
+
lt as isGrantedSync,
|
|
1045
1060
|
ct as pkceChallengePair,
|
|
1046
1061
|
Ye as verifyAndExtractToken,
|
|
1047
|
-
|
|
1062
|
+
ut as verifyChallenge
|
|
1048
1063
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@versini/auth-common",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.4.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Arno Versini",
|
|
6
6
|
"publishConfig": {
|
|
@@ -36,5 +36,5 @@
|
|
|
36
36
|
"jose": "6.0.10",
|
|
37
37
|
"uuid": "11.1.0"
|
|
38
38
|
},
|
|
39
|
-
"gitHead": "
|
|
39
|
+
"gitHead": "3109c57783f179b3d0f2fee8cecf16cc8ba333e1"
|
|
40
40
|
}
|