Skip to content

Commit 7aa72ca

Browse files
author
Lasim
committed
refactor(backend): use GlobalSettings for backend URL in OAuth routes
1 parent bfcb1ff commit 7aa72ca

File tree

2 files changed

+5
-12
lines changed

2 files changed

+5
-12
lines changed

services/backend/src/routes/mcp/installations/authorize.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { getDb } from '../../../db';
99
import { mcpServers, mcpServerInstallations } from '../../../db/schema.sqlite';
1010
import { eq } from 'drizzle-orm';
1111
import { nanoid } from 'nanoid';
12+
import { GlobalSettings } from '../../../global-settings';
1213
import {
1314
TEAM_ID_PARAM_SCHEMA,
1415
OAUTH_AUTHORIZE_REQUEST_SCHEMA,
@@ -172,13 +173,8 @@ export default async function authorizeRoute(server: FastifyInstance) {
172173
const installationId = nanoid();
173174
const authService = new OAuthAuthorizationService(request.log);
174175

175-
// Build backend URL for OAuth callback
176-
const protocol = process.env.NODE_ENV === 'production' ? 'https' : 'http';
177-
const host = process.env.HOST || 'localhost';
178-
const port = process.env.PORT || '3000';
179-
const backendUrl = process.env.NODE_ENV === 'production'
180-
? `${protocol}://${host}`
181-
: `${protocol}://${host}:${port}`;
176+
// Get backend URL from global settings for OAuth callback
177+
const backendUrl = await GlobalSettings.get('global.backend_url', 'http://localhost:3000');
182178
const redirectUri = `${backendUrl}/api/teams/${teamId}/mcp/installations/${installationId}/oauth/callback`;
183179

184180
// Discover OAuth endpoints and check for dynamic client registration

services/backend/src/routes/mcp/installations/callback.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { OAuthTokenService } from '../../../services/OAuthTokenService';
66
import { OAuthDiscoveryService } from '../../../services/OAuthDiscoveryService';
77
import { encrypt } from '../../../utils/encryption';
88
import { GlobalSettingsInitService } from '../../../global-settings';
9+
import { GlobalSettings } from '../../../global-settings';
910
import { nanoid } from 'nanoid';
1011
import {
1112
OAUTH_CALLBACK_QUERY_SCHEMA,
@@ -201,11 +202,7 @@ export default async function oauthCallbackRoute(server: FastifyInstance) {
201202
}
202203

203204
// Construct redirect URI (must match what was sent in authorization request)
204-
const protocol = process.env.NODE_ENV === 'production' ? 'https' : 'http';
205-
const host = process.env.HOST || 'localhost';
206-
const port = process.env.PORT || '3000';
207-
const backendUrl =
208-
process.env.NODE_ENV === 'production' ? `${protocol}://${host}` : `${protocol}://${host}:${port}`;
205+
const backendUrl = await GlobalSettings.get('global.backend_url', 'http://localhost:3000');
209206
const redirectUri = `${backendUrl}/api/teams/${teamId}/mcp/installations/${installationId}/oauth/callback`;
210207

211208
// Get client_id from installation (may be dynamically registered)

0 commit comments

Comments
 (0)