Skip to content

Commit ad1dad8

Browse files
authored
🛂 fix: Reuse OpenID Auth Tokens with Proxy Setup (danny-avila#8151)
* Fixes danny-avila#8099 in correctly setting up proxy support - fixes the openid Strategy - fixes the openid jwt strategy (jwksRsa fetching in a proxy environment) Signed-off-by: Regli Daniel <[email protected]> * Fixes danny-avila#8099 in correctly setting up proxy support - properly formatted Signed-off-by: Regli Daniel <[email protected]> --------- Signed-off-by: Regli Daniel <[email protected]> Signed-off-by: Regli Daniel <[email protected]> Co-authored-by: schnaker85 <1daniregligmail.com>
1 parent 99ad954 commit ad1dad8

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

api/strategies/openIdJwtStrategy.js

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const { SystemRoles } = require('librechat-data-provider');
2+
const { HttpsProxyAgent } = require('https-proxy-agent');
23
const { Strategy: JwtStrategy, ExtractJwt } = require('passport-jwt');
34
const { updateUser, findUser } = require('~/models');
45
const { logger } = require('~/config');
@@ -13,17 +14,23 @@ const { isEnabled } = require('~/server/utils');
1314
* The strategy extracts the JWT from the Authorization header as a Bearer token.
1415
* The JWT is then verified using the signing key, and the user is retrieved from the database.
1516
*/
16-
const openIdJwtLogin = (openIdConfig) =>
17-
new JwtStrategy(
17+
const openIdJwtLogin = (openIdConfig) => {
18+
let jwksRsaOptions = {
19+
cache: isEnabled(process.env.OPENID_JWKS_URL_CACHE_ENABLED) || true,
20+
cacheMaxAge: process.env.OPENID_JWKS_URL_CACHE_TIME
21+
? eval(process.env.OPENID_JWKS_URL_CACHE_TIME)
22+
: 60000,
23+
jwksUri: openIdConfig.serverMetadata().jwks_uri,
24+
};
25+
26+
if (process.env.PROXY) {
27+
jwksRsaOptions.requestAgent = new HttpsProxyAgent(process.env.PROXY);
28+
}
29+
30+
return new JwtStrategy(
1831
{
1932
jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
20-
secretOrKeyProvider: jwksRsa.passportJwtSecret({
21-
cache: isEnabled(process.env.OPENID_JWKS_URL_CACHE_ENABLED) || true,
22-
cacheMaxAge: process.env.OPENID_JWKS_URL_CACHE_TIME
23-
? eval(process.env.OPENID_JWKS_URL_CACHE_TIME)
24-
: 60000,
25-
jwksUri: openIdConfig.serverMetadata().jwks_uri,
26-
}),
33+
secretOrKeyProvider: jwksRsa.passportJwtSecret(jwksRsaOptions),
2734
},
2835
async (payload, done) => {
2936
try {
@@ -48,5 +55,6 @@ const openIdJwtLogin = (openIdConfig) =>
4855
}
4956
},
5057
);
58+
};
5159

5260
module.exports = openIdJwtLogin;

api/strategies/openidStrategy.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ async function customFetch(url, options) {
4949
logger.info(`[openidStrategy] proxy agent configured: ${process.env.PROXY}`);
5050
fetchOptions = {
5151
...options,
52-
dispatcher: new HttpsProxyAgent(process.env.PROXY),
52+
dispatcher: new undici.ProxyAgent(process.env.PROXY),
5353
};
5454
}
5555

0 commit comments

Comments
 (0)