@forklaunch/core 0.14.14 → 0.14.16
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/lib/http/index.d.mts +79 -1
- package/lib/http/index.d.ts +79 -1
- package/lib/http/index.js +24 -16
- package/lib/http/index.js.map +1 -1
- package/lib/http/index.mjs +22 -16
- package/lib/http/index.mjs.map +1 -1
- package/package.json +8 -8
package/lib/http/index.mjs
CHANGED
@@ -127,12 +127,26 @@ function isJwtAuthMethod(maybeJwtAuthMethod) {
|
|
127
127
|
}
|
128
128
|
|
129
129
|
// src/http/discriminateAuthMethod.ts
|
130
|
-
var DEFAULT_TTL = 60 * 1e3 * 5;
|
131
|
-
var
|
130
|
+
var DEFAULT_TTL = process.env.JWKS_TTL ? parseInt(process.env.JWKS_TTL) : 60 * 1e3 * 5;
|
131
|
+
var cachedJwks = {
|
132
132
|
value: null,
|
133
133
|
lastUpdated: null,
|
134
134
|
ttl: DEFAULT_TTL
|
135
135
|
};
|
136
|
+
async function getCachedJwks(jwksPublicKeyUrl) {
|
137
|
+
if (cachedJwks.value && cachedJwks.lastUpdated && Date.now() - cachedJwks.lastUpdated.getTime() < cachedJwks.ttl) {
|
138
|
+
return cachedJwks.value;
|
139
|
+
} else {
|
140
|
+
const jwksResponse = await fetch(jwksPublicKeyUrl);
|
141
|
+
const jwks = (await jwksResponse.json()).keys;
|
142
|
+
cachedJwks.value = jwks;
|
143
|
+
cachedJwks.lastUpdated = /* @__PURE__ */ new Date();
|
144
|
+
cachedJwks.ttl = parseInt(
|
145
|
+
jwksResponse.headers.get("cache-control")?.split("=")[1] ?? `${DEFAULT_TTL / 1e3}`
|
146
|
+
) * 1e3;
|
147
|
+
return jwks;
|
148
|
+
}
|
149
|
+
}
|
136
150
|
async function discriminateAuthMethod(auth) {
|
137
151
|
let authMethod;
|
138
152
|
if (isBasicAuthMethod(auth)) {
|
@@ -157,17 +171,7 @@ async function discriminateAuthMethod(auth) {
|
|
157
171
|
} else {
|
158
172
|
let jwks;
|
159
173
|
if ("jwksPublicKeyUrl" in jwt) {
|
160
|
-
|
161
|
-
jwks = memoizedJwks.value;
|
162
|
-
} else {
|
163
|
-
const jwksResponse = await fetch(jwt.jwksPublicKeyUrl);
|
164
|
-
jwks = (await jwksResponse.json()).keys;
|
165
|
-
memoizedJwks.value = jwks;
|
166
|
-
memoizedJwks.lastUpdated = /* @__PURE__ */ new Date();
|
167
|
-
memoizedJwks.ttl = parseInt(
|
168
|
-
jwksResponse.headers.get("cache-control")?.split("=")[1] ?? `${DEFAULT_TTL / 1e3}`
|
169
|
-
) * 1e3;
|
170
|
-
}
|
174
|
+
jwks = await getCachedJwks(jwt.jwksPublicKeyUrl);
|
171
175
|
} else if ("jwksPublicKey" in jwt) {
|
172
176
|
jwks = [jwt.jwksPublicKey];
|
173
177
|
}
|
@@ -177,9 +181,9 @@ async function discriminateAuthMethod(auth) {
|
|
177
181
|
const { payload } = await jwtVerify(token, key);
|
178
182
|
return payload;
|
179
183
|
} catch {
|
180
|
-
|
181
|
-
|
182
|
-
|
184
|
+
cachedJwks.value = null;
|
185
|
+
cachedJwks.lastUpdated = null;
|
186
|
+
cachedJwks.ttl = DEFAULT_TTL;
|
183
187
|
continue;
|
184
188
|
}
|
185
189
|
}
|
@@ -3993,6 +3997,7 @@ export {
|
|
3993
3997
|
OpenTelemetryCollector,
|
3994
3998
|
createHmacToken,
|
3995
3999
|
delete_,
|
4000
|
+
discriminateAuthMethod,
|
3996
4001
|
discriminateBody,
|
3997
4002
|
discriminateResponseBodies,
|
3998
4003
|
enrichExpressLikeSend,
|
@@ -4000,6 +4005,7 @@ export {
|
|
4000
4005
|
generateMcpServer,
|
4001
4006
|
generateOpenApiSpecs,
|
4002
4007
|
get,
|
4008
|
+
getCachedJwks,
|
4003
4009
|
getCodeForStatus,
|
4004
4010
|
head,
|
4005
4011
|
httpRequestsTotalCounter,
|