mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-09-22 06:00:56 +02:00

* feat(api): refresh token logic * feat(client): refresh token logic * feat(data-provider): refresh token logic * fix: SSE uses esm * chore: add default refresh token expiry to AuthService, add message about env var not set when generating a token * chore: update scripts to more compatible bun methods, ran bun install again * chore: update env.example and playwright workflow with JWT_REFRESH_SECRET * chore: update breaking changes docs * chore: add timeout to url visit * chore: add default SESSION_EXPIRY in generateToken logic, add act script for testing github actions * fix(e2e): refresh automatically in development environment to pass e2e tests
140 lines
3 KiB
JavaScript
140 lines
3 KiB
JavaScript
const passport = require('passport');
|
|
const express = require('express');
|
|
const router = express.Router();
|
|
const config = require('../../../config/loader');
|
|
const { setAuthTokens } = require('../services/AuthService');
|
|
const domains = config.domains;
|
|
|
|
/**
|
|
* Google Routes
|
|
*/
|
|
router.get(
|
|
'/google',
|
|
passport.authenticate('google', {
|
|
scope: ['openid', 'profile', 'email'],
|
|
session: false,
|
|
}),
|
|
);
|
|
|
|
router.get(
|
|
'/google/callback',
|
|
passport.authenticate('google', {
|
|
failureRedirect: `${domains.client}/login`,
|
|
failureMessage: true,
|
|
session: false,
|
|
scope: ['openid', 'profile', 'email'],
|
|
}),
|
|
async (req, res) => {
|
|
try {
|
|
await setAuthTokens(req.user._id, res);
|
|
res.redirect(domains.client);
|
|
} catch (err) {
|
|
console.error('Error in setting authentication tokens:', err);
|
|
}
|
|
},
|
|
);
|
|
|
|
router.get(
|
|
'/facebook',
|
|
passport.authenticate('facebook', {
|
|
scope: ['public_profile'],
|
|
profileFields: ['id', 'email', 'name'],
|
|
session: false,
|
|
}),
|
|
);
|
|
|
|
router.get(
|
|
'/facebook/callback',
|
|
passport.authenticate('facebook', {
|
|
failureRedirect: `${domains.client}/login`,
|
|
failureMessage: true,
|
|
session: false,
|
|
scope: ['public_profile'],
|
|
profileFields: ['id', 'email', 'name'],
|
|
}),
|
|
async (req, res) => {
|
|
try {
|
|
await setAuthTokens(req.user._id, res);
|
|
res.redirect(domains.client);
|
|
} catch (err) {
|
|
console.error('Error in setting authentication tokens:', err);
|
|
}
|
|
},
|
|
);
|
|
|
|
router.get(
|
|
'/openid',
|
|
passport.authenticate('openid', {
|
|
session: false,
|
|
}),
|
|
);
|
|
|
|
router.get(
|
|
'/openid/callback',
|
|
passport.authenticate('openid', {
|
|
failureRedirect: `${domains.client}/login`,
|
|
failureMessage: true,
|
|
session: false,
|
|
}),
|
|
async (req, res) => {
|
|
try {
|
|
await setAuthTokens(req.user._id, res);
|
|
res.redirect(domains.client);
|
|
} catch (err) {
|
|
console.error('Error in setting authentication tokens:', err);
|
|
}
|
|
},
|
|
);
|
|
|
|
router.get(
|
|
'/github',
|
|
passport.authenticate('github', {
|
|
scope: ['user:email', 'read:user'],
|
|
session: false,
|
|
}),
|
|
);
|
|
|
|
router.get(
|
|
'/github/callback',
|
|
passport.authenticate('github', {
|
|
failureRedirect: `${domains.client}/login`,
|
|
failureMessage: true,
|
|
session: false,
|
|
scope: ['user:email', 'read:user'],
|
|
}),
|
|
async (req, res) => {
|
|
try {
|
|
await setAuthTokens(req.user._id, res);
|
|
res.redirect(domains.client);
|
|
} catch (err) {
|
|
console.error('Error in setting authentication tokens:', err);
|
|
}
|
|
},
|
|
);
|
|
router.get(
|
|
'/discord',
|
|
passport.authenticate('discord', {
|
|
scope: ['identify', 'email'],
|
|
session: false,
|
|
}),
|
|
);
|
|
|
|
router.get(
|
|
'/discord/callback',
|
|
passport.authenticate('discord', {
|
|
failureRedirect: `${domains.client}/login`,
|
|
failureMessage: true,
|
|
session: false,
|
|
scope: ['identify', 'email'],
|
|
}),
|
|
async (req, res) => {
|
|
try {
|
|
await setAuthTokens(req.user._id, res);
|
|
res.redirect(domains.client);
|
|
} catch (err) {
|
|
console.error('Error in setting authentication tokens:', err);
|
|
}
|
|
},
|
|
);
|
|
|
|
module.exports = router;
|