snapshot of https://github.com/RocketChat/Rocket.Chat.git (develop, 2026-09-16; blobs > 131072B omitted)
Some checks failed
Create issues from TODOs / todos (push) Failing after 3s
Close inactive issues / close-issues (push) Has been cancelled
Deploy GitHub Pages / deploy-preview (push) Has been cancelled
CI / ⚙️ Variables Setup (push) Has been cancelled
CI / ⚙️ Test Guard (push) Has been cancelled
CI / 🚀 Notify external services - draft (push) Has been cancelled
CI / 📦 Build Packages (push) Has been cancelled
CI / 📦 Meteor Build (coverage) (push) Has been cancelled
CI / 📦 Meteor Build (production) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], fips) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Publish Docker Images (ghcr.io) (push) Has been cancelled
CI / 📦 Track Image Sizes (push) Has been cancelled
CI / 🔎 Code Check - Action Lint (push) Has been cancelled
CI / 🔎 Code Check (push) Has been cancelled
CI / 🔨 Test Storybook (push) Has been cancelled
CI / 🔨 Test Unit (push) Has been cancelled
CI / 🔨 Test API (CE) (push) Has been cancelled
CI / 🔨 Test API Livechat (CE) (push) Has been cancelled
CI / 🔨 Test UI (CE) (push) Has been cancelled
CI / 🔨 Test API (EE) (push) Has been cancelled
CI / 🔨 Test API Livechat (EE) (push) Has been cancelled
CI / 🔨 Test API Apps (deno-runtime - EE) (push) Has been cancelled
CI / 🔨 Test UI (EE) (push) Has been cancelled
CI / 🔨 Test API (FIPS) (push) Has been cancelled
CI / 🔨 Test API Livechat (FIPS) (push) Has been cancelled
CI / 🔨 Test UI (FIPS) (push) Has been cancelled
CI / 🔨 Test Federation Matrix (push) Has been cancelled
CI / 📊 Report Coverage (push) Has been cancelled
CI / ✅ Tests Done (push) Has been cancelled
CI / 🚀 Publish build assets (push) Has been cancelled
CI / 🚀 Publish Docker Images (DockerHub) (push) Has been cancelled
CI / 🚀 Notify external services (push) Has been cancelled
CI / Update Version Durability (push) Has been cancelled
Release / Release (push) Has been cancelled
Auto-close duplicate issues / auto-close-duplicates (push) Failing after 1s
Code scanning - action / CodeQL-Build (push) Failing after 1s

This commit is contained in:
upstream-mirror
2026-09-16 01:21:02 +05:00
commit 30810eecd7
10161 changed files with 987110 additions and 0 deletions

View File

@@ -0,0 +1,104 @@
import { Users } from '@rocket.chat/models';
import bodyParser from 'body-parser';
import MongoStore from 'connect-mongo';
import express from 'express';
import rateLimit from 'express-rate-limit';
import session from 'express-session';
import { MongoInternals } from 'meteor/mongo';
import { WebApp } from 'meteor/webapp';
import passport from 'passport';
import { configureOAuthServices } from '../lib/oauth/configureOAuthServices';
import { createOAuthServiceConfig } from '../lib/oauth/createOAuthServiceConfig';
import { getOAuthServices } from '../lib/oauth/getOAuthServices';
import type { ICachedSettings } from '../settings/CachedSettings';
const oAuthPaths = ['/oauth', '/_oauth'];
const { Router: router } = express;
export const oAuthRouter = router();
const oAuthApp = express();
oAuthApp.set('trust proxy', 1);
export const configurePassport = (settings: ICachedSettings) => {
const { client } = MongoInternals.defaultRemoteCollectionDriver().mongo;
oAuthApp.use(
oAuthPaths,
session({
name: 'oauth',
secret: settings.get<string>('Accounts_OAuth_Session_Secret'),
resave: false,
saveUninitialized: false,
proxy: true,
store: MongoStore.create({
client,
collectionName: 'rocketchat_oauth_sessions',
ttl: 5 * 60,
autoRemove: 'native',
}),
cookie: {
httpOnly: true,
secure: process.env.NODE_ENV === 'production',
maxAge: 5 * 60 * 1000, // 5 minutes
sameSite: process.env.NODE_ENV === 'production' ? 'none' : 'lax',
},
}),
);
oAuthApp.use(oAuthPaths, passport.initialize());
oAuthApp.use(oAuthPaths, passport.session());
oAuthApp.use(oAuthPaths, bodyParser.urlencoded({ extended: true }));
const createOAuthRateLimiter = () =>
rateLimit({
windowMs: settings.get<number>('API_Enable_Rate_Limiter_Limit_Time_Default'),
max: settings.get<number>('API_Enable_Rate_Limiter_Limit_Calls_Default'),
skip: () =>
process.env.TEST_MODE === 'true' ||
process.env.TEST_MODE === 'api' ||
settings.get<boolean>('API_Enable_Rate_Limiter') !== true ||
(process.env.NODE_ENV === 'development' && settings.get<boolean>('API_Enable_Rate_Limiter_Dev') !== true),
handler: (_req, res) => {
res.status(429).json({
success: false,
error: 'Too many requests. Please try again later.',
});
},
});
let oauthRateLimiter = createOAuthRateLimiter();
settings.watchMultiple(['API_Enable_Rate_Limiter_Limit_Time_Default', 'API_Enable_Rate_Limiter_Limit_Calls_Default'], () => {
oauthRateLimiter = createOAuthRateLimiter();
});
oAuthRouter.use(oAuthPaths, (req, res, next) => oauthRateLimiter(req, res, next));
// Register OAuth Routes
oAuthApp.use(oAuthRouter);
passport.serializeUser((user: any, done) => {
done(null, user._id);
});
passport.deserializeUser(async (id, done) => {
const user = await Users.findOneById(id as string, { projection: { __rooms: 0 } });
// we don’t actually use this user later
done(null, user);
});
settings.watchByRegex(/^(Accounts_OAuth_[a-z0-9_]+|API_GitHub_Enterprise_URL)$/i, () => {
if (!settings.get<boolean>('Accounts_OAuth_Use_Modern_Flow')) {
return;
}
const services = getOAuthServices(settings);
const oauthServiceConfigs = createOAuthServiceConfig(settings, services);
configureOAuthServices(oauthServiceConfigs, settings);
});
WebApp.rawConnectHandlers.use(oAuthApp);
};