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