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