mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-16 08:20:14 +01:00
* 🧹 chore: Update logger imports to use @librechat/data-schemas across multiple files and remove unused sleep function from queue.js (#9930) * chore: Replace local isEnabled utility with @librechat/api import across multiple files, update test files * chore: Replace local logger import with @librechat/data-schemas logger in countTokens.js and fork.js * chore: Update logs volume path in docker-compose.yml to correct directory * chore: import order of isEnabled in static.js
23 lines
962 B
JavaScript
23 lines
962 B
JavaScript
const cookies = require('cookie');
|
|
const passport = require('passport');
|
|
const { isEnabled } = require('@librechat/api');
|
|
|
|
/**
|
|
* Custom Middleware to handle JWT authentication, with support for OpenID token reuse
|
|
* Switches between JWT and OpenID authentication based on cookies and environment settings
|
|
*/
|
|
const requireJwtAuth = (req, res, next) => {
|
|
// Check if token provider is specified in cookies
|
|
const cookieHeader = req.headers.cookie;
|
|
const tokenProvider = cookieHeader ? cookies.parse(cookieHeader).token_provider : null;
|
|
|
|
// Use OpenID authentication if token provider is OpenID and OPENID_REUSE_TOKENS is enabled
|
|
if (tokenProvider === 'openid' && isEnabled(process.env.OPENID_REUSE_TOKENS)) {
|
|
return passport.authenticate('openidJwt', { session: false })(req, res, next);
|
|
}
|
|
|
|
// Default to standard JWT authentication
|
|
return passport.authenticate('jwt', { session: false })(req, res, next);
|
|
};
|
|
|
|
module.exports = requireJwtAuth;
|