@versini/auth-common 4.6.1 → 4.6.2
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 +37 -37
- package/dist/index.js +185 -189
- package/package.json +4 -4
package/dist/index.d.ts
CHANGED
|
@@ -46,35 +46,6 @@ declare const API_TYPE: {
|
|
|
46
46
|
GOOGLE: string;
|
|
47
47
|
};
|
|
48
48
|
|
|
49
|
-
declare const verifyAndExtractToken: (token: string) => Promise<jose.JWTVerifyResult<jose.JWTPayload> | undefined>;
|
|
50
|
-
declare const decodeToken: (token: string) => jose.JWTPayload | undefined;
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Generate a PKCE code challenge from a code verifier.
|
|
54
|
-
*
|
|
55
|
-
* @param code_verifier
|
|
56
|
-
* @returns The base64 url encoded code challenge.
|
|
57
|
-
*/
|
|
58
|
-
declare function generateCodeChallenge(code_verifier: string): Promise<string>;
|
|
59
|
-
/**
|
|
60
|
-
* Generate a PKCE challenge pair.
|
|
61
|
-
*
|
|
62
|
-
* @param length Length of the verifier (between 43-128). Defaults to 43.
|
|
63
|
-
* @returns PKCE challenge pair.
|
|
64
|
-
*/
|
|
65
|
-
declare function pkceChallengePair(length?: number): Promise<{
|
|
66
|
-
code_verifier: string;
|
|
67
|
-
code_challenge: string;
|
|
68
|
-
}>;
|
|
69
|
-
/**
|
|
70
|
-
* Verify that a code_verifier produces the expected code challenge.
|
|
71
|
-
*
|
|
72
|
-
* @param code_verifier
|
|
73
|
-
* @param expectedChallenge The code challenge to verify.
|
|
74
|
-
* @returns True if challenges are equal. False otherwise.
|
|
75
|
-
*/
|
|
76
|
-
declare function verifyChallenge(code_verifier: string, expectedChallenge: string): Promise<boolean>;
|
|
77
|
-
|
|
78
49
|
type BodyLike = Record<string, unknown> & {
|
|
79
50
|
access_token?: string;
|
|
80
51
|
};
|
|
@@ -102,6 +73,19 @@ type GetToken = {
|
|
|
102
73
|
};
|
|
103
74
|
declare const getToken: ({ headers, body, clientId }: GetToken) => string;
|
|
104
75
|
|
|
76
|
+
/**
|
|
77
|
+
* Get a Session Id from a request.
|
|
78
|
+
*
|
|
79
|
+
* @param headers An object containing the request headers, usually `req.headers`.
|
|
80
|
+
* @param clientId The client ID to use.
|
|
81
|
+
*
|
|
82
|
+
*/
|
|
83
|
+
type GetSessionProps = {
|
|
84
|
+
clientId: string;
|
|
85
|
+
headers: HeadersLike;
|
|
86
|
+
};
|
|
87
|
+
declare const getSession: ({ headers, clientId }: GetSessionProps) => string;
|
|
88
|
+
|
|
105
89
|
type ScopesGrants = {
|
|
106
90
|
[key: string]: string[];
|
|
107
91
|
} | string[];
|
|
@@ -177,16 +161,32 @@ declare const isGranted: (token: string, scopes: ScopesGrants) => Promise<boolea
|
|
|
177
161
|
declare const isGrantedSync: (token: string, scopes: ScopesGrants) => boolean;
|
|
178
162
|
|
|
179
163
|
/**
|
|
180
|
-
*
|
|
164
|
+
* Generate a PKCE code challenge from a code verifier.
|
|
181
165
|
*
|
|
182
|
-
* @param
|
|
183
|
-
* @
|
|
166
|
+
* @param code_verifier
|
|
167
|
+
* @returns The base64 url encoded code challenge.
|
|
168
|
+
*/
|
|
169
|
+
declare function generateCodeChallenge(code_verifier: string): Promise<string>;
|
|
170
|
+
/**
|
|
171
|
+
* Generate a PKCE challenge pair.
|
|
184
172
|
*
|
|
173
|
+
* @param length Length of the verifier (between 43-128). Defaults to 43.
|
|
174
|
+
* @returns PKCE challenge pair.
|
|
185
175
|
*/
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
}
|
|
190
|
-
|
|
176
|
+
declare function pkceChallengePair(length?: number): Promise<{
|
|
177
|
+
code_verifier: string;
|
|
178
|
+
code_challenge: string;
|
|
179
|
+
}>;
|
|
180
|
+
/**
|
|
181
|
+
* Verify that a code_verifier produces the expected code challenge.
|
|
182
|
+
*
|
|
183
|
+
* @param code_verifier
|
|
184
|
+
* @param expectedChallenge The code challenge to verify.
|
|
185
|
+
* @returns True if challenges are equal. False otherwise.
|
|
186
|
+
*/
|
|
187
|
+
declare function verifyChallenge(code_verifier: string, expectedChallenge: string): Promise<boolean>;
|
|
188
|
+
|
|
189
|
+
declare const verifyAndExtractToken: (token: string) => Promise<jose.JWTVerifyResult<jose.JWTPayload> | undefined>;
|
|
190
|
+
declare const decodeToken: (token: string) => jose.JWTPayload | undefined;
|
|
191
191
|
|
|
192
192
|
export { API_TYPE, AUTH_TYPES, BODY, type BodyLike, HEADERS, type HeadersLike, JWT, JWT_PUBLIC_KEY, type ScopesGrants, TOKEN_EXPIRATION, decodeToken, generateCodeChallenge, getSession, getToken, isGranted, isGrantedSync, pkceChallengePair, verifyAndExtractToken, verifyChallenge };
|
package/dist/index.js
CHANGED
|
@@ -1,17 +1,13 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
@versini/auth-common v4.6.1
|
|
3
|
-
© 2025 gizmette.com
|
|
4
|
-
*/
|
|
5
1
|
try {
|
|
6
2
|
window.__VERSINI_AUTH_COMMON__ || (window.__VERSINI_AUTH_COMMON__ = {
|
|
7
|
-
version: "4.6.
|
|
8
|
-
buildTime: "
|
|
3
|
+
version: "4.6.2",
|
|
4
|
+
buildTime: "01/23/2026 08:36 PM EST",
|
|
9
5
|
homepage: "https://github.com/aversini/auth-client",
|
|
10
6
|
license: "MIT"
|
|
11
7
|
});
|
|
12
8
|
} catch {
|
|
13
9
|
}
|
|
14
|
-
const
|
|
10
|
+
const ct = {
|
|
15
11
|
ID_TOKEN: "id_token",
|
|
16
12
|
ACCESS_TOKEN: "token",
|
|
17
13
|
ID_AND_ACCESS_TOKEN: "id_token token",
|
|
@@ -20,7 +16,7 @@ const st = {
|
|
|
20
16
|
PASSKEY: "passkey",
|
|
21
17
|
AUTH0: "auth0",
|
|
22
18
|
GOOGLE: "google"
|
|
23
|
-
},
|
|
19
|
+
}, dt = {
|
|
24
20
|
CLIENT_ID: "X-Auth-ClientId",
|
|
25
21
|
AUTH_TYPE: "X-Auth-Type"
|
|
26
22
|
}, oe = {
|
|
@@ -47,18 +43,45 @@ aMwPFOIcJH+rKfFgNcHLcaS5syp7zU1ANwZ+trgR+DifBr8TLVkBynmNeTyhDm2+
|
|
|
47
43
|
l0haqjMk0UoNPPE8iYBWUHQJJE1Dqstj65d6Eh5g64Pao25y4cmYJbKjiblIGEkE
|
|
48
44
|
sjqybA9mARAqh9k/eiIopecWSiffNQTwVQVd2I9ZH3BalhEXHlqFgrjz51kFqg81
|
|
49
45
|
awIDAQAB
|
|
50
|
-
-----END PUBLIC KEY-----`,
|
|
46
|
+
-----END PUBLIC KEY-----`, ut = {
|
|
51
47
|
ACCESS: "5m",
|
|
52
48
|
ID: "90d",
|
|
53
49
|
REFRESH: "90d"
|
|
54
|
-
},
|
|
50
|
+
}, ft = {
|
|
55
51
|
CODE: "code",
|
|
56
52
|
LOGOUT: "logout",
|
|
57
53
|
LOGIN: "login",
|
|
58
54
|
REFRESH: "refresh",
|
|
59
55
|
GOOGLE: "google"
|
|
60
|
-
},
|
|
61
|
-
|
|
56
|
+
}, se = (e, t) => {
|
|
57
|
+
const r = e?.cookie;
|
|
58
|
+
if (typeof r != "string")
|
|
59
|
+
return;
|
|
60
|
+
const n = new RegExp(`auth.${t}.session=(.+?)(?:;|$)`), a = r.match(n);
|
|
61
|
+
if (a)
|
|
62
|
+
return a[1];
|
|
63
|
+
}, lt = ({ headers: e, clientId: t }) => se(e, t) || "", ce = /^Bearer (.+)$/i, de = (e) => {
|
|
64
|
+
if (typeof e?.authorization != "string")
|
|
65
|
+
return;
|
|
66
|
+
const t = e.authorization.match(ce);
|
|
67
|
+
if (t)
|
|
68
|
+
return t[1];
|
|
69
|
+
}, ue = (e, t) => {
|
|
70
|
+
const r = e?.cookie;
|
|
71
|
+
if (typeof r != "string")
|
|
72
|
+
return;
|
|
73
|
+
const n = new RegExp(`auth.${t}=(.+?)(?:;|$)`), a = r.match(n);
|
|
74
|
+
if (a)
|
|
75
|
+
return a[1];
|
|
76
|
+
}, fe = (e) => {
|
|
77
|
+
const t = e?.[oe.ACCESS_TOKEN];
|
|
78
|
+
if (typeof t == "string")
|
|
79
|
+
return t;
|
|
80
|
+
}, pt = ({ headers: e, body: t, clientId: r }) => {
|
|
81
|
+
const n = de(e), a = ue(e, r);
|
|
82
|
+
return fe(t) || a || n || "";
|
|
83
|
+
}, N = new TextEncoder(), v = new TextDecoder();
|
|
84
|
+
function le(...e) {
|
|
62
85
|
const t = e.reduce((a, { length: o }) => a + o, 0), r = new Uint8Array(t);
|
|
63
86
|
let n = 0;
|
|
64
87
|
for (const a of e)
|
|
@@ -83,13 +106,13 @@ function G(e) {
|
|
|
83
106
|
r[n] = t.charCodeAt(n);
|
|
84
107
|
return r;
|
|
85
108
|
}
|
|
86
|
-
function
|
|
109
|
+
function T(e) {
|
|
87
110
|
if (Uint8Array.fromBase64)
|
|
88
|
-
return Uint8Array.fromBase64(typeof e == "string" ? e :
|
|
111
|
+
return Uint8Array.fromBase64(typeof e == "string" ? e : v.decode(e), {
|
|
89
112
|
alphabet: "base64url"
|
|
90
113
|
});
|
|
91
114
|
let t = e;
|
|
92
|
-
t instanceof Uint8Array && (t =
|
|
115
|
+
t instanceof Uint8Array && (t = v.decode(t)), t = t.replace(/-/g, "+").replace(/_/g, "/");
|
|
93
116
|
try {
|
|
94
117
|
return G(t);
|
|
95
118
|
} catch {
|
|
@@ -123,7 +146,7 @@ class M extends A {
|
|
|
123
146
|
super(t, { cause: { claim: n, reason: a, payload: r } }), this.claim = n, this.reason = a, this.payload = r;
|
|
124
147
|
}
|
|
125
148
|
}
|
|
126
|
-
class
|
|
149
|
+
class pe extends A {
|
|
127
150
|
static code = "ERR_JOSE_ALG_NOT_ALLOWED";
|
|
128
151
|
code = "ERR_JOSE_ALG_NOT_ALLOWED";
|
|
129
152
|
}
|
|
@@ -139,7 +162,7 @@ class S extends A {
|
|
|
139
162
|
static code = "ERR_JWT_INVALID";
|
|
140
163
|
code = "ERR_JWT_INVALID";
|
|
141
164
|
}
|
|
142
|
-
class
|
|
165
|
+
class he extends A {
|
|
143
166
|
static code = "ERR_JWS_SIGNATURE_VERIFICATION_FAILED";
|
|
144
167
|
code = "ERR_JWS_SIGNATURE_VERIFICATION_FAILED";
|
|
145
168
|
constructor(t = "signature verification failed", r) {
|
|
@@ -150,7 +173,7 @@ const h = (e, t = "algorithm.name") => new TypeError(`CryptoKey does not support
|
|
|
150
173
|
function x(e) {
|
|
151
174
|
return parseInt(e.name.slice(4), 10);
|
|
152
175
|
}
|
|
153
|
-
function
|
|
176
|
+
function ye(e) {
|
|
154
177
|
switch (e) {
|
|
155
178
|
case "ES256":
|
|
156
179
|
return "P-256";
|
|
@@ -162,11 +185,11 @@ function ue(e) {
|
|
|
162
185
|
throw new Error("unreachable");
|
|
163
186
|
}
|
|
164
187
|
}
|
|
165
|
-
function
|
|
188
|
+
function me(e, t) {
|
|
166
189
|
if (!e.usages.includes(t))
|
|
167
190
|
throw new TypeError(`CryptoKey does not support this operation, its usages must include ${t}.`);
|
|
168
191
|
}
|
|
169
|
-
function
|
|
192
|
+
function Se(e, t, r) {
|
|
170
193
|
switch (t) {
|
|
171
194
|
case "HS256":
|
|
172
195
|
case "HS384":
|
|
@@ -216,7 +239,7 @@ function le(e, t, r) {
|
|
|
216
239
|
case "ES512": {
|
|
217
240
|
if (!b(e.algorithm, "ECDSA"))
|
|
218
241
|
throw h("ECDSA");
|
|
219
|
-
const n =
|
|
242
|
+
const n = ye(t);
|
|
220
243
|
if (e.algorithm.namedCurve !== n)
|
|
221
244
|
throw h(n, "algorithm.namedCurve");
|
|
222
245
|
break;
|
|
@@ -224,7 +247,7 @@ function le(e, t, r) {
|
|
|
224
247
|
default:
|
|
225
248
|
throw new TypeError("CryptoKey does not support this operation");
|
|
226
249
|
}
|
|
227
|
-
|
|
250
|
+
me(e, r);
|
|
228
251
|
}
|
|
229
252
|
function q(e, t, ...r) {
|
|
230
253
|
if (r = r.filter(Boolean), r.length > 2) {
|
|
@@ -233,7 +256,7 @@ function q(e, t, ...r) {
|
|
|
233
256
|
} else r.length === 2 ? e += `one of type ${r[0]} or ${r[1]}.` : e += `of type ${r[0]}.`;
|
|
234
257
|
return t == null ? e += ` Received ${t}` : typeof t == "function" && t.name ? e += ` Received function ${t.name}` : typeof t == "object" && t != null && t.constructor?.name && (e += ` Received an instance of ${t.constructor.name}`), e;
|
|
235
258
|
}
|
|
236
|
-
const
|
|
259
|
+
const Ee = (e, ...t) => q("Key must be ", e, ...t), z = (e, t, ...r) => q(`Key for the ${e} algorithm must be `, t, ...r), X = (e) => {
|
|
237
260
|
if (e?.[Symbol.toStringTag] === "CryptoKey")
|
|
238
261
|
return !0;
|
|
239
262
|
try {
|
|
@@ -242,7 +265,7 @@ const pe = (e, ...t) => q("Key must be ", e, ...t), z = (e, t, ...r) => q(`Key f
|
|
|
242
265
|
return !1;
|
|
243
266
|
}
|
|
244
267
|
}, Q = (e) => e?.[Symbol.toStringTag] === "KeyObject", Z = (e) => X(e) || Q(e);
|
|
245
|
-
function
|
|
268
|
+
function we(...e) {
|
|
246
269
|
const t = e.filter(Boolean);
|
|
247
270
|
if (t.length === 0 || t.length === 1)
|
|
248
271
|
return !0;
|
|
@@ -261,9 +284,9 @@ function he(...e) {
|
|
|
261
284
|
}
|
|
262
285
|
return !0;
|
|
263
286
|
}
|
|
264
|
-
const
|
|
287
|
+
const Ae = (e) => typeof e == "object" && e !== null;
|
|
265
288
|
function P(e) {
|
|
266
|
-
if (!
|
|
289
|
+
if (!Ae(e) || Object.prototype.toString.call(e) !== "[object Object]")
|
|
267
290
|
return !1;
|
|
268
291
|
if (Object.getPrototypeOf(e) === null)
|
|
269
292
|
return !0;
|
|
@@ -272,7 +295,7 @@ function P(e) {
|
|
|
272
295
|
t = Object.getPrototypeOf(t);
|
|
273
296
|
return Object.getPrototypeOf(e) === t;
|
|
274
297
|
}
|
|
275
|
-
function
|
|
298
|
+
function ge(e, t) {
|
|
276
299
|
if (e.startsWith("RS") || e.startsWith("PS")) {
|
|
277
300
|
const { modulusLength: r } = t.algorithm;
|
|
278
301
|
if (typeof r != "number" || r < 2048)
|
|
@@ -286,7 +309,7 @@ const W = (e, t) => {
|
|
|
286
309
|
if (e[r] !== t[r])
|
|
287
310
|
return !1;
|
|
288
311
|
return !0;
|
|
289
|
-
},
|
|
312
|
+
}, be = (e) => ({ data: e, pos: 0 }), R = (e) => {
|
|
290
313
|
const t = e.data[e.pos++];
|
|
291
314
|
if (t & 128) {
|
|
292
315
|
const r = t & 127;
|
|
@@ -302,18 +325,18 @@ const W = (e, t) => {
|
|
|
302
325
|
}, j = (e, t) => {
|
|
303
326
|
const r = e.data.subarray(e.pos, e.pos + t);
|
|
304
327
|
return e.pos += t, r;
|
|
305
|
-
},
|
|
328
|
+
}, Ce = (e) => {
|
|
306
329
|
O(e, 6, "Expected algorithm OID");
|
|
307
330
|
const t = R(e);
|
|
308
331
|
return j(e, t);
|
|
309
332
|
};
|
|
310
|
-
function
|
|
333
|
+
function Ke(e) {
|
|
311
334
|
O(e, 48, "Invalid SPKI structure"), R(e), O(e, 48, "Expected algorithm identifier");
|
|
312
335
|
const t = R(e);
|
|
313
336
|
return { algIdStart: e.pos, algIdLength: t };
|
|
314
337
|
}
|
|
315
|
-
const
|
|
316
|
-
const t =
|
|
338
|
+
const ve = (e) => {
|
|
339
|
+
const t = Ce(e);
|
|
317
340
|
if (W(t, [43, 101, 110]))
|
|
318
341
|
return "X25519";
|
|
319
342
|
if (!W(t, [42, 134, 72, 206, 61, 2, 1]))
|
|
@@ -328,7 +351,7 @@ const Ae = (e) => {
|
|
|
328
351
|
if (W(n, o))
|
|
329
352
|
return a;
|
|
330
353
|
throw new Error("Unsupported named curve");
|
|
331
|
-
},
|
|
354
|
+
}, Te = async (e, t, r, n) => {
|
|
332
355
|
let a, o;
|
|
333
356
|
const i = () => ["verify"], s = () => ["encrypt", "wrapKey"];
|
|
334
357
|
switch (r) {
|
|
@@ -383,15 +406,15 @@ const Ae = (e) => {
|
|
|
383
406
|
throw new E('Invalid or unsupported "alg" (Algorithm) value');
|
|
384
407
|
}
|
|
385
408
|
return crypto.subtle.importKey(e, t, a, n?.extractable ?? !0, o);
|
|
386
|
-
},
|
|
387
|
-
const n =
|
|
409
|
+
}, Pe = (e, t) => G(e.replace(t, "")), _e = (e, t, r) => {
|
|
410
|
+
const n = Pe(e, /(?:-----(?:BEGIN|END) PUBLIC KEY-----|\s)/g);
|
|
388
411
|
let a = r;
|
|
389
412
|
return t?.startsWith?.("ECDH-ES") && (a ||= {}, a.getNamedCurve = (o) => {
|
|
390
|
-
const i =
|
|
391
|
-
return
|
|
392
|
-
}),
|
|
413
|
+
const i = be(o);
|
|
414
|
+
return Ke(i), ve(i);
|
|
415
|
+
}), Te("spki", n, t, a);
|
|
393
416
|
};
|
|
394
|
-
function
|
|
417
|
+
function Ie(e) {
|
|
395
418
|
let t, r;
|
|
396
419
|
switch (e.kty) {
|
|
397
420
|
case "AKP": {
|
|
@@ -476,18 +499,18 @@ function Ke(e) {
|
|
|
476
499
|
}
|
|
477
500
|
return { algorithm: t, keyUsages: r };
|
|
478
501
|
}
|
|
479
|
-
async function
|
|
502
|
+
async function Re(e) {
|
|
480
503
|
if (!e.alg)
|
|
481
504
|
throw new TypeError('"alg" argument is required when "jwk.alg" is not present');
|
|
482
|
-
const { algorithm: t, keyUsages: r } =
|
|
505
|
+
const { algorithm: t, keyUsages: r } = Ie(e), n = { ...e };
|
|
483
506
|
return n.kty !== "AKP" && delete n.alg, delete n.use, crypto.subtle.importKey("jwk", n, t, e.ext ?? !(e.d || e.priv), e.key_ops ?? r);
|
|
484
507
|
}
|
|
485
|
-
async function
|
|
508
|
+
async function Oe(e, t, r) {
|
|
486
509
|
if (e.indexOf("-----BEGIN PUBLIC KEY-----") !== 0)
|
|
487
510
|
throw new TypeError('"spki" must be SPKI formatted string');
|
|
488
|
-
return
|
|
511
|
+
return _e(e, t, r);
|
|
489
512
|
}
|
|
490
|
-
function
|
|
513
|
+
function De(e, t, r, n, a) {
|
|
491
514
|
if (a.crit !== void 0 && n?.crit === void 0)
|
|
492
515
|
throw new e('"crit" (Critical) Header Parameter MUST be integrity protected');
|
|
493
516
|
if (!n || n.crit === void 0)
|
|
@@ -506,22 +529,22 @@ function Pe(e, t, r, n, a) {
|
|
|
506
529
|
}
|
|
507
530
|
return new Set(n.crit);
|
|
508
531
|
}
|
|
509
|
-
function
|
|
532
|
+
function xe(e, t) {
|
|
510
533
|
if (t !== void 0 && (!Array.isArray(t) || t.some((r) => typeof r != "string")))
|
|
511
534
|
throw new TypeError(`"${e}" option must be an array of strings`);
|
|
512
535
|
if (t)
|
|
513
536
|
return new Set(t);
|
|
514
537
|
}
|
|
515
|
-
const L = (e) => P(e) && typeof e.kty == "string",
|
|
538
|
+
const L = (e) => P(e) && typeof e.kty == "string", We = (e) => e.kty !== "oct" && (e.kty === "AKP" && typeof e.priv == "string" || typeof e.d == "string"), He = (e) => e.kty !== "oct" && e.d === void 0 && e.priv === void 0, Je = (e) => e.kty === "oct" && typeof e.k == "string";
|
|
516
539
|
let K;
|
|
517
540
|
const $ = async (e, t, r, n = !1) => {
|
|
518
541
|
K ||= /* @__PURE__ */ new WeakMap();
|
|
519
542
|
let a = K.get(e);
|
|
520
543
|
if (a?.[r])
|
|
521
544
|
return a[r];
|
|
522
|
-
const o = await
|
|
545
|
+
const o = await Re({ ...t, alg: r });
|
|
523
546
|
return n && Object.freeze(e), a ? a[r] = o : K.set(e, { [r]: o }), o;
|
|
524
|
-
},
|
|
547
|
+
}, Le = (e, t) => {
|
|
525
548
|
K ||= /* @__PURE__ */ new WeakMap();
|
|
526
549
|
let r = K.get(e);
|
|
527
550
|
if (r?.[t])
|
|
@@ -618,7 +641,7 @@ const $ = async (e, t, r, n = !1) => {
|
|
|
618
641
|
throw new TypeError("given KeyObject instance cannot be used for this algorithm");
|
|
619
642
|
return r ? r[t] = o : K.set(e, { [t]: o }), o;
|
|
620
643
|
};
|
|
621
|
-
async function
|
|
644
|
+
async function Ue(e, t) {
|
|
622
645
|
if (e instanceof Uint8Array || X(e))
|
|
623
646
|
return e;
|
|
624
647
|
if (Q(e)) {
|
|
@@ -626,7 +649,7 @@ async function xe(e, t) {
|
|
|
626
649
|
return e.export();
|
|
627
650
|
if ("toCryptoKey" in e && typeof e.toCryptoKey == "function")
|
|
628
651
|
try {
|
|
629
|
-
return
|
|
652
|
+
return Le(e, t);
|
|
630
653
|
} catch (n) {
|
|
631
654
|
if (n instanceof TypeError)
|
|
632
655
|
throw n;
|
|
@@ -635,7 +658,7 @@ async function xe(e, t) {
|
|
|
635
658
|
return $(e, r, t);
|
|
636
659
|
}
|
|
637
660
|
if (L(e))
|
|
638
|
-
return e.k ?
|
|
661
|
+
return e.k ? T(e.k) : $(e, e, t, !0);
|
|
639
662
|
throw new Error("unreachable");
|
|
640
663
|
}
|
|
641
664
|
const C = (e) => e?.[Symbol.toStringTag], J = (e, t, r) => {
|
|
@@ -681,10 +704,10 @@ const C = (e) => e?.[Symbol.toStringTag], J = (e, t, r) => {
|
|
|
681
704
|
throw new TypeError(`Invalid key for this operation, its "key_ops" must include "${n}" when present`);
|
|
682
705
|
}
|
|
683
706
|
return !0;
|
|
684
|
-
},
|
|
707
|
+
}, Ne = (e, t, r) => {
|
|
685
708
|
if (!(t instanceof Uint8Array)) {
|
|
686
709
|
if (L(t)) {
|
|
687
|
-
if (
|
|
710
|
+
if (Je(t) && J(e, t, r))
|
|
688
711
|
return;
|
|
689
712
|
throw new TypeError('JSON Web Key for symmetric algorithms must have JWK "kty" (Key Type) equal to "oct" and the JWK "k" (Key Value) present');
|
|
690
713
|
}
|
|
@@ -693,19 +716,19 @@ const C = (e) => e?.[Symbol.toStringTag], J = (e, t, r) => {
|
|
|
693
716
|
if (t.type !== "secret")
|
|
694
717
|
throw new TypeError(`${C(t)} instances for symmetric algorithms must be of type "secret"`);
|
|
695
718
|
}
|
|
696
|
-
},
|
|
719
|
+
}, Me = (e, t, r) => {
|
|
697
720
|
if (L(t))
|
|
698
721
|
switch (r) {
|
|
699
722
|
case "decrypt":
|
|
700
723
|
case "sign":
|
|
701
|
-
if (
|
|
724
|
+
if (We(t) && J(e, t, r))
|
|
702
725
|
return;
|
|
703
|
-
throw new TypeError("JSON Web Key for this operation be a private JWK");
|
|
726
|
+
throw new TypeError("JSON Web Key for this operation must be a private JWK");
|
|
704
727
|
case "encrypt":
|
|
705
728
|
case "verify":
|
|
706
|
-
if (
|
|
729
|
+
if (He(t) && J(e, t, r))
|
|
707
730
|
return;
|
|
708
|
-
throw new TypeError("JSON Web Key for this operation be a public JWK");
|
|
731
|
+
throw new TypeError("JSON Web Key for this operation must be a public JWK");
|
|
709
732
|
}
|
|
710
733
|
if (!Z(t))
|
|
711
734
|
throw new TypeError(z(e, t, "CryptoKey", "KeyObject", "JSON Web Key"));
|
|
@@ -726,20 +749,20 @@ const C = (e) => e?.[Symbol.toStringTag], J = (e, t, r) => {
|
|
|
726
749
|
throw new TypeError(`${C(t)} instances for asymmetric algorithm encryption must be of type "public"`);
|
|
727
750
|
}
|
|
728
751
|
};
|
|
729
|
-
function
|
|
752
|
+
function $e(e, t, r) {
|
|
730
753
|
switch (e.substring(0, 2)) {
|
|
731
754
|
case "A1":
|
|
732
755
|
case "A2":
|
|
733
756
|
case "di":
|
|
734
757
|
case "HS":
|
|
735
758
|
case "PB":
|
|
736
|
-
|
|
759
|
+
Ne(e, t, r);
|
|
737
760
|
break;
|
|
738
761
|
default:
|
|
739
|
-
|
|
762
|
+
Me(e, t, r);
|
|
740
763
|
}
|
|
741
764
|
}
|
|
742
|
-
function
|
|
765
|
+
function ke(e, t) {
|
|
743
766
|
const r = `SHA-${e.slice(-3)}`;
|
|
744
767
|
switch (e) {
|
|
745
768
|
case "HS256":
|
|
@@ -769,25 +792,25 @@ function Le(e, t) {
|
|
|
769
792
|
throw new E(`alg ${e} is not supported either by JOSE or your javascript runtime`);
|
|
770
793
|
}
|
|
771
794
|
}
|
|
772
|
-
async function
|
|
795
|
+
async function Be(e, t, r) {
|
|
773
796
|
if (t instanceof Uint8Array) {
|
|
774
797
|
if (!e.startsWith("HS"))
|
|
775
|
-
throw new TypeError(
|
|
798
|
+
throw new TypeError(Ee(t, "CryptoKey", "KeyObject", "JSON Web Key"));
|
|
776
799
|
return crypto.subtle.importKey("raw", t, { hash: `SHA-${e.slice(-3)}`, name: "HMAC" }, !1, [r]);
|
|
777
800
|
}
|
|
778
|
-
return
|
|
801
|
+
return Se(t, e, r), t;
|
|
779
802
|
}
|
|
780
|
-
async function
|
|
781
|
-
const a = await
|
|
782
|
-
|
|
783
|
-
const o =
|
|
803
|
+
async function Ye(e, t, r, n) {
|
|
804
|
+
const a = await Be(e, t, "verify");
|
|
805
|
+
ge(e, a);
|
|
806
|
+
const o = ke(e, a.algorithm);
|
|
784
807
|
try {
|
|
785
808
|
return await crypto.subtle.verify(o, a, r, n);
|
|
786
809
|
} catch {
|
|
787
810
|
return !1;
|
|
788
811
|
}
|
|
789
812
|
}
|
|
790
|
-
async function
|
|
813
|
+
async function Fe(e, t, r) {
|
|
791
814
|
if (!P(e))
|
|
792
815
|
throw new d("Flattened JWS must be an object");
|
|
793
816
|
if (e.protected === void 0 && e.header === void 0)
|
|
@@ -803,47 +826,47 @@ async function Me(e, t, r) {
|
|
|
803
826
|
let n = {};
|
|
804
827
|
if (e.protected)
|
|
805
828
|
try {
|
|
806
|
-
const ae =
|
|
807
|
-
n = JSON.parse(
|
|
829
|
+
const ae = T(e.protected);
|
|
830
|
+
n = JSON.parse(v.decode(ae));
|
|
808
831
|
} catch {
|
|
809
832
|
throw new d("JWS Protected Header is invalid");
|
|
810
833
|
}
|
|
811
|
-
if (!
|
|
834
|
+
if (!we(n, e.header))
|
|
812
835
|
throw new d("JWS Protected and JWS Unprotected Header Parameter names must be disjoint");
|
|
813
836
|
const a = {
|
|
814
837
|
...n,
|
|
815
838
|
...e.header
|
|
816
|
-
}, o =
|
|
839
|
+
}, o = De(d, /* @__PURE__ */ new Map([["b64", !0]]), r?.crit, n, a);
|
|
817
840
|
let i = !0;
|
|
818
841
|
if (o.has("b64") && (i = n.b64, typeof i != "boolean"))
|
|
819
842
|
throw new d('The "b64" (base64url-encode payload) Header Parameter must be a boolean');
|
|
820
843
|
const { alg: s } = a;
|
|
821
844
|
if (typeof s != "string" || !s)
|
|
822
845
|
throw new d('JWS "alg" (Algorithm) Header Parameter missing or invalid');
|
|
823
|
-
const u = r &&
|
|
846
|
+
const u = r && xe("algorithms", r.algorithms);
|
|
824
847
|
if (u && !u.has(s))
|
|
825
|
-
throw new
|
|
848
|
+
throw new pe('"alg" (Algorithm) Header Parameter value not allowed');
|
|
826
849
|
if (i) {
|
|
827
850
|
if (typeof e.payload != "string")
|
|
828
851
|
throw new d("JWS Payload must be a string");
|
|
829
852
|
} else if (typeof e.payload != "string" && !(e.payload instanceof Uint8Array))
|
|
830
853
|
throw new d("JWS Payload must be a string or an Uint8Array instance");
|
|
831
854
|
let m = !1;
|
|
832
|
-
typeof t == "function" && (t = await t(n, e), m = !0),
|
|
833
|
-
const w =
|
|
855
|
+
typeof t == "function" && (t = await t(n, e), m = !0), $e(s, t, "verify");
|
|
856
|
+
const w = le(e.protected !== void 0 ? D(e.protected) : new Uint8Array(), D("."), typeof e.payload == "string" ? i ? D(e.payload) : N.encode(e.payload) : e.payload);
|
|
834
857
|
let l;
|
|
835
858
|
try {
|
|
836
|
-
l =
|
|
859
|
+
l = T(e.signature);
|
|
837
860
|
} catch {
|
|
838
861
|
throw new d("Failed to base64url decode the signature");
|
|
839
862
|
}
|
|
840
|
-
const _ = await
|
|
841
|
-
if (!await
|
|
842
|
-
throw new
|
|
863
|
+
const _ = await Ue(t, s);
|
|
864
|
+
if (!await Ye(s, _, l, w))
|
|
865
|
+
throw new he();
|
|
843
866
|
let f;
|
|
844
867
|
if (i)
|
|
845
868
|
try {
|
|
846
|
-
f =
|
|
869
|
+
f = T(e.payload);
|
|
847
870
|
} catch {
|
|
848
871
|
throw new d("Failed to base64url decode the payload");
|
|
849
872
|
}
|
|
@@ -851,18 +874,18 @@ async function Me(e, t, r) {
|
|
|
851
874
|
const g = { payload: f };
|
|
852
875
|
return e.protected !== void 0 && (g.protectedHeader = n), e.header !== void 0 && (g.unprotectedHeader = e.header), m ? { ...g, key: _ } : g;
|
|
853
876
|
}
|
|
854
|
-
async function
|
|
855
|
-
if (e instanceof Uint8Array && (e =
|
|
877
|
+
async function Ve(e, t, r) {
|
|
878
|
+
if (e instanceof Uint8Array && (e = v.decode(e)), typeof e != "string")
|
|
856
879
|
throw new d("Compact JWS must be a string or Uint8Array");
|
|
857
880
|
const { 0: n, 1: a, 2: o, length: i } = e.split(".");
|
|
858
881
|
if (i !== 3)
|
|
859
882
|
throw new d("Invalid Compact JWS");
|
|
860
|
-
const s = await
|
|
883
|
+
const s = await Fe({ payload: a, protected: n, signature: o }, t, r), u = { payload: s.payload, protectedHeader: s.protectedHeader };
|
|
861
884
|
return typeof t == "function" ? { ...u, key: s.key } : u;
|
|
862
885
|
}
|
|
863
|
-
const
|
|
886
|
+
const Ge = (e) => Math.floor(e.getTime() / 1e3), ee = 60, te = ee * 60, U = te * 24, qe = U * 7, ze = U * 365.25, Xe = /^(\+|\-)? ?(\d+|\d+\.\d+) ?(seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)(?: (ago|from now))?$/i;
|
|
864
887
|
function k(e) {
|
|
865
|
-
const t =
|
|
888
|
+
const t = Xe.exec(e);
|
|
866
889
|
if (!t || t[4] && t[1])
|
|
867
890
|
throw new TypeError("Invalid time period format");
|
|
868
891
|
const r = parseFloat(t[2]), n = t[3].toLowerCase();
|
|
@@ -897,19 +920,19 @@ function k(e) {
|
|
|
897
920
|
case "week":
|
|
898
921
|
case "weeks":
|
|
899
922
|
case "w":
|
|
900
|
-
a = Math.round(r *
|
|
923
|
+
a = Math.round(r * qe);
|
|
901
924
|
break;
|
|
902
925
|
default:
|
|
903
|
-
a = Math.round(r *
|
|
926
|
+
a = Math.round(r * ze);
|
|
904
927
|
break;
|
|
905
928
|
}
|
|
906
929
|
return t[1] === "-" || t[4] === "ago" ? -a : a;
|
|
907
930
|
}
|
|
908
|
-
const B = (e) => e.includes("/") ? e.toLowerCase() : `application/${e.toLowerCase()}`,
|
|
909
|
-
function
|
|
931
|
+
const B = (e) => e.includes("/") ? e.toLowerCase() : `application/${e.toLowerCase()}`, Qe = (e, t) => typeof e == "string" ? t.includes(e) : Array.isArray(e) ? t.some(Set.prototype.has.bind(new Set(e))) : !1;
|
|
932
|
+
function Ze(e, t, r = {}) {
|
|
910
933
|
let n;
|
|
911
934
|
try {
|
|
912
|
-
n = JSON.parse(
|
|
935
|
+
n = JSON.parse(v.decode(t));
|
|
913
936
|
} catch {
|
|
914
937
|
}
|
|
915
938
|
if (!P(n))
|
|
@@ -926,7 +949,7 @@ function Ge(e, t, r = {}) {
|
|
|
926
949
|
throw new p('unexpected "iss" claim value', n, "iss", "check_failed");
|
|
927
950
|
if (s && n.sub !== s)
|
|
928
951
|
throw new p('unexpected "sub" claim value', n, "sub", "check_failed");
|
|
929
|
-
if (u && !
|
|
952
|
+
if (u && !Qe(n.aud, typeof u == "string" ? [u] : u))
|
|
930
953
|
throw new p('unexpected "aud" claim value', n, "aud", "check_failed");
|
|
931
954
|
let l;
|
|
932
955
|
switch (typeof r.clockTolerance) {
|
|
@@ -942,7 +965,7 @@ function Ge(e, t, r = {}) {
|
|
|
942
965
|
default:
|
|
943
966
|
throw new TypeError("Invalid clockTolerance option type");
|
|
944
967
|
}
|
|
945
|
-
const { currentDate: _ } = r, I =
|
|
968
|
+
const { currentDate: _ } = r, I = Ge(_ || /* @__PURE__ */ new Date());
|
|
946
969
|
if ((n.iat !== void 0 || m) && typeof n.iat != "number")
|
|
947
970
|
throw new p('"iat" claim must be a number', n, "iat", "invalid");
|
|
948
971
|
if (n.nbf !== void 0) {
|
|
@@ -966,11 +989,11 @@ function Ge(e, t, r = {}) {
|
|
|
966
989
|
}
|
|
967
990
|
return n;
|
|
968
991
|
}
|
|
969
|
-
async function
|
|
970
|
-
const n = await
|
|
992
|
+
async function je(e, t, r) {
|
|
993
|
+
const n = await Ve(e, t, r);
|
|
971
994
|
if (n.protectedHeader.crit?.includes("b64") && n.protectedHeader.b64 === !1)
|
|
972
995
|
throw new S("JWTs MUST NOT use unencoded payload");
|
|
973
|
-
const o = { payload:
|
|
996
|
+
const o = { payload: Ze(n.protectedHeader, n.payload, r), protectedHeader: n.protectedHeader };
|
|
974
997
|
return typeof t == "function" ? { ...o, key: n.key } : o;
|
|
975
998
|
}
|
|
976
999
|
function re(e) {
|
|
@@ -985,13 +1008,13 @@ function re(e) {
|
|
|
985
1008
|
throw new S("JWTs must contain a payload");
|
|
986
1009
|
let n;
|
|
987
1010
|
try {
|
|
988
|
-
n =
|
|
1011
|
+
n = T(t);
|
|
989
1012
|
} catch {
|
|
990
1013
|
throw new S("Failed to base64url decode the payload");
|
|
991
1014
|
}
|
|
992
1015
|
let a;
|
|
993
1016
|
try {
|
|
994
|
-
a = JSON.parse(
|
|
1017
|
+
a = JSON.parse(v.decode(n));
|
|
995
1018
|
} catch {
|
|
996
1019
|
throw new S("Failed to parse the decoded payload as JSON");
|
|
997
1020
|
}
|
|
@@ -999,48 +1022,81 @@ function re(e) {
|
|
|
999
1022
|
throw new S("Invalid JWT Claims Set");
|
|
1000
1023
|
return a;
|
|
1001
1024
|
}
|
|
1002
|
-
const
|
|
1025
|
+
const et = async (e) => {
|
|
1003
1026
|
try {
|
|
1004
|
-
const t = y.ALG, n = await
|
|
1005
|
-
return await
|
|
1027
|
+
const t = y.ALG, n = await Oe(ie, t);
|
|
1028
|
+
return await je(e, n, {
|
|
1006
1029
|
issuer: y.ISSUER
|
|
1007
1030
|
});
|
|
1008
1031
|
} catch {
|
|
1009
1032
|
return;
|
|
1010
1033
|
}
|
|
1011
|
-
},
|
|
1034
|
+
}, ht = (e) => {
|
|
1012
1035
|
try {
|
|
1013
1036
|
return re(e);
|
|
1014
1037
|
} catch {
|
|
1015
1038
|
return;
|
|
1016
1039
|
}
|
|
1040
|
+
}, yt = async (e, t) => {
|
|
1041
|
+
const r = await et(e);
|
|
1042
|
+
if (!r || !r.payload)
|
|
1043
|
+
return !1;
|
|
1044
|
+
let n = [];
|
|
1045
|
+
if (Array.isArray(r.payload[y.SCOPES_KEY]))
|
|
1046
|
+
n = r.payload[y.SCOPES_KEY];
|
|
1047
|
+
else if (typeof r.payload[y.SCOPE_KEY] == "string")
|
|
1048
|
+
n = r.payload[y.SCOPE_KEY].split(" ").filter((o) => o.trim() !== "");
|
|
1049
|
+
else
|
|
1050
|
+
return !1;
|
|
1051
|
+
return Array.isArray(t) ? t.every((a) => n.includes(a)) : Object.keys(t).some(
|
|
1052
|
+
(a) => t[a].every((o) => n.includes(o))
|
|
1053
|
+
);
|
|
1054
|
+
}, mt = (e, t) => {
|
|
1055
|
+
try {
|
|
1056
|
+
const r = re(e);
|
|
1057
|
+
if (!r)
|
|
1058
|
+
return !1;
|
|
1059
|
+
let n = [];
|
|
1060
|
+
if (Array.isArray(r[y.SCOPES_KEY]))
|
|
1061
|
+
n = r[y.SCOPES_KEY];
|
|
1062
|
+
else if (typeof r[y.SCOPE_KEY] == "string")
|
|
1063
|
+
n = r[y.SCOPE_KEY].split(" ").filter((o) => o.trim() !== "");
|
|
1064
|
+
else
|
|
1065
|
+
return !1;
|
|
1066
|
+
return Array.isArray(t) ? t.every((a) => n.includes(a)) : Object.keys(t).some(
|
|
1067
|
+
(a) => t[a].every((o) => n.includes(o))
|
|
1068
|
+
);
|
|
1069
|
+
} catch {
|
|
1070
|
+
return !1;
|
|
1071
|
+
}
|
|
1017
1072
|
}, c = [];
|
|
1018
1073
|
for (let e = 0; e < 256; ++e)
|
|
1019
1074
|
c.push((e + 256).toString(16).slice(1));
|
|
1020
|
-
function
|
|
1075
|
+
function tt(e, t = 0) {
|
|
1021
1076
|
return (c[e[t + 0]] + c[e[t + 1]] + c[e[t + 2]] + c[e[t + 3]] + "-" + c[e[t + 4]] + c[e[t + 5]] + "-" + c[e[t + 6]] + c[e[t + 7]] + "-" + c[e[t + 8]] + c[e[t + 9]] + "-" + c[e[t + 10]] + c[e[t + 11]] + c[e[t + 12]] + c[e[t + 13]] + c[e[t + 14]] + c[e[t + 15]]).toLowerCase();
|
|
1022
1077
|
}
|
|
1023
1078
|
let H;
|
|
1024
|
-
const
|
|
1025
|
-
function
|
|
1079
|
+
const rt = new Uint8Array(16);
|
|
1080
|
+
function nt() {
|
|
1026
1081
|
if (!H) {
|
|
1027
1082
|
if (typeof crypto > "u" || !crypto.getRandomValues)
|
|
1028
1083
|
throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
|
|
1029
1084
|
H = crypto.getRandomValues.bind(crypto);
|
|
1030
1085
|
}
|
|
1031
|
-
return H(
|
|
1086
|
+
return H(rt);
|
|
1032
1087
|
}
|
|
1033
|
-
const
|
|
1034
|
-
function
|
|
1035
|
-
if (Y.randomUUID && !e)
|
|
1036
|
-
return Y.randomUUID();
|
|
1088
|
+
const at = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto), Y = { randomUUID: at };
|
|
1089
|
+
function ot(e, t, r) {
|
|
1037
1090
|
e = e || {};
|
|
1038
|
-
const n = e.random ?? e.rng?.() ??
|
|
1091
|
+
const n = e.random ?? e.rng?.() ?? nt();
|
|
1039
1092
|
if (n.length < 16)
|
|
1040
1093
|
throw new Error("Random bytes length must be >= 16");
|
|
1041
|
-
return n[6] = n[6] & 15 | 64, n[8] = n[8] & 63 | 128,
|
|
1094
|
+
return n[6] = n[6] & 15 | 64, n[8] = n[8] & 63 | 128, tt(n);
|
|
1095
|
+
}
|
|
1096
|
+
function F(e, t, r) {
|
|
1097
|
+
return Y.randomUUID && !e ? Y.randomUUID() : ot(e);
|
|
1042
1098
|
}
|
|
1043
|
-
const V = globalThis.crypto,
|
|
1099
|
+
const V = globalThis.crypto, it = (e) => `${F()}${F()}`.slice(0, e), st = (e) => btoa(
|
|
1044
1100
|
[...new Uint8Array(e)].map((t) => String.fromCharCode(t)).join("")
|
|
1045
1101
|
);
|
|
1046
1102
|
async function ne(e) {
|
|
@@ -1049,96 +1105,36 @@ async function ne(e) {
|
|
|
1049
1105
|
"crypto.subtle is available only in secure contexts (HTTPS)."
|
|
1050
1106
|
);
|
|
1051
1107
|
const t = new TextEncoder().encode(e), r = await V.subtle.digest("SHA-256", t);
|
|
1052
|
-
return
|
|
1108
|
+
return st(r).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
1053
1109
|
}
|
|
1054
|
-
async function
|
|
1110
|
+
async function St(e) {
|
|
1055
1111
|
const t = e || 43;
|
|
1056
1112
|
if (t < 43 || t > 128)
|
|
1057
1113
|
throw `Expected a length between 43 and 128. Received ${e}.`;
|
|
1058
|
-
const r =
|
|
1114
|
+
const r = it(t), n = await ne(r);
|
|
1059
1115
|
return {
|
|
1060
1116
|
code_verifier: r,
|
|
1061
1117
|
code_challenge: n
|
|
1062
1118
|
};
|
|
1063
1119
|
}
|
|
1064
|
-
async function
|
|
1120
|
+
async function Et(e, t) {
|
|
1065
1121
|
return t === await ne(e);
|
|
1066
1122
|
}
|
|
1067
|
-
const rt = /^Bearer (.+)$/i, nt = (e) => {
|
|
1068
|
-
if (typeof e?.authorization != "string")
|
|
1069
|
-
return;
|
|
1070
|
-
const t = e.authorization.match(rt);
|
|
1071
|
-
if (t)
|
|
1072
|
-
return t[1];
|
|
1073
|
-
}, at = (e, t) => {
|
|
1074
|
-
const r = e?.cookie;
|
|
1075
|
-
if (typeof r != "string")
|
|
1076
|
-
return;
|
|
1077
|
-
const n = new RegExp(`auth.${t}=(.+?)(?:;|$)`), a = r.match(n);
|
|
1078
|
-
if (a)
|
|
1079
|
-
return a[1];
|
|
1080
|
-
}, ot = (e) => {
|
|
1081
|
-
const t = e?.[oe.ACCESS_TOKEN];
|
|
1082
|
-
if (typeof t == "string")
|
|
1083
|
-
return t;
|
|
1084
|
-
}, ht = ({ headers: e, body: t, clientId: r }) => {
|
|
1085
|
-
const n = nt(e), a = at(e, r);
|
|
1086
|
-
return ot(t) || a || n || "";
|
|
1087
|
-
}, yt = async (e, t) => {
|
|
1088
|
-
const r = await ze(e);
|
|
1089
|
-
if (!r || !r.payload)
|
|
1090
|
-
return !1;
|
|
1091
|
-
let n = [];
|
|
1092
|
-
if (Array.isArray(r.payload[y.SCOPES_KEY]))
|
|
1093
|
-
n = r.payload[y.SCOPES_KEY];
|
|
1094
|
-
else if (typeof r.payload[y.SCOPE_KEY] == "string")
|
|
1095
|
-
n = r.payload[y.SCOPE_KEY].split(" ").filter((o) => o.trim() !== "");
|
|
1096
|
-
else
|
|
1097
|
-
return !1;
|
|
1098
|
-
return Array.isArray(t) ? t.every((a) => n.includes(a)) : Object.keys(t).some(
|
|
1099
|
-
(a) => t[a].every((o) => n.includes(o))
|
|
1100
|
-
);
|
|
1101
|
-
}, mt = (e, t) => {
|
|
1102
|
-
try {
|
|
1103
|
-
const r = re(e);
|
|
1104
|
-
if (!r)
|
|
1105
|
-
return !1;
|
|
1106
|
-
let n = [];
|
|
1107
|
-
if (Array.isArray(r[y.SCOPES_KEY]))
|
|
1108
|
-
n = r[y.SCOPES_KEY];
|
|
1109
|
-
else if (typeof r[y.SCOPE_KEY] == "string")
|
|
1110
|
-
n = r[y.SCOPE_KEY].split(" ").filter((o) => o.trim() !== "");
|
|
1111
|
-
else
|
|
1112
|
-
return !1;
|
|
1113
|
-
return Array.isArray(t) ? t.every((a) => n.includes(a)) : Object.keys(t).some(
|
|
1114
|
-
(a) => t[a].every((o) => n.includes(o))
|
|
1115
|
-
);
|
|
1116
|
-
} catch {
|
|
1117
|
-
return !1;
|
|
1118
|
-
}
|
|
1119
|
-
}, it = (e, t) => {
|
|
1120
|
-
const r = e?.cookie;
|
|
1121
|
-
if (typeof r != "string")
|
|
1122
|
-
return;
|
|
1123
|
-
const n = new RegExp(`auth.${t}.session=(.+?)(?:;|$)`), a = r.match(n);
|
|
1124
|
-
if (a)
|
|
1125
|
-
return a[1];
|
|
1126
|
-
}, St = ({ headers: e, clientId: t }) => it(e, t) || "";
|
|
1127
1123
|
export {
|
|
1128
|
-
|
|
1129
|
-
|
|
1124
|
+
ft as API_TYPE,
|
|
1125
|
+
ct as AUTH_TYPES,
|
|
1130
1126
|
oe as BODY,
|
|
1131
|
-
|
|
1127
|
+
dt as HEADERS,
|
|
1132
1128
|
y as JWT,
|
|
1133
1129
|
ie as JWT_PUBLIC_KEY,
|
|
1134
|
-
|
|
1135
|
-
|
|
1130
|
+
ut as TOKEN_EXPIRATION,
|
|
1131
|
+
ht as decodeToken,
|
|
1136
1132
|
ne as generateCodeChallenge,
|
|
1137
|
-
|
|
1138
|
-
|
|
1133
|
+
lt as getSession,
|
|
1134
|
+
pt as getToken,
|
|
1139
1135
|
yt as isGranted,
|
|
1140
1136
|
mt as isGrantedSync,
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1137
|
+
St as pkceChallengePair,
|
|
1138
|
+
et as verifyAndExtractToken,
|
|
1139
|
+
Et as verifyChallenge
|
|
1144
1140
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@versini/auth-common",
|
|
3
|
-
"version": "4.6.
|
|
3
|
+
"version": "4.6.2",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Arno Versini",
|
|
6
6
|
"publishConfig": {
|
|
@@ -34,8 +34,8 @@
|
|
|
34
34
|
"test:coverage": "vitest run --coverage"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"jose": "6.1.
|
|
38
|
-
"uuid": "
|
|
37
|
+
"jose": "6.1.3",
|
|
38
|
+
"uuid": "13.0.0"
|
|
39
39
|
},
|
|
40
|
-
"gitHead": "
|
|
40
|
+
"gitHead": "78e93181feacb67a6de1628448ae7a22fddfdf34"
|
|
41
41
|
}
|