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