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