@versini/auth-common 4.1.1 → 4.1.3
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.js +379 -317
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
@versini/auth-common v4.1.
|
|
2
|
+
@versini/auth-common v4.1.3
|
|
3
3
|
© 2024 gizmette.com
|
|
4
4
|
*/
|
|
5
5
|
try {
|
|
6
6
|
window.__VERSINI_AUTH_COMMON__ || (window.__VERSINI_AUTH_COMMON__ = {
|
|
7
|
-
version: "4.1.
|
|
8
|
-
buildTime: "09/
|
|
7
|
+
version: "4.1.3",
|
|
8
|
+
buildTime: "09/30/2024 01:36 PM 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 ct = {
|
|
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
|
+
}, st = {
|
|
22
22
|
CLIENT_ID: "X-Auth-ClientId"
|
|
23
|
-
},
|
|
23
|
+
}, se = {
|
|
24
24
|
ACCESS_TOKEN: "access_token"
|
|
25
|
-
},
|
|
25
|
+
}, W = {
|
|
26
26
|
ALG: "RS256",
|
|
27
27
|
USER_ID_KEY: "sub",
|
|
28
28
|
USERNAME_KEY: "username",
|
|
@@ -35,7 +35,7 @@ const et = {
|
|
|
35
35
|
SCOPES_KEY: "scopes",
|
|
36
36
|
CLIENT_ID_KEY: "aud",
|
|
37
37
|
ISSUER: "gizmette.com"
|
|
38
|
-
},
|
|
38
|
+
}, ue = `-----BEGIN PUBLIC KEY-----
|
|
39
39
|
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAsF6i3Jd9fY/3COqCw/m7
|
|
40
40
|
w5PKyTYLGAI2I6SIIdpe6i6DOCbEkmDz7LdVsBqwNtVi8gvWYIj+8ol6rU3qu1v5
|
|
41
41
|
i1Jd45GSK4kzkVdgCmQZbM5ak0KI99q5wsrAIzUd+LRJ2HRvWtr5IYdsIiXaQjle
|
|
@@ -43,33 +43,33 @@ aMwPFOIcJH+rKfFgNcHLcaS5syp7zU1ANwZ+trgR+DifBr8TLVkBynmNeTyhDm2+
|
|
|
43
43
|
l0haqjMk0UoNPPE8iYBWUHQJJE1Dqstj65d6Eh5g64Pao25y4cmYJbKjiblIGEkE
|
|
44
44
|
sjqybA9mARAqh9k/eiIopecWSiffNQTwVQVd2I9ZH3BalhEXHlqFgrjz51kFqg81
|
|
45
45
|
awIDAQAB
|
|
46
|
-
-----END PUBLIC KEY-----`,
|
|
46
|
+
-----END PUBLIC KEY-----`, ut = {
|
|
47
47
|
ACCESS: "5m",
|
|
48
48
|
ID: "90d",
|
|
49
49
|
REFRESH: "90d"
|
|
50
|
-
},
|
|
50
|
+
}, dt = {
|
|
51
51
|
CODE: "code",
|
|
52
52
|
LOGOUT: "logout",
|
|
53
53
|
LOGIN: "login",
|
|
54
54
|
REFRESH: "refresh"
|
|
55
|
-
},
|
|
56
|
-
function
|
|
57
|
-
const t = e.reduce((
|
|
55
|
+
}, D = crypto, Q = (e) => e instanceof CryptoKey, I = new TextEncoder(), P = new TextDecoder();
|
|
56
|
+
function de(...e) {
|
|
57
|
+
const t = e.reduce((o, { length: a }) => o + a, 0), r = new Uint8Array(t);
|
|
58
58
|
let n = 0;
|
|
59
|
-
for (const
|
|
60
|
-
r.set(
|
|
59
|
+
for (const o of e)
|
|
60
|
+
r.set(o, n), n += o.length;
|
|
61
61
|
return r;
|
|
62
62
|
}
|
|
63
|
-
const
|
|
63
|
+
const fe = (e) => {
|
|
64
64
|
const t = atob(e), r = new Uint8Array(t.length);
|
|
65
65
|
for (let n = 0; n < t.length; n++)
|
|
66
66
|
r[n] = t.charCodeAt(n);
|
|
67
67
|
return r;
|
|
68
|
-
},
|
|
68
|
+
}, g = (e) => {
|
|
69
69
|
let t = e;
|
|
70
|
-
t instanceof Uint8Array && (t =
|
|
70
|
+
t instanceof Uint8Array && (t = P.decode(t)), t = t.replace(/-/g, "+").replace(/_/g, "/").replace(/\s/g, "");
|
|
71
71
|
try {
|
|
72
|
-
return
|
|
72
|
+
return fe(t);
|
|
73
73
|
} catch {
|
|
74
74
|
throw new TypeError("The input to be decoded is not correctly encoded.");
|
|
75
75
|
}
|
|
@@ -87,19 +87,19 @@ class h extends A {
|
|
|
87
87
|
static get code() {
|
|
88
88
|
return "ERR_JWT_CLAIM_VALIDATION_FAILED";
|
|
89
89
|
}
|
|
90
|
-
constructor(t, r, n = "unspecified",
|
|
91
|
-
super(t), this.code = "ERR_JWT_CLAIM_VALIDATION_FAILED", this.claim = n, this.reason =
|
|
90
|
+
constructor(t, r, n = "unspecified", o = "unspecified") {
|
|
91
|
+
super(t), this.code = "ERR_JWT_CLAIM_VALIDATION_FAILED", this.claim = n, this.reason = o, this.payload = r;
|
|
92
92
|
}
|
|
93
93
|
}
|
|
94
|
-
class
|
|
94
|
+
class B extends A {
|
|
95
95
|
static get code() {
|
|
96
96
|
return "ERR_JWT_EXPIRED";
|
|
97
97
|
}
|
|
98
|
-
constructor(t, r, n = "unspecified",
|
|
99
|
-
super(t), this.code = "ERR_JWT_EXPIRED", this.claim = n, this.reason =
|
|
98
|
+
constructor(t, r, n = "unspecified", o = "unspecified") {
|
|
99
|
+
super(t), this.code = "ERR_JWT_EXPIRED", this.claim = n, this.reason = o, this.payload = r;
|
|
100
100
|
}
|
|
101
101
|
}
|
|
102
|
-
class
|
|
102
|
+
class le extends A {
|
|
103
103
|
constructor() {
|
|
104
104
|
super(...arguments), this.code = "ERR_JOSE_ALG_NOT_ALLOWED";
|
|
105
105
|
}
|
|
@@ -107,7 +107,7 @@ class ce extends A {
|
|
|
107
107
|
return "ERR_JOSE_ALG_NOT_ALLOWED";
|
|
108
108
|
}
|
|
109
109
|
}
|
|
110
|
-
class
|
|
110
|
+
class p extends A {
|
|
111
111
|
constructor() {
|
|
112
112
|
super(...arguments), this.code = "ERR_JOSE_NOT_SUPPORTED";
|
|
113
113
|
}
|
|
@@ -115,7 +115,7 @@ class w extends A {
|
|
|
115
115
|
return "ERR_JOSE_NOT_SUPPORTED";
|
|
116
116
|
}
|
|
117
117
|
}
|
|
118
|
-
class
|
|
118
|
+
class d extends A {
|
|
119
119
|
constructor() {
|
|
120
120
|
super(...arguments), this.code = "ERR_JWS_INVALID";
|
|
121
121
|
}
|
|
@@ -131,7 +131,7 @@ class S extends A {
|
|
|
131
131
|
return "ERR_JWT_INVALID";
|
|
132
132
|
}
|
|
133
133
|
}
|
|
134
|
-
class
|
|
134
|
+
class he extends A {
|
|
135
135
|
constructor() {
|
|
136
136
|
super(...arguments), this.code = "ERR_JWS_SIGNATURE_VERIFICATION_FAILED", this.message = "signature verification failed";
|
|
137
137
|
}
|
|
@@ -139,16 +139,16 @@ class se extends A {
|
|
|
139
139
|
return "ERR_JWS_SIGNATURE_VERIFICATION_FAILED";
|
|
140
140
|
}
|
|
141
141
|
}
|
|
142
|
-
function
|
|
142
|
+
function y(e, t = "algorithm.name") {
|
|
143
143
|
return new TypeError(`CryptoKey does not support this operation, its ${t} must be ${e}`);
|
|
144
144
|
}
|
|
145
|
-
function
|
|
145
|
+
function R(e, t) {
|
|
146
146
|
return e.name === t;
|
|
147
147
|
}
|
|
148
|
-
function
|
|
148
|
+
function N(e) {
|
|
149
149
|
return parseInt(e.name.slice(4), 10);
|
|
150
150
|
}
|
|
151
|
-
function
|
|
151
|
+
function pe(e) {
|
|
152
152
|
switch (e) {
|
|
153
153
|
case "ES256":
|
|
154
154
|
return "P-256";
|
|
@@ -160,7 +160,7 @@ function de(e) {
|
|
|
160
160
|
throw new Error("unreachable");
|
|
161
161
|
}
|
|
162
162
|
}
|
|
163
|
-
function
|
|
163
|
+
function me(e, t) {
|
|
164
164
|
if (t.length && !t.some((r) => e.usages.includes(r))) {
|
|
165
165
|
let r = "CryptoKey does not support this operation, its usages must include ";
|
|
166
166
|
if (t.length > 2) {
|
|
@@ -170,94 +170,94 @@ function ue(e, t) {
|
|
|
170
170
|
throw new TypeError(r);
|
|
171
171
|
}
|
|
172
172
|
}
|
|
173
|
-
function
|
|
173
|
+
function ye(e, t, ...r) {
|
|
174
174
|
switch (t) {
|
|
175
175
|
case "HS256":
|
|
176
176
|
case "HS384":
|
|
177
177
|
case "HS512": {
|
|
178
|
-
if (!
|
|
179
|
-
throw
|
|
178
|
+
if (!R(e.algorithm, "HMAC"))
|
|
179
|
+
throw y("HMAC");
|
|
180
180
|
const n = parseInt(t.slice(2), 10);
|
|
181
|
-
if (
|
|
182
|
-
throw
|
|
181
|
+
if (N(e.algorithm.hash) !== n)
|
|
182
|
+
throw y(`SHA-${n}`, "algorithm.hash");
|
|
183
183
|
break;
|
|
184
184
|
}
|
|
185
185
|
case "RS256":
|
|
186
186
|
case "RS384":
|
|
187
187
|
case "RS512": {
|
|
188
|
-
if (!
|
|
189
|
-
throw
|
|
188
|
+
if (!R(e.algorithm, "RSASSA-PKCS1-v1_5"))
|
|
189
|
+
throw y("RSASSA-PKCS1-v1_5");
|
|
190
190
|
const n = parseInt(t.slice(2), 10);
|
|
191
|
-
if (
|
|
192
|
-
throw
|
|
191
|
+
if (N(e.algorithm.hash) !== n)
|
|
192
|
+
throw y(`SHA-${n}`, "algorithm.hash");
|
|
193
193
|
break;
|
|
194
194
|
}
|
|
195
195
|
case "PS256":
|
|
196
196
|
case "PS384":
|
|
197
197
|
case "PS512": {
|
|
198
|
-
if (!
|
|
199
|
-
throw
|
|
198
|
+
if (!R(e.algorithm, "RSA-PSS"))
|
|
199
|
+
throw y("RSA-PSS");
|
|
200
200
|
const n = parseInt(t.slice(2), 10);
|
|
201
|
-
if (
|
|
202
|
-
throw
|
|
201
|
+
if (N(e.algorithm.hash) !== n)
|
|
202
|
+
throw y(`SHA-${n}`, "algorithm.hash");
|
|
203
203
|
break;
|
|
204
204
|
}
|
|
205
205
|
case "EdDSA": {
|
|
206
206
|
if (e.algorithm.name !== "Ed25519" && e.algorithm.name !== "Ed448")
|
|
207
|
-
throw
|
|
207
|
+
throw y("Ed25519 or Ed448");
|
|
208
208
|
break;
|
|
209
209
|
}
|
|
210
210
|
case "ES256":
|
|
211
211
|
case "ES384":
|
|
212
212
|
case "ES512": {
|
|
213
|
-
if (!
|
|
214
|
-
throw
|
|
215
|
-
const n =
|
|
213
|
+
if (!R(e.algorithm, "ECDSA"))
|
|
214
|
+
throw y("ECDSA");
|
|
215
|
+
const n = pe(t);
|
|
216
216
|
if (e.algorithm.namedCurve !== n)
|
|
217
|
-
throw
|
|
217
|
+
throw y(n, "algorithm.namedCurve");
|
|
218
218
|
break;
|
|
219
219
|
}
|
|
220
220
|
default:
|
|
221
221
|
throw new TypeError("CryptoKey does not support this operation");
|
|
222
222
|
}
|
|
223
|
-
|
|
223
|
+
me(e, r);
|
|
224
224
|
}
|
|
225
|
-
function
|
|
225
|
+
function Z(e, t, ...r) {
|
|
226
226
|
var n;
|
|
227
|
-
if (r.length > 2) {
|
|
228
|
-
const
|
|
229
|
-
e += `one of type ${r.join(", ")}, or ${
|
|
227
|
+
if (r = r.filter(Boolean), r.length > 2) {
|
|
228
|
+
const o = r.pop();
|
|
229
|
+
e += `one of type ${r.join(", ")}, or ${o}.`;
|
|
230
230
|
} else r.length === 2 ? e += `one of type ${r[0]} or ${r[1]}.` : e += `of type ${r[0]}.`;
|
|
231
231
|
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;
|
|
232
232
|
}
|
|
233
|
-
const
|
|
234
|
-
function
|
|
235
|
-
return
|
|
233
|
+
const V = (e, ...t) => Z("Key must be ", e, ...t);
|
|
234
|
+
function j(e, t, ...r) {
|
|
235
|
+
return Z(`Key for the ${e} algorithm must be `, t, ...r);
|
|
236
236
|
}
|
|
237
|
-
const
|
|
237
|
+
const ee = (e) => Q(e) ? !0 : (e == null ? void 0 : e[Symbol.toStringTag]) === "KeyObject", x = ["CryptoKey"], Se = (...e) => {
|
|
238
238
|
const t = e.filter(Boolean);
|
|
239
239
|
if (t.length === 0 || t.length === 1)
|
|
240
240
|
return !0;
|
|
241
241
|
let r;
|
|
242
242
|
for (const n of t) {
|
|
243
|
-
const
|
|
243
|
+
const o = Object.keys(n);
|
|
244
244
|
if (!r || r.size === 0) {
|
|
245
|
-
r = new Set(
|
|
245
|
+
r = new Set(o);
|
|
246
246
|
continue;
|
|
247
247
|
}
|
|
248
|
-
for (const
|
|
249
|
-
if (r.has(
|
|
248
|
+
for (const a of o) {
|
|
249
|
+
if (r.has(a))
|
|
250
250
|
return !1;
|
|
251
|
-
r.add(
|
|
251
|
+
r.add(a);
|
|
252
252
|
}
|
|
253
253
|
}
|
|
254
254
|
return !0;
|
|
255
255
|
};
|
|
256
|
-
function
|
|
256
|
+
function Ee(e) {
|
|
257
257
|
return typeof e == "object" && e !== null;
|
|
258
258
|
}
|
|
259
|
-
function
|
|
260
|
-
if (!
|
|
259
|
+
function _(e) {
|
|
260
|
+
if (!Ee(e) || Object.prototype.toString.call(e) !== "[object Object]")
|
|
261
261
|
return !1;
|
|
262
262
|
if (Object.getPrototypeOf(e) === null)
|
|
263
263
|
return !0;
|
|
@@ -266,14 +266,26 @@ function K(e) {
|
|
|
266
266
|
t = Object.getPrototypeOf(t);
|
|
267
267
|
return Object.getPrototypeOf(e) === t;
|
|
268
268
|
}
|
|
269
|
-
const
|
|
269
|
+
const we = (e, t) => {
|
|
270
270
|
if (e.startsWith("RS") || e.startsWith("PS")) {
|
|
271
271
|
const { modulusLength: r } = t.algorithm;
|
|
272
272
|
if (typeof r != "number" || r < 2048)
|
|
273
273
|
throw new TypeError(`${e} requires key modulusLength to be 2048 bits or larger`);
|
|
274
274
|
}
|
|
275
275
|
};
|
|
276
|
-
function
|
|
276
|
+
function K(e) {
|
|
277
|
+
return _(e) && typeof e.kty == "string";
|
|
278
|
+
}
|
|
279
|
+
function ge(e) {
|
|
280
|
+
return e.kty !== "oct" && typeof e.d == "string";
|
|
281
|
+
}
|
|
282
|
+
function be(e) {
|
|
283
|
+
return e.kty !== "oct" && typeof e.d > "u";
|
|
284
|
+
}
|
|
285
|
+
function Ae(e) {
|
|
286
|
+
return K(e) && e.kty === "oct" && typeof e.k == "string";
|
|
287
|
+
}
|
|
288
|
+
function Ce(e) {
|
|
277
289
|
let t, r;
|
|
278
290
|
switch (e.kty) {
|
|
279
291
|
case "RSA": {
|
|
@@ -298,7 +310,7 @@ function me(e) {
|
|
|
298
310
|
}, r = e.d ? ["decrypt", "unwrapKey"] : ["encrypt", "wrapKey"];
|
|
299
311
|
break;
|
|
300
312
|
default:
|
|
301
|
-
throw new
|
|
313
|
+
throw new p('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
|
|
302
314
|
}
|
|
303
315
|
break;
|
|
304
316
|
}
|
|
@@ -320,7 +332,7 @@ function me(e) {
|
|
|
320
332
|
t = { name: "ECDH", namedCurve: e.crv }, r = e.d ? ["deriveBits"] : [];
|
|
321
333
|
break;
|
|
322
334
|
default:
|
|
323
|
-
throw new
|
|
335
|
+
throw new p('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
|
|
324
336
|
}
|
|
325
337
|
break;
|
|
326
338
|
}
|
|
@@ -336,168 +348,218 @@ function me(e) {
|
|
|
336
348
|
t = { name: e.crv }, r = e.d ? ["deriveBits"] : [];
|
|
337
349
|
break;
|
|
338
350
|
default:
|
|
339
|
-
throw new
|
|
351
|
+
throw new p('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
|
|
340
352
|
}
|
|
341
353
|
break;
|
|
342
354
|
}
|
|
343
355
|
default:
|
|
344
|
-
throw new
|
|
356
|
+
throw new p('Invalid or unsupported JWK "kty" (Key Type) Parameter value');
|
|
345
357
|
}
|
|
346
358
|
return { algorithm: t, keyUsages: r };
|
|
347
359
|
}
|
|
348
|
-
const
|
|
360
|
+
const te = async (e) => {
|
|
349
361
|
if (!e.alg)
|
|
350
362
|
throw new TypeError('"alg" argument is required when "jwk.alg" is not present');
|
|
351
|
-
const { algorithm: t, keyUsages: r } =
|
|
363
|
+
const { algorithm: t, keyUsages: r } = Ce(e), n = [
|
|
352
364
|
t,
|
|
353
365
|
e.ext ?? !1,
|
|
354
366
|
e.key_ops ?? r
|
|
355
|
-
],
|
|
356
|
-
return delete
|
|
357
|
-
},
|
|
358
|
-
let
|
|
359
|
-
const
|
|
367
|
+
], o = { ...e };
|
|
368
|
+
return delete o.alg, delete o.use, D.subtle.importKey("jwk", o, ...n);
|
|
369
|
+
}, re = (e) => g(e);
|
|
370
|
+
let C, v;
|
|
371
|
+
const ne = (e) => (e == null ? void 0 : e[Symbol.toStringTag]) === "KeyObject", J = async (e, t, r, n, o = !1) => {
|
|
360
372
|
let a = e.get(t);
|
|
361
373
|
if (a != null && a[n])
|
|
362
374
|
return a[n];
|
|
363
|
-
const
|
|
364
|
-
return a ? a[n] =
|
|
365
|
-
},
|
|
366
|
-
if (
|
|
375
|
+
const i = await te({ ...r, alg: n });
|
|
376
|
+
return o && Object.freeze(t), a ? a[n] = i : e.set(t, { [n]: i }), i;
|
|
377
|
+
}, ve = (e, t) => {
|
|
378
|
+
if (ne(e)) {
|
|
367
379
|
let r = e.export({ format: "jwk" });
|
|
368
|
-
return delete r.d, delete r.dp, delete r.dq, delete r.p, delete r.q, delete r.qi, r.k ?
|
|
380
|
+
return delete r.d, delete r.dp, delete r.dq, delete r.p, delete r.q, delete r.qi, r.k ? re(r.k) : (v || (v = /* @__PURE__ */ new WeakMap()), J(v, e, r, t));
|
|
369
381
|
}
|
|
370
|
-
return e;
|
|
371
|
-
},
|
|
372
|
-
if (
|
|
382
|
+
return K(e) ? e.k ? g(e.k) : (v || (v = /* @__PURE__ */ new WeakMap()), J(v, e, e, t, !0)) : e;
|
|
383
|
+
}, Te = (e, t) => {
|
|
384
|
+
if (ne(e)) {
|
|
373
385
|
let r = e.export({ format: "jwk" });
|
|
374
|
-
return r.k ?
|
|
386
|
+
return r.k ? re(r.k) : (C || (C = /* @__PURE__ */ new WeakMap()), J(C, e, r, t));
|
|
375
387
|
}
|
|
376
|
-
return e;
|
|
377
|
-
},
|
|
388
|
+
return K(e) ? e.k ? g(e.k) : (C || (C = /* @__PURE__ */ new WeakMap()), J(C, e, e, t, !0)) : e;
|
|
389
|
+
}, _e = { normalizePublicKey: ve, normalizePrivateKey: Te }, w = (e, t, r = 0) => {
|
|
378
390
|
r === 0 && (t.unshift(t.length), t.unshift(6));
|
|
379
391
|
const n = e.indexOf(t[0], r);
|
|
380
392
|
if (n === -1)
|
|
381
393
|
return !1;
|
|
382
|
-
const
|
|
383
|
-
return
|
|
384
|
-
},
|
|
394
|
+
const o = e.subarray(n, n + t.length);
|
|
395
|
+
return o.length !== t.length ? !1 : o.every((a, i) => a === t[i]) || w(e, t, n + 1);
|
|
396
|
+
}, F = (e) => {
|
|
385
397
|
switch (!0) {
|
|
386
|
-
case
|
|
398
|
+
case w(e, [42, 134, 72, 206, 61, 3, 1, 7]):
|
|
387
399
|
return "P-256";
|
|
388
|
-
case
|
|
400
|
+
case w(e, [43, 129, 4, 0, 34]):
|
|
389
401
|
return "P-384";
|
|
390
|
-
case
|
|
402
|
+
case w(e, [43, 129, 4, 0, 35]):
|
|
391
403
|
return "P-521";
|
|
392
|
-
case
|
|
404
|
+
case w(e, [43, 101, 110]):
|
|
393
405
|
return "X25519";
|
|
394
|
-
case
|
|
406
|
+
case w(e, [43, 101, 111]):
|
|
395
407
|
return "X448";
|
|
396
|
-
case
|
|
408
|
+
case w(e, [43, 101, 112]):
|
|
397
409
|
return "Ed25519";
|
|
398
|
-
case
|
|
410
|
+
case w(e, [43, 101, 113]):
|
|
399
411
|
return "Ed448";
|
|
400
412
|
default:
|
|
401
|
-
throw new
|
|
413
|
+
throw new p("Invalid or unsupported EC Key Curve or OKP Key Sub Type");
|
|
402
414
|
}
|
|
403
|
-
},
|
|
404
|
-
let
|
|
415
|
+
}, Ke = async (e, t, r, n, o) => {
|
|
416
|
+
let a, i;
|
|
405
417
|
const c = new Uint8Array(atob(r.replace(e, "")).split("").map((s) => s.charCodeAt(0)));
|
|
406
418
|
switch (n) {
|
|
407
419
|
case "PS256":
|
|
408
420
|
case "PS384":
|
|
409
421
|
case "PS512":
|
|
410
|
-
|
|
422
|
+
a = { name: "RSA-PSS", hash: `SHA-${n.slice(-3)}` }, i = ["verify"];
|
|
411
423
|
break;
|
|
412
424
|
case "RS256":
|
|
413
425
|
case "RS384":
|
|
414
426
|
case "RS512":
|
|
415
|
-
|
|
427
|
+
a = { name: "RSASSA-PKCS1-v1_5", hash: `SHA-${n.slice(-3)}` }, i = ["verify"];
|
|
416
428
|
break;
|
|
417
429
|
case "RSA-OAEP":
|
|
418
430
|
case "RSA-OAEP-256":
|
|
419
431
|
case "RSA-OAEP-384":
|
|
420
432
|
case "RSA-OAEP-512":
|
|
421
|
-
|
|
433
|
+
a = {
|
|
422
434
|
name: "RSA-OAEP",
|
|
423
435
|
hash: `SHA-${parseInt(n.slice(-3), 10) || 1}`
|
|
424
436
|
}, i = ["encrypt", "wrapKey"];
|
|
425
437
|
break;
|
|
426
438
|
case "ES256":
|
|
427
|
-
|
|
439
|
+
a = { name: "ECDSA", namedCurve: "P-256" }, i = ["verify"];
|
|
428
440
|
break;
|
|
429
441
|
case "ES384":
|
|
430
|
-
|
|
442
|
+
a = { name: "ECDSA", namedCurve: "P-384" }, i = ["verify"];
|
|
431
443
|
break;
|
|
432
444
|
case "ES512":
|
|
433
|
-
|
|
445
|
+
a = { name: "ECDSA", namedCurve: "P-521" }, i = ["verify"];
|
|
434
446
|
break;
|
|
435
447
|
case "ECDH-ES":
|
|
436
448
|
case "ECDH-ES+A128KW":
|
|
437
449
|
case "ECDH-ES+A192KW":
|
|
438
450
|
case "ECDH-ES+A256KW": {
|
|
439
|
-
const s =
|
|
440
|
-
|
|
451
|
+
const s = F(c);
|
|
452
|
+
a = s.startsWith("P-") ? { name: "ECDH", namedCurve: s } : { name: s }, i = [];
|
|
441
453
|
break;
|
|
442
454
|
}
|
|
443
455
|
case "EdDSA":
|
|
444
|
-
|
|
456
|
+
a = { name: F(c) }, i = ["verify"];
|
|
445
457
|
break;
|
|
446
458
|
default:
|
|
447
|
-
throw new
|
|
459
|
+
throw new p('Invalid or unsupported "alg" (Algorithm) value');
|
|
448
460
|
}
|
|
449
|
-
return
|
|
450
|
-
},
|
|
451
|
-
async function
|
|
461
|
+
return D.subtle.importKey(t, c, a, !1, i);
|
|
462
|
+
}, Pe = (e, t, r) => Ke(/(?:-----(?:BEGIN|END) PUBLIC KEY-----|\s)/g, "spki", e, t);
|
|
463
|
+
async function Ie(e, t, r) {
|
|
452
464
|
if (e.indexOf("-----BEGIN PUBLIC KEY-----") !== 0)
|
|
453
465
|
throw new TypeError('"spki" must be SPKI formatted string');
|
|
454
|
-
return
|
|
466
|
+
return Pe(e, t);
|
|
467
|
+
}
|
|
468
|
+
async function Re(e, t) {
|
|
469
|
+
if (!_(e))
|
|
470
|
+
throw new TypeError("JWK must be an object");
|
|
471
|
+
switch (t || (t = e.alg), e.kty) {
|
|
472
|
+
case "oct":
|
|
473
|
+
if (typeof e.k != "string" || !e.k)
|
|
474
|
+
throw new TypeError('missing "k" (Key Value) Parameter value');
|
|
475
|
+
return g(e.k);
|
|
476
|
+
case "RSA":
|
|
477
|
+
if (e.oth !== void 0)
|
|
478
|
+
throw new p('RSA JWK "oth" (Other Primes Info) Parameter value is not supported');
|
|
479
|
+
case "EC":
|
|
480
|
+
case "OKP":
|
|
481
|
+
return te({ ...e, alg: t });
|
|
482
|
+
default:
|
|
483
|
+
throw new p('Unsupported "kty" (Key Type) Parameter value');
|
|
484
|
+
}
|
|
455
485
|
}
|
|
456
|
-
const
|
|
486
|
+
const T = (e) => e == null ? void 0 : e[Symbol.toStringTag], $ = (e, t, r) => {
|
|
487
|
+
var n, o;
|
|
488
|
+
if (t.use !== void 0 && t.use !== "sig")
|
|
489
|
+
throw new TypeError("Invalid key for this operation, when present its use must be sig");
|
|
490
|
+
if (t.key_ops !== void 0 && ((o = (n = t.key_ops).includes) == null ? void 0 : o.call(n, r)) !== !0)
|
|
491
|
+
throw new TypeError(`Invalid key for this operation, when present its key_ops must include ${r}`);
|
|
492
|
+
if (t.alg !== void 0 && t.alg !== e)
|
|
493
|
+
throw new TypeError(`Invalid key for this operation, when present its alg must be ${e}`);
|
|
494
|
+
return !0;
|
|
495
|
+
}, Oe = (e, t, r, n) => {
|
|
457
496
|
if (!(t instanceof Uint8Array)) {
|
|
458
|
-
if (
|
|
459
|
-
|
|
497
|
+
if (n && K(t)) {
|
|
498
|
+
if (Ae(t) && $(e, t, r))
|
|
499
|
+
return;
|
|
500
|
+
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');
|
|
501
|
+
}
|
|
502
|
+
if (!ee(t))
|
|
503
|
+
throw new TypeError(j(e, t, ...x, "Uint8Array", n ? "JSON Web Key" : null));
|
|
460
504
|
if (t.type !== "secret")
|
|
461
|
-
throw new TypeError(`${
|
|
462
|
-
}
|
|
463
|
-
},
|
|
464
|
-
if (
|
|
465
|
-
|
|
505
|
+
throw new TypeError(`${T(t)} instances for symmetric algorithms must be of type "secret"`);
|
|
506
|
+
}
|
|
507
|
+
}, We = (e, t, r, n) => {
|
|
508
|
+
if (n && K(t))
|
|
509
|
+
switch (r) {
|
|
510
|
+
case "sign":
|
|
511
|
+
if (ge(t) && $(e, t, r))
|
|
512
|
+
return;
|
|
513
|
+
throw new TypeError("JSON Web Key for this operation be a private JWK");
|
|
514
|
+
case "verify":
|
|
515
|
+
if (be(t) && $(e, t, r))
|
|
516
|
+
return;
|
|
517
|
+
throw new TypeError("JSON Web Key for this operation be a public JWK");
|
|
518
|
+
}
|
|
519
|
+
if (!ee(t))
|
|
520
|
+
throw new TypeError(j(e, t, ...x, n ? "JSON Web Key" : null));
|
|
466
521
|
if (t.type === "secret")
|
|
467
|
-
throw new TypeError(`${
|
|
522
|
+
throw new TypeError(`${T(t)} instances for asymmetric algorithms must not be of type "secret"`);
|
|
523
|
+
if (r === "sign" && t.type === "public")
|
|
524
|
+
throw new TypeError(`${T(t)} instances for asymmetric algorithm signing must be of type "private"`);
|
|
525
|
+
if (r === "decrypt" && t.type === "public")
|
|
526
|
+
throw new TypeError(`${T(t)} instances for asymmetric algorithm decryption must be of type "private"`);
|
|
468
527
|
if (t.algorithm && r === "verify" && t.type === "private")
|
|
469
|
-
throw new TypeError(`${
|
|
528
|
+
throw new TypeError(`${T(t)} instances for asymmetric algorithm verifying must be of type "public"`);
|
|
470
529
|
if (t.algorithm && r === "encrypt" && t.type === "private")
|
|
471
|
-
throw new TypeError(`${
|
|
472
|
-
}, ve = (e, t, r) => {
|
|
473
|
-
e.startsWith("HS") || e === "dir" || e.startsWith("PBES2") || /^A\d{3}(?:GCM)?KW$/.test(e) ? Ce(e, t) : _e(e, t, r);
|
|
530
|
+
throw new TypeError(`${T(t)} instances for asymmetric algorithm encryption must be of type "public"`);
|
|
474
531
|
};
|
|
475
|
-
function
|
|
476
|
-
|
|
532
|
+
function oe(e, t, r, n) {
|
|
533
|
+
t.startsWith("HS") || t === "dir" || t.startsWith("PBES2") || /^A\d{3}(?:GCM)?KW$/.test(t) ? Oe(t, r, n, e) : We(t, r, n, e);
|
|
534
|
+
}
|
|
535
|
+
oe.bind(void 0, !1);
|
|
536
|
+
const Y = oe.bind(void 0, !0);
|
|
537
|
+
function xe(e, t, r, n, o) {
|
|
538
|
+
if (o.crit !== void 0 && (n == null ? void 0 : n.crit) === void 0)
|
|
477
539
|
throw new e('"crit" (Critical) Header Parameter MUST be integrity protected');
|
|
478
540
|
if (!n || n.crit === void 0)
|
|
479
541
|
return /* @__PURE__ */ new Set();
|
|
480
542
|
if (!Array.isArray(n.crit) || n.crit.length === 0 || n.crit.some((i) => typeof i != "string" || i.length === 0))
|
|
481
543
|
throw new e('"crit" (Critical) Header Parameter MUST be an array of non-empty strings when present');
|
|
482
|
-
let
|
|
483
|
-
r !== void 0 ?
|
|
544
|
+
let a;
|
|
545
|
+
r !== void 0 ? a = new Map([...Object.entries(r), ...t.entries()]) : a = t;
|
|
484
546
|
for (const i of n.crit) {
|
|
485
|
-
if (!
|
|
486
|
-
throw new
|
|
487
|
-
if (
|
|
547
|
+
if (!a.has(i))
|
|
548
|
+
throw new p(`Extension Header Parameter "${i}" is not recognized`);
|
|
549
|
+
if (o[i] === void 0)
|
|
488
550
|
throw new e(`Extension Header Parameter "${i}" is missing`);
|
|
489
|
-
if (
|
|
551
|
+
if (a.get(i) && n[i] === void 0)
|
|
490
552
|
throw new e(`Extension Header Parameter "${i}" MUST be integrity protected`);
|
|
491
553
|
}
|
|
492
554
|
return new Set(n.crit);
|
|
493
555
|
}
|
|
494
|
-
const
|
|
556
|
+
const Je = (e, t) => {
|
|
495
557
|
if (t !== void 0 && (!Array.isArray(t) || t.some((r) => typeof r != "string")))
|
|
496
558
|
throw new TypeError(`"${e}" option must be an array of strings`);
|
|
497
559
|
if (t)
|
|
498
560
|
return new Set(t);
|
|
499
561
|
};
|
|
500
|
-
function
|
|
562
|
+
function De(e, t) {
|
|
501
563
|
const r = `SHA-${e.slice(-3)}`;
|
|
502
564
|
switch (e) {
|
|
503
565
|
case "HS256":
|
|
@@ -519,214 +581,214 @@ function Re(e, t) {
|
|
|
519
581
|
case "EdDSA":
|
|
520
582
|
return { name: t.name };
|
|
521
583
|
default:
|
|
522
|
-
throw new
|
|
584
|
+
throw new p(`alg ${e} is not supported either by JOSE or your javascript runtime`);
|
|
523
585
|
}
|
|
524
586
|
}
|
|
525
|
-
async function
|
|
526
|
-
if (t = await
|
|
527
|
-
return
|
|
587
|
+
async function He(e, t, r) {
|
|
588
|
+
if (t = await _e.normalizePublicKey(t, e), Q(t))
|
|
589
|
+
return ye(t, e, r), t;
|
|
528
590
|
if (t instanceof Uint8Array) {
|
|
529
591
|
if (!e.startsWith("HS"))
|
|
530
|
-
throw new TypeError(
|
|
531
|
-
return
|
|
592
|
+
throw new TypeError(V(t, ...x));
|
|
593
|
+
return D.subtle.importKey("raw", t, { hash: `SHA-${e.slice(-3)}`, name: "HMAC" }, !1, [r]);
|
|
532
594
|
}
|
|
533
|
-
throw new TypeError(
|
|
595
|
+
throw new TypeError(V(t, ...x, "Uint8Array", "JSON Web Key"));
|
|
534
596
|
}
|
|
535
|
-
const
|
|
536
|
-
const
|
|
537
|
-
|
|
538
|
-
const
|
|
597
|
+
const Ne = async (e, t, r, n) => {
|
|
598
|
+
const o = await He(e, t, "verify");
|
|
599
|
+
we(e, o);
|
|
600
|
+
const a = De(e, o.algorithm);
|
|
539
601
|
try {
|
|
540
|
-
return await
|
|
602
|
+
return await D.subtle.verify(a, o, r, n);
|
|
541
603
|
} catch {
|
|
542
604
|
return !1;
|
|
543
605
|
}
|
|
544
606
|
};
|
|
545
|
-
async function
|
|
546
|
-
if (!
|
|
547
|
-
throw new
|
|
607
|
+
async function Ue(e, t, r) {
|
|
608
|
+
if (!_(e))
|
|
609
|
+
throw new d("Flattened JWS must be an object");
|
|
548
610
|
if (e.protected === void 0 && e.header === void 0)
|
|
549
|
-
throw new
|
|
611
|
+
throw new d('Flattened JWS must have either of the "protected" or "header" members');
|
|
550
612
|
if (e.protected !== void 0 && typeof e.protected != "string")
|
|
551
|
-
throw new
|
|
613
|
+
throw new d("JWS Protected Header incorrect type");
|
|
552
614
|
if (e.payload === void 0)
|
|
553
|
-
throw new
|
|
615
|
+
throw new d("JWS Payload missing");
|
|
554
616
|
if (typeof e.signature != "string")
|
|
555
|
-
throw new
|
|
556
|
-
if (e.header !== void 0 && !
|
|
557
|
-
throw new
|
|
617
|
+
throw new d("JWS Signature missing or incorrect type");
|
|
618
|
+
if (e.header !== void 0 && !_(e.header))
|
|
619
|
+
throw new d("JWS Unprotected Header incorrect type");
|
|
558
620
|
let n = {};
|
|
559
621
|
if (e.protected)
|
|
560
622
|
try {
|
|
561
|
-
const
|
|
562
|
-
n = JSON.parse(
|
|
623
|
+
const H = g(e.protected);
|
|
624
|
+
n = JSON.parse(P.decode(H));
|
|
563
625
|
} catch {
|
|
564
|
-
throw new
|
|
626
|
+
throw new d("JWS Protected Header is invalid");
|
|
565
627
|
}
|
|
566
|
-
if (!
|
|
567
|
-
throw new
|
|
568
|
-
const
|
|
628
|
+
if (!Se(n, e.header))
|
|
629
|
+
throw new d("JWS Protected and JWS Unprotected Header Parameter names must be disjoint");
|
|
630
|
+
const o = {
|
|
569
631
|
...n,
|
|
570
632
|
...e.header
|
|
571
|
-
},
|
|
633
|
+
}, a = xe(d, /* @__PURE__ */ new Map([["b64", !0]]), r == null ? void 0 : r.crit, n, o);
|
|
572
634
|
let i = !0;
|
|
573
|
-
if (
|
|
574
|
-
throw new
|
|
575
|
-
const { alg: c } =
|
|
635
|
+
if (a.has("b64") && (i = n.b64, typeof i != "boolean"))
|
|
636
|
+
throw new d('The "b64" (base64url-encode payload) Header Parameter must be a boolean');
|
|
637
|
+
const { alg: c } = o;
|
|
576
638
|
if (typeof c != "string" || !c)
|
|
577
|
-
throw new
|
|
578
|
-
const s = r &&
|
|
639
|
+
throw new d('JWS "alg" (Algorithm) Header Parameter missing or invalid');
|
|
640
|
+
const s = r && Je("algorithms", r.algorithms);
|
|
579
641
|
if (s && !s.has(c))
|
|
580
|
-
throw new
|
|
642
|
+
throw new le('"alg" (Algorithm) Header Parameter value not allowed');
|
|
581
643
|
if (i) {
|
|
582
644
|
if (typeof e.payload != "string")
|
|
583
|
-
throw new
|
|
645
|
+
throw new d("JWS Payload must be a string");
|
|
584
646
|
} else if (typeof e.payload != "string" && !(e.payload instanceof Uint8Array))
|
|
585
|
-
throw new
|
|
586
|
-
let
|
|
587
|
-
typeof t == "function"
|
|
588
|
-
const
|
|
589
|
-
let
|
|
647
|
+
throw new d("JWS Payload must be a string or an Uint8Array instance");
|
|
648
|
+
let m = !1;
|
|
649
|
+
typeof t == "function" ? (t = await t(n, e), m = !0, Y(c, t, "verify"), K(t) && (t = await Re(t, c))) : Y(c, t, "verify");
|
|
650
|
+
const b = de(I.encode(e.protected ?? ""), I.encode("."), typeof e.payload == "string" ? I.encode(e.payload) : e.payload);
|
|
651
|
+
let l;
|
|
590
652
|
try {
|
|
591
|
-
|
|
653
|
+
l = g(e.signature);
|
|
592
654
|
} catch {
|
|
593
|
-
throw new
|
|
655
|
+
throw new d("Failed to base64url decode the signature");
|
|
594
656
|
}
|
|
595
|
-
if (!await
|
|
596
|
-
throw new
|
|
597
|
-
let
|
|
657
|
+
if (!await Ne(c, t, l, b))
|
|
658
|
+
throw new he();
|
|
659
|
+
let E;
|
|
598
660
|
if (i)
|
|
599
661
|
try {
|
|
600
|
-
|
|
662
|
+
E = g(e.payload);
|
|
601
663
|
} catch {
|
|
602
|
-
throw new
|
|
664
|
+
throw new d("Failed to base64url decode the payload");
|
|
603
665
|
}
|
|
604
|
-
else typeof e.payload == "string" ?
|
|
605
|
-
const
|
|
606
|
-
return e.protected !== void 0 && (
|
|
607
|
-
}
|
|
608
|
-
async function
|
|
609
|
-
if (e instanceof Uint8Array && (e =
|
|
610
|
-
throw new
|
|
611
|
-
const { 0: n, 1:
|
|
666
|
+
else typeof e.payload == "string" ? E = I.encode(e.payload) : E = e.payload;
|
|
667
|
+
const f = { payload: E };
|
|
668
|
+
return e.protected !== void 0 && (f.protectedHeader = n), e.header !== void 0 && (f.unprotectedHeader = e.header), m ? { ...f, key: t } : f;
|
|
669
|
+
}
|
|
670
|
+
async function $e(e, t, r) {
|
|
671
|
+
if (e instanceof Uint8Array && (e = P.decode(e)), typeof e != "string")
|
|
672
|
+
throw new d("Compact JWS must be a string or Uint8Array");
|
|
673
|
+
const { 0: n, 1: o, 2: a, length: i } = e.split(".");
|
|
612
674
|
if (i !== 3)
|
|
613
|
-
throw new
|
|
614
|
-
const c = await
|
|
675
|
+
throw new d("Invalid Compact JWS");
|
|
676
|
+
const c = await Ue({ payload: o, protected: n, signature: a }, t, r), s = { payload: c.payload, protectedHeader: c.protectedHeader };
|
|
615
677
|
return typeof t == "function" ? { ...s, key: c.key } : s;
|
|
616
678
|
}
|
|
617
|
-
const
|
|
618
|
-
const t =
|
|
679
|
+
const Le = (e) => Math.floor(e.getTime() / 1e3), ae = 60, ie = ae * 60, L = ie * 24, Me = L * 7, Be = L * 365.25, Ve = /^(\+|\-)? ?(\d+|\d+\.\d+) ?(seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)(?: (ago|from now))?$/i, k = (e) => {
|
|
680
|
+
const t = Ve.exec(e);
|
|
619
681
|
if (!t || t[4] && t[1])
|
|
620
682
|
throw new TypeError("Invalid time period format");
|
|
621
683
|
const r = parseFloat(t[2]), n = t[3].toLowerCase();
|
|
622
|
-
let
|
|
684
|
+
let o;
|
|
623
685
|
switch (n) {
|
|
624
686
|
case "sec":
|
|
625
687
|
case "secs":
|
|
626
688
|
case "second":
|
|
627
689
|
case "seconds":
|
|
628
690
|
case "s":
|
|
629
|
-
|
|
691
|
+
o = Math.round(r);
|
|
630
692
|
break;
|
|
631
693
|
case "minute":
|
|
632
694
|
case "minutes":
|
|
633
695
|
case "min":
|
|
634
696
|
case "mins":
|
|
635
697
|
case "m":
|
|
636
|
-
|
|
698
|
+
o = Math.round(r * ae);
|
|
637
699
|
break;
|
|
638
700
|
case "hour":
|
|
639
701
|
case "hours":
|
|
640
702
|
case "hr":
|
|
641
703
|
case "hrs":
|
|
642
704
|
case "h":
|
|
643
|
-
|
|
705
|
+
o = Math.round(r * ie);
|
|
644
706
|
break;
|
|
645
707
|
case "day":
|
|
646
708
|
case "days":
|
|
647
709
|
case "d":
|
|
648
|
-
|
|
710
|
+
o = Math.round(r * L);
|
|
649
711
|
break;
|
|
650
712
|
case "week":
|
|
651
713
|
case "weeks":
|
|
652
714
|
case "w":
|
|
653
|
-
|
|
715
|
+
o = Math.round(r * Me);
|
|
654
716
|
break;
|
|
655
717
|
default:
|
|
656
|
-
|
|
718
|
+
o = Math.round(r * Be);
|
|
657
719
|
break;
|
|
658
720
|
}
|
|
659
|
-
return t[1] === "-" || t[4] === "ago" ? -
|
|
660
|
-
},
|
|
721
|
+
return t[1] === "-" || t[4] === "ago" ? -o : o;
|
|
722
|
+
}, G = (e) => e.toLowerCase().replace(/^application\//, ""), Fe = (e, t) => typeof e == "string" ? t.includes(e) : Array.isArray(e) ? t.some(Set.prototype.has.bind(new Set(e))) : !1, Ye = (e, t, r = {}) => {
|
|
661
723
|
let n;
|
|
662
724
|
try {
|
|
663
|
-
n = JSON.parse(
|
|
725
|
+
n = JSON.parse(P.decode(t));
|
|
664
726
|
} catch {
|
|
665
727
|
}
|
|
666
|
-
if (!
|
|
728
|
+
if (!_(n))
|
|
667
729
|
throw new S("JWT Claims Set must be a top-level JSON object");
|
|
668
|
-
const { typ:
|
|
669
|
-
if (
|
|
730
|
+
const { typ: o } = r;
|
|
731
|
+
if (o && (typeof e.typ != "string" || G(e.typ) !== G(o)))
|
|
670
732
|
throw new h('unexpected "typ" JWT header value', n, "typ", "check_failed");
|
|
671
|
-
const { requiredClaims:
|
|
672
|
-
|
|
673
|
-
for (const
|
|
674
|
-
if (!(
|
|
675
|
-
throw new h(`missing required "${
|
|
733
|
+
const { requiredClaims: a = [], issuer: i, subject: c, audience: s, maxTokenAge: m } = r, b = [...a];
|
|
734
|
+
m !== void 0 && b.push("iat"), s !== void 0 && b.push("aud"), c !== void 0 && b.push("sub"), i !== void 0 && b.push("iss");
|
|
735
|
+
for (const f of new Set(b.reverse()))
|
|
736
|
+
if (!(f in n))
|
|
737
|
+
throw new h(`missing required "${f}" claim`, n, f, "missing");
|
|
676
738
|
if (i && !(Array.isArray(i) ? i : [i]).includes(n.iss))
|
|
677
739
|
throw new h('unexpected "iss" claim value', n, "iss", "check_failed");
|
|
678
740
|
if (c && n.sub !== c)
|
|
679
741
|
throw new h('unexpected "sub" claim value', n, "sub", "check_failed");
|
|
680
|
-
if (s && !
|
|
742
|
+
if (s && !Fe(n.aud, typeof s == "string" ? [s] : s))
|
|
681
743
|
throw new h('unexpected "aud" claim value', n, "aud", "check_failed");
|
|
682
|
-
let
|
|
744
|
+
let l;
|
|
683
745
|
switch (typeof r.clockTolerance) {
|
|
684
746
|
case "string":
|
|
685
|
-
|
|
747
|
+
l = k(r.clockTolerance);
|
|
686
748
|
break;
|
|
687
749
|
case "number":
|
|
688
|
-
|
|
750
|
+
l = r.clockTolerance;
|
|
689
751
|
break;
|
|
690
752
|
case "undefined":
|
|
691
|
-
|
|
753
|
+
l = 0;
|
|
692
754
|
break;
|
|
693
755
|
default:
|
|
694
756
|
throw new TypeError("Invalid clockTolerance option type");
|
|
695
757
|
}
|
|
696
|
-
const { currentDate:
|
|
697
|
-
if ((n.iat !== void 0 ||
|
|
758
|
+
const { currentDate: M } = r, E = Le(M || /* @__PURE__ */ new Date());
|
|
759
|
+
if ((n.iat !== void 0 || m) && typeof n.iat != "number")
|
|
698
760
|
throw new h('"iat" claim must be a number', n, "iat", "invalid");
|
|
699
761
|
if (n.nbf !== void 0) {
|
|
700
762
|
if (typeof n.nbf != "number")
|
|
701
763
|
throw new h('"nbf" claim must be a number', n, "nbf", "invalid");
|
|
702
|
-
if (n.nbf >
|
|
764
|
+
if (n.nbf > E + l)
|
|
703
765
|
throw new h('"nbf" claim timestamp check failed', n, "nbf", "check_failed");
|
|
704
766
|
}
|
|
705
767
|
if (n.exp !== void 0) {
|
|
706
768
|
if (typeof n.exp != "number")
|
|
707
769
|
throw new h('"exp" claim must be a number', n, "exp", "invalid");
|
|
708
|
-
if (n.exp <=
|
|
709
|
-
throw new
|
|
710
|
-
}
|
|
711
|
-
if (
|
|
712
|
-
const
|
|
713
|
-
if (
|
|
714
|
-
throw new
|
|
715
|
-
if (
|
|
770
|
+
if (n.exp <= E - l)
|
|
771
|
+
throw new B('"exp" claim timestamp check failed', n, "exp", "check_failed");
|
|
772
|
+
}
|
|
773
|
+
if (m) {
|
|
774
|
+
const f = E - n.iat, H = typeof m == "number" ? m : k(m);
|
|
775
|
+
if (f - l > H)
|
|
776
|
+
throw new B('"iat" claim timestamp check failed (too far in the past)', n, "iat", "check_failed");
|
|
777
|
+
if (f < 0 - l)
|
|
716
778
|
throw new h('"iat" claim timestamp check failed (it should be in the past)', n, "iat", "check_failed");
|
|
717
779
|
}
|
|
718
780
|
return n;
|
|
719
781
|
};
|
|
720
|
-
async function
|
|
782
|
+
async function ke(e, t, r) {
|
|
721
783
|
var i;
|
|
722
|
-
const n = await
|
|
784
|
+
const n = await $e(e, t, r);
|
|
723
785
|
if ((i = n.protectedHeader.crit) != null && i.includes("b64") && n.protectedHeader.b64 === !1)
|
|
724
786
|
throw new S("JWTs MUST NOT use unencoded payload");
|
|
725
|
-
const
|
|
726
|
-
return typeof t == "function" ? { ...
|
|
787
|
+
const a = { payload: Ye(n.protectedHeader, n.payload, r), protectedHeader: n.protectedHeader };
|
|
788
|
+
return typeof t == "function" ? { ...a, key: n.key } : a;
|
|
727
789
|
}
|
|
728
|
-
const
|
|
729
|
-
function
|
|
790
|
+
const Ge = g;
|
|
791
|
+
function qe(e) {
|
|
730
792
|
if (typeof e != "string")
|
|
731
793
|
throw new S("JWTs must use Compact JWS serialization, JWT must be a string");
|
|
732
794
|
const { 1: t, length: r } = e.split(".");
|
|
@@ -738,134 +800,134 @@ function ke(e) {
|
|
|
738
800
|
throw new S("JWTs must contain a payload");
|
|
739
801
|
let n;
|
|
740
802
|
try {
|
|
741
|
-
n =
|
|
803
|
+
n = Ge(t);
|
|
742
804
|
} catch {
|
|
743
805
|
throw new S("Failed to base64url decode the payload");
|
|
744
806
|
}
|
|
745
|
-
let
|
|
807
|
+
let o;
|
|
746
808
|
try {
|
|
747
|
-
|
|
809
|
+
o = JSON.parse(P.decode(n));
|
|
748
810
|
} catch {
|
|
749
811
|
throw new S("Failed to parse the decoded payload as JSON");
|
|
750
812
|
}
|
|
751
|
-
if (!
|
|
813
|
+
if (!_(o))
|
|
752
814
|
throw new S("Invalid JWT Claims Set");
|
|
753
|
-
return
|
|
815
|
+
return o;
|
|
754
816
|
}
|
|
755
|
-
const
|
|
817
|
+
const ze = async (e) => {
|
|
756
818
|
try {
|
|
757
|
-
const t =
|
|
758
|
-
return await
|
|
759
|
-
issuer:
|
|
819
|
+
const t = W.ALG, n = await Ie(ue, t);
|
|
820
|
+
return await ke(e, n, {
|
|
821
|
+
issuer: W.ISSUER
|
|
760
822
|
});
|
|
761
823
|
} catch {
|
|
762
824
|
return;
|
|
763
825
|
}
|
|
764
|
-
},
|
|
826
|
+
}, ft = (e) => {
|
|
765
827
|
try {
|
|
766
|
-
return
|
|
828
|
+
return qe(e);
|
|
767
829
|
} catch {
|
|
768
830
|
return;
|
|
769
831
|
}
|
|
770
832
|
};
|
|
771
|
-
var
|
|
772
|
-
for (var
|
|
773
|
-
|
|
774
|
-
function
|
|
775
|
-
return (
|
|
776
|
-
}
|
|
777
|
-
var
|
|
778
|
-
function
|
|
779
|
-
if (!
|
|
833
|
+
var u = [];
|
|
834
|
+
for (var U = 0; U < 256; ++U)
|
|
835
|
+
u.push((U + 256).toString(16).slice(1));
|
|
836
|
+
function Xe(e, t = 0) {
|
|
837
|
+
return (u[e[t + 0]] + u[e[t + 1]] + u[e[t + 2]] + u[e[t + 3]] + "-" + u[e[t + 4]] + u[e[t + 5]] + "-" + u[e[t + 6]] + u[e[t + 7]] + "-" + u[e[t + 8]] + u[e[t + 9]] + "-" + u[e[t + 10]] + u[e[t + 11]] + u[e[t + 12]] + u[e[t + 13]] + u[e[t + 14]] + u[e[t + 15]]).toLowerCase();
|
|
838
|
+
}
|
|
839
|
+
var O, Qe = new Uint8Array(16);
|
|
840
|
+
function Ze() {
|
|
841
|
+
if (!O && (O = typeof crypto < "u" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto), !O))
|
|
780
842
|
throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
|
|
781
|
-
return
|
|
843
|
+
return O(Qe);
|
|
782
844
|
}
|
|
783
|
-
var
|
|
784
|
-
const
|
|
785
|
-
randomUUID:
|
|
845
|
+
var je = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto);
|
|
846
|
+
const q = {
|
|
847
|
+
randomUUID: je
|
|
786
848
|
};
|
|
787
|
-
function
|
|
788
|
-
if (
|
|
789
|
-
return
|
|
849
|
+
function z(e, t, r) {
|
|
850
|
+
if (q.randomUUID && !t && !e)
|
|
851
|
+
return q.randomUUID();
|
|
790
852
|
e = e || {};
|
|
791
|
-
var n = e.random || (e.rng ||
|
|
792
|
-
return n[6] = n[6] & 15 | 64, n[8] = n[8] & 63 | 128,
|
|
853
|
+
var n = e.random || (e.rng || Ze)();
|
|
854
|
+
return n[6] = n[6] & 15 | 64, n[8] = n[8] & 63 | 128, Xe(n);
|
|
793
855
|
}
|
|
794
|
-
const
|
|
856
|
+
const X = globalThis.crypto, et = (e) => `${z()}${z()}`.slice(0, e), tt = (e) => btoa(
|
|
795
857
|
[...new Uint8Array(e)].map((t) => String.fromCharCode(t)).join("")
|
|
796
858
|
);
|
|
797
|
-
async function
|
|
798
|
-
if (!
|
|
859
|
+
async function ce(e) {
|
|
860
|
+
if (!X.subtle)
|
|
799
861
|
throw new Error(
|
|
800
862
|
"crypto.subtle is available only in secure contexts (HTTPS)."
|
|
801
863
|
);
|
|
802
|
-
const t = new TextEncoder().encode(e), r = await
|
|
803
|
-
return
|
|
864
|
+
const t = new TextEncoder().encode(e), r = await X.subtle.digest("SHA-256", t);
|
|
865
|
+
return tt(r).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
804
866
|
}
|
|
805
|
-
async function
|
|
867
|
+
async function lt(e) {
|
|
806
868
|
const t = e || 43;
|
|
807
869
|
if (t < 43 || t > 128)
|
|
808
870
|
throw `Expected a length between 43 and 128. Received ${e}.`;
|
|
809
|
-
const r =
|
|
871
|
+
const r = et(t), n = await ce(r);
|
|
810
872
|
return {
|
|
811
873
|
code_verifier: r,
|
|
812
874
|
code_challenge: n
|
|
813
875
|
};
|
|
814
876
|
}
|
|
815
|
-
async function
|
|
816
|
-
return t === await
|
|
877
|
+
async function ht(e, t) {
|
|
878
|
+
return t === await ce(e);
|
|
817
879
|
}
|
|
818
|
-
const
|
|
880
|
+
const rt = /^Bearer (.+)$/i, nt = (e) => {
|
|
819
881
|
if (typeof (e == null ? void 0 : e.authorization) != "string")
|
|
820
882
|
return;
|
|
821
|
-
const t = e.authorization.match(
|
|
883
|
+
const t = e.authorization.match(rt);
|
|
822
884
|
if (t)
|
|
823
885
|
return t[1];
|
|
824
|
-
},
|
|
886
|
+
}, ot = (e, t) => {
|
|
825
887
|
const r = e == null ? void 0 : e.cookie;
|
|
826
888
|
if (typeof r != "string")
|
|
827
889
|
return;
|
|
828
|
-
const n = new RegExp(`auth.${t}=(.+?)(?:;|$)`),
|
|
829
|
-
if (
|
|
830
|
-
return
|
|
831
|
-
},
|
|
832
|
-
const t = e == null ? void 0 : e[
|
|
890
|
+
const n = new RegExp(`auth.${t}=(.+?)(?:;|$)`), o = r.match(n);
|
|
891
|
+
if (o)
|
|
892
|
+
return o[1];
|
|
893
|
+
}, at = (e) => {
|
|
894
|
+
const t = e == null ? void 0 : e[se.ACCESS_TOKEN];
|
|
833
895
|
if (typeof t == "string")
|
|
834
896
|
return t;
|
|
835
|
-
},
|
|
836
|
-
const n =
|
|
837
|
-
return
|
|
838
|
-
},
|
|
839
|
-
var
|
|
840
|
-
const r = await
|
|
841
|
-
if (!r || !Array.isArray((
|
|
897
|
+
}, pt = ({ headers: e, body: t, clientId: r }) => {
|
|
898
|
+
const n = nt(e), o = ot(e, r);
|
|
899
|
+
return at(t) || o || n || "";
|
|
900
|
+
}, mt = async (e, t) => {
|
|
901
|
+
var o;
|
|
902
|
+
const r = await ze(e);
|
|
903
|
+
if (!r || !Array.isArray((o = r.payload) == null ? void 0 : o[W.SCOPES_KEY]))
|
|
842
904
|
return !1;
|
|
843
|
-
const n = r.payload[
|
|
844
|
-
return Array.isArray(t) ? t.every((
|
|
845
|
-
(
|
|
905
|
+
const n = r.payload[W.SCOPES_KEY];
|
|
906
|
+
return Array.isArray(t) ? t.every((a) => n.includes(a)) : Object.keys(t).some(
|
|
907
|
+
(a) => t[a].every((i) => n.includes(i))
|
|
846
908
|
);
|
|
847
|
-
},
|
|
909
|
+
}, it = (e, t) => {
|
|
848
910
|
const r = e == null ? void 0 : e.cookie;
|
|
849
911
|
if (typeof r != "string")
|
|
850
912
|
return;
|
|
851
|
-
const n = new RegExp(`auth.${t}.session=(.+?)(?:;|$)`),
|
|
852
|
-
if (
|
|
853
|
-
return
|
|
854
|
-
},
|
|
913
|
+
const n = new RegExp(`auth.${t}.session=(.+?)(?:;|$)`), o = r.match(n);
|
|
914
|
+
if (o)
|
|
915
|
+
return o[1];
|
|
916
|
+
}, yt = ({ headers: e, clientId: t }) => it(e, t) || "";
|
|
855
917
|
export {
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
918
|
+
dt as API_TYPE,
|
|
919
|
+
ct as AUTH_TYPES,
|
|
920
|
+
se as BODY,
|
|
921
|
+
st as HEADERS,
|
|
922
|
+
W as JWT,
|
|
923
|
+
ue as JWT_PUBLIC_KEY,
|
|
924
|
+
ut as TOKEN_EXPIRATION,
|
|
925
|
+
ft as decodeToken,
|
|
926
|
+
ce as generateCodeChallenge,
|
|
927
|
+
yt as getSession,
|
|
928
|
+
pt as getToken,
|
|
929
|
+
mt as isGranted,
|
|
930
|
+
lt as pkceChallengePair,
|
|
931
|
+
ze as verifyAndExtractToken,
|
|
932
|
+
ht as verifyChallenge
|
|
871
933
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@versini/auth-common",
|
|
3
|
-
"version": "4.1.
|
|
3
|
+
"version": "4.1.3",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Arno Versini",
|
|
6
6
|
"publishConfig": {
|
|
@@ -33,8 +33,8 @@
|
|
|
33
33
|
"test:coverage": "vitest run --coverage"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"jose": "5.
|
|
36
|
+
"jose": "5.9.3",
|
|
37
37
|
"uuid": "10.0.0"
|
|
38
38
|
},
|
|
39
|
-
"gitHead": "
|
|
39
|
+
"gitHead": "40dc7c7a47965743b8f2a7e7e8d1c4c39736bdfd"
|
|
40
40
|
}
|