mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-16 16:30:15 +01:00
chore: remove jose as Bun now supports JWT 🍞 (#1167)
* chore: remove jose as Bun now supports JWT * chore: npm audit
This commit is contained in:
parent
9ca84edb9a
commit
5d95433c83
8 changed files with 46 additions and 68 deletions
|
|
@ -41,7 +41,6 @@
|
||||||
"handlebars": "^4.7.7",
|
"handlebars": "^4.7.7",
|
||||||
"html": "^1.0.0",
|
"html": "^1.0.0",
|
||||||
"ioredis": "^5.3.2",
|
"ioredis": "^5.3.2",
|
||||||
"jose": "^4.15.2",
|
|
||||||
"js-yaml": "^4.1.0",
|
"js-yaml": "^4.1.0",
|
||||||
"jsonwebtoken": "^9.0.0",
|
"jsonwebtoken": "^9.0.0",
|
||||||
"keyv": "^4.5.4",
|
"keyv": "^4.5.4",
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,13 @@
|
||||||
|
const crypto = require('crypto');
|
||||||
|
const cookies = require('cookie');
|
||||||
|
const jwt = require('jsonwebtoken');
|
||||||
|
const { Session, User } = require('../../models');
|
||||||
const {
|
const {
|
||||||
registerUser,
|
registerUser,
|
||||||
requestPasswordReset,
|
requestPasswordReset,
|
||||||
resetPassword,
|
resetPassword,
|
||||||
setAuthTokens,
|
setAuthTokens,
|
||||||
} = require('../services/AuthService');
|
} = require('../services/AuthService');
|
||||||
const jose = require('jose');
|
|
||||||
const jwt = require('jsonwebtoken');
|
|
||||||
const Session = require('../../models/Session');
|
|
||||||
const User = require('../../models/User');
|
|
||||||
const crypto = require('crypto');
|
|
||||||
const cookies = require('cookie');
|
|
||||||
|
|
||||||
const registrationController = async (req, res) => {
|
const registrationController = async (req, res) => {
|
||||||
try {
|
try {
|
||||||
|
|
@ -78,12 +76,7 @@ const refreshController = async (req, res) => {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let payload;
|
let payload;
|
||||||
if (typeof Bun !== 'undefined') {
|
payload = jwt.verify(refreshToken, process.env.JWT_REFRESH_SECRET);
|
||||||
const secret = new TextEncoder().encode(process.env.JWT_REFRESH_SECRET);
|
|
||||||
({ payload } = await jose.jwtVerify(refreshToken, secret));
|
|
||||||
} else {
|
|
||||||
payload = jwt.verify(refreshToken, process.env.JWT_REFRESH_SECRET);
|
|
||||||
}
|
|
||||||
const userId = payload.id;
|
const userId = payload.id;
|
||||||
const user = await User.findOne({ _id: userId });
|
const user = await User.findOne({ _id: userId });
|
||||||
if (!user) {
|
if (!user) {
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ const { PORT, HOST, ALLOW_SOCIAL_LOGIN } = process.env ?? {};
|
||||||
const port = Number(PORT) || 3080;
|
const port = Number(PORT) || 3080;
|
||||||
const host = HOST || 'localhost';
|
const host = HOST || 'localhost';
|
||||||
const projectPath = path.join(__dirname, '..', '..', 'client');
|
const projectPath = path.join(__dirname, '..', '..', 'client');
|
||||||
const { jwtLogin, joseLogin, passportLogin } = require('../strategies');
|
const { jwtLogin, passportLogin } = require('../strategies');
|
||||||
|
|
||||||
const startServer = async () => {
|
const startServer = async () => {
|
||||||
await connectDb();
|
await connectDb();
|
||||||
|
|
@ -39,11 +39,7 @@ const startServer = async () => {
|
||||||
|
|
||||||
// OAUTH
|
// OAUTH
|
||||||
app.use(passport.initialize());
|
app.use(passport.initialize());
|
||||||
if (typeof Bun !== 'undefined') {
|
passport.use(await jwtLogin());
|
||||||
passport.use('jwt', await joseLogin());
|
|
||||||
} else {
|
|
||||||
passport.use(await jwtLogin());
|
|
||||||
}
|
|
||||||
passport.use(passportLogin());
|
passport.use(passportLogin());
|
||||||
|
|
||||||
if (ALLOW_SOCIAL_LOGIN?.toLowerCase() === 'true') {
|
if (ALLOW_SOCIAL_LOGIN?.toLowerCase() === 'true') {
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
const jose = require('jose');
|
|
||||||
const jwt = require('jsonwebtoken');
|
const jwt = require('jsonwebtoken');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -21,15 +20,6 @@ const jwt = require('jsonwebtoken');
|
||||||
* });
|
* });
|
||||||
*/
|
*/
|
||||||
async function signPayload({ payload, secret, expirationTime }) {
|
async function signPayload({ payload, secret, expirationTime }) {
|
||||||
if (typeof Bun !== 'undefined') {
|
|
||||||
// this code will only run when the file is run with Bun
|
|
||||||
const encodedSecret = new TextEncoder().encode(secret);
|
|
||||||
return await new jose.SignJWT(payload)
|
|
||||||
.setProtectedHeader({ alg: 'HS256' })
|
|
||||||
.setExpirationTime(expirationTime + 's')
|
|
||||||
.sign(encodedSecret);
|
|
||||||
}
|
|
||||||
|
|
||||||
return jwt.sign(payload, secret, { expiresIn: expirationTime });
|
return jwt.sign(payload, secret, { expiresIn: expirationTime });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,17 +2,15 @@ const passportLogin = require('./localStrategy');
|
||||||
const googleLogin = require('./googleStrategy');
|
const googleLogin = require('./googleStrategy');
|
||||||
const githubLogin = require('./githubStrategy');
|
const githubLogin = require('./githubStrategy');
|
||||||
const discordLogin = require('./discordStrategy');
|
const discordLogin = require('./discordStrategy');
|
||||||
const joseLogin = require('./joseStrategy');
|
|
||||||
const jwtLogin = require('./jwtStrategy');
|
|
||||||
const facebookLogin = require('./facebookStrategy');
|
const facebookLogin = require('./facebookStrategy');
|
||||||
const setupOpenId = require('./openidStrategy');
|
const setupOpenId = require('./openidStrategy');
|
||||||
|
const jwtLogin = require('./jwtStrategy');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
passportLogin,
|
passportLogin,
|
||||||
googleLogin,
|
googleLogin,
|
||||||
githubLogin,
|
githubLogin,
|
||||||
discordLogin,
|
discordLogin,
|
||||||
joseLogin,
|
|
||||||
jwtLogin,
|
jwtLogin,
|
||||||
facebookLogin,
|
facebookLogin,
|
||||||
setupOpenId,
|
setupOpenId,
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,6 @@
|
||||||
const jose = require('jose');
|
/* const jose = require('jose');
|
||||||
|
* No longer using this strategy as Bun now supports JWTs natively.
|
||||||
|
|
||||||
const passportCustom = require('passport-custom');
|
const passportCustom = require('passport-custom');
|
||||||
const CustomStrategy = passportCustom.Strategy;
|
const CustomStrategy = passportCustom.Strategy;
|
||||||
const User = require('../models/User');
|
const User = require('../models/User');
|
||||||
|
|
@ -36,3 +38,4 @@ const joseLogin = async () =>
|
||||||
});
|
});
|
||||||
|
|
||||||
module.exports = joseLogin;
|
module.exports = joseLogin;
|
||||||
|
*/
|
||||||
|
|
|
||||||
BIN
bun.lockb
BIN
bun.lockb
Binary file not shown.
69
package-lock.json
generated
69
package-lock.json
generated
|
|
@ -62,7 +62,6 @@
|
||||||
"handlebars": "^4.7.7",
|
"handlebars": "^4.7.7",
|
||||||
"html": "^1.0.0",
|
"html": "^1.0.0",
|
||||||
"ioredis": "^5.3.2",
|
"ioredis": "^5.3.2",
|
||||||
"jose": "^4.15.2",
|
|
||||||
"js-yaml": "^4.1.0",
|
"js-yaml": "^4.1.0",
|
||||||
"jsonwebtoken": "^9.0.0",
|
"jsonwebtoken": "^9.0.0",
|
||||||
"keyv": "^4.5.4",
|
"keyv": "^4.5.4",
|
||||||
|
|
@ -1622,12 +1621,12 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@babel/generator": {
|
"node_modules/@babel/generator": {
|
||||||
"version": "7.22.15",
|
"version": "7.23.3",
|
||||||
"resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.22.15.tgz",
|
"resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.23.3.tgz",
|
||||||
"integrity": "sha512-Zu9oWARBqeVOW0dZOjXc3JObrzuqothQ3y/n1kUtrjCoCPLkXUwMvOo/F/TCfoHMbWIFlWwpZtkZVb9ga4U2pA==",
|
"integrity": "sha512-keeZWAV4LU3tW0qRi19HRpabC/ilM0HRBBzf9/k8FFiG4KVpiv0FIy4hHfLfFQZNhziCTPTmd59zoyv6DNISzg==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@babel/types": "^7.22.15",
|
"@babel/types": "^7.23.3",
|
||||||
"@jridgewell/gen-mapping": "^0.3.2",
|
"@jridgewell/gen-mapping": "^0.3.2",
|
||||||
"@jridgewell/trace-mapping": "^0.3.17",
|
"@jridgewell/trace-mapping": "^0.3.17",
|
||||||
"jsesc": "^2.5.1"
|
"jsesc": "^2.5.1"
|
||||||
|
|
@ -1760,22 +1759,22 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@babel/helper-environment-visitor": {
|
"node_modules/@babel/helper-environment-visitor": {
|
||||||
"version": "7.22.5",
|
"version": "7.22.20",
|
||||||
"resolved": "https://registry.npmjs.org/@babel/helper-environment-visitor/-/helper-environment-visitor-7.22.5.tgz",
|
"resolved": "https://registry.npmjs.org/@babel/helper-environment-visitor/-/helper-environment-visitor-7.22.20.tgz",
|
||||||
"integrity": "sha512-XGmhECfVA/5sAt+H+xpSg0mfrHq6FzNr9Oxh7PSEBBRUb/mL7Kz3NICXb194rCqAEdxkhPT1a88teizAFyvk8Q==",
|
"integrity": "sha512-zfedSIzFhat/gFhWfHtgWvlec0nqB9YEIVrpuwjruLlXfUSnA8cJB0miHKwqDnQ7d32aKo2xt88/xZptwxbfhA==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=6.9.0"
|
"node": ">=6.9.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@babel/helper-function-name": {
|
"node_modules/@babel/helper-function-name": {
|
||||||
"version": "7.22.5",
|
"version": "7.23.0",
|
||||||
"resolved": "https://registry.npmjs.org/@babel/helper-function-name/-/helper-function-name-7.22.5.tgz",
|
"resolved": "https://registry.npmjs.org/@babel/helper-function-name/-/helper-function-name-7.23.0.tgz",
|
||||||
"integrity": "sha512-wtHSq6jMRE3uF2otvfuD3DIvVhOsSNshQl0Qrd7qC9oQJzHvOL4qQXlQn2916+CXGywIjpGuIkoyZRRxHPiNQQ==",
|
"integrity": "sha512-OErEqsrxjZTJciZ4Oo+eoZqeW9UIiOcuYKRJA4ZAgV9myA+pOXhhmpfNCKjEH/auVfEYVFJ6y1Tc4r0eIApqiw==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@babel/template": "^7.22.5",
|
"@babel/template": "^7.22.15",
|
||||||
"@babel/types": "^7.22.5"
|
"@babel/types": "^7.23.0"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=6.9.0"
|
"node": ">=6.9.0"
|
||||||
|
|
@ -1937,9 +1936,9 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@babel/helper-validator-identifier": {
|
"node_modules/@babel/helper-validator-identifier": {
|
||||||
"version": "7.22.15",
|
"version": "7.22.20",
|
||||||
"resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.22.15.tgz",
|
"resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.22.20.tgz",
|
||||||
"integrity": "sha512-4E/F9IIEi8WR94324mbDUMo074YTheJmd7eZF5vITTeYchqAi6sYXRLHUVsmkdmY4QjfKTcB2jB7dVP3NaBElQ==",
|
"integrity": "sha512-Y4OZ+ytlatR8AI+8KZfKuL5urKp7qey08ha31L8b3BwewJAoJamTzyvxPR/5D+KkdJCGPq/+8TukHBlY10FX9A==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=6.9.0"
|
"node": ">=6.9.0"
|
||||||
|
|
@ -2068,9 +2067,9 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@babel/parser": {
|
"node_modules/@babel/parser": {
|
||||||
"version": "7.22.16",
|
"version": "7.23.3",
|
||||||
"resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.22.16.tgz",
|
"resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.23.3.tgz",
|
||||||
"integrity": "sha512-+gPfKv8UWeKKeJTUxe59+OobVcrYHETCsORl61EmSkmgymguYk/X5bp7GuUIXaFsc6y++v8ZxPsLSSuujqDphA==",
|
"integrity": "sha512-uVsWNvlVsIninV2prNz/3lHCb+5CJ+e+IUBfbjToAHODtfGYLfCFuY4AU7TskI+dAKk+njsPiBjq1gKTvZOBaw==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"bin": {
|
"bin": {
|
||||||
"parser": "bin/babel-parser.js"
|
"parser": "bin/babel-parser.js"
|
||||||
|
|
@ -3511,19 +3510,19 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@babel/traverse": {
|
"node_modules/@babel/traverse": {
|
||||||
"version": "7.22.17",
|
"version": "7.23.3",
|
||||||
"resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.22.17.tgz",
|
"resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.23.3.tgz",
|
||||||
"integrity": "sha512-xK4Uwm0JnAMvxYZxOVecss85WxTEIbTa7bnGyf/+EgCL5Zt3U7htUpEOWv9detPlamGKuRzCqw74xVglDWpPdg==",
|
"integrity": "sha512-+K0yF1/9yR0oHdE0StHuEj3uTPzwwbrLGfNOndVJVV2TqA5+j3oljJUb4nmB954FLGjNem976+B+eDuLIjesiQ==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@babel/code-frame": "^7.22.13",
|
"@babel/code-frame": "^7.22.13",
|
||||||
"@babel/generator": "^7.22.15",
|
"@babel/generator": "^7.23.3",
|
||||||
"@babel/helper-environment-visitor": "^7.22.5",
|
"@babel/helper-environment-visitor": "^7.22.20",
|
||||||
"@babel/helper-function-name": "^7.22.5",
|
"@babel/helper-function-name": "^7.23.0",
|
||||||
"@babel/helper-hoist-variables": "^7.22.5",
|
"@babel/helper-hoist-variables": "^7.22.5",
|
||||||
"@babel/helper-split-export-declaration": "^7.22.6",
|
"@babel/helper-split-export-declaration": "^7.22.6",
|
||||||
"@babel/parser": "^7.22.16",
|
"@babel/parser": "^7.23.3",
|
||||||
"@babel/types": "^7.22.17",
|
"@babel/types": "^7.23.3",
|
||||||
"debug": "^4.1.0",
|
"debug": "^4.1.0",
|
||||||
"globals": "^11.1.0"
|
"globals": "^11.1.0"
|
||||||
},
|
},
|
||||||
|
|
@ -3541,13 +3540,13 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@babel/types": {
|
"node_modules/@babel/types": {
|
||||||
"version": "7.22.17",
|
"version": "7.23.3",
|
||||||
"resolved": "https://registry.npmjs.org/@babel/types/-/types-7.22.17.tgz",
|
"resolved": "https://registry.npmjs.org/@babel/types/-/types-7.23.3.tgz",
|
||||||
"integrity": "sha512-YSQPHLFtQNE5xN9tHuZnzu8vPr61wVTBZdfv1meex1NBosa4iT05k/Jw06ddJugi4bk7The/oSwQGFcksmEJQg==",
|
"integrity": "sha512-OZnvoH2l8PK5eUvEcUyCt/sXgr/h+UWpVuBbOljwcrAgUl6lpchoQ++PHGyQy1AtYnVA6CEq3y5xeEI10brpXw==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@babel/helper-string-parser": "^7.22.5",
|
"@babel/helper-string-parser": "^7.22.5",
|
||||||
"@babel/helper-validator-identifier": "^7.22.15",
|
"@babel/helper-validator-identifier": "^7.22.20",
|
||||||
"to-fast-properties": "^2.0.0"
|
"to-fast-properties": "^2.0.0"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
|
|
@ -8794,9 +8793,9 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/axios": {
|
"node_modules/axios": {
|
||||||
"version": "1.5.0",
|
"version": "1.6.1",
|
||||||
"resolved": "https://registry.npmjs.org/axios/-/axios-1.5.0.tgz",
|
"resolved": "https://registry.npmjs.org/axios/-/axios-1.6.1.tgz",
|
||||||
"integrity": "sha512-D4DdjDo5CY50Qms0qGQTTw6Q44jl7zRwY7bthds06pUGfChBCTcQs+N743eFWGEd6pRTMd6A+I87aWyFV5wiZQ==",
|
"integrity": "sha512-vfBmhDpKafglh0EldBEbVuoe7DyAavGSLWhuSm5ZSEKQnHhBf0xAAwybbNH1IkrJNGnS/VG4I5yxig1pCEXE4g==",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"follow-redirects": "^1.15.0",
|
"follow-redirects": "^1.15.0",
|
||||||
"form-data": "^4.0.0",
|
"form-data": "^4.0.0",
|
||||||
|
|
@ -24098,7 +24097,7 @@
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@tanstack/react-query": "^4.28.0",
|
"@tanstack/react-query": "^4.28.0",
|
||||||
"axios": "^1.3.4",
|
"axios": "^1.3.4",
|
||||||
"openai": "^4.11.1",
|
"openai": "4.11.1",
|
||||||
"zod": "^3.22.4"
|
"zod": "^3.22.4"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue