Skip to content

Commit 39b4c09

Browse files
committed
fix(backend): update OAuth client details in installation callback
1 parent 1138bd5 commit 39b4c09

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

services/backend/src/jobs/refresh-oauth-tokens.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,11 +161,22 @@ export async function refreshExpiringOAuthTokens(logger: FastifyBaseLogger) {
161161
// Determine client ID: use stored DCR client ID or fall back to 'deploystack'
162162
const clientId = installation.oauth_client_id || 'deploystack';
163163

164+
// Decrypt client secret if stored (from DCR or pre-registered provider)
165+
const clientSecret = installation.oauth_client_secret
166+
? decrypt(installation.oauth_client_secret, logger)
167+
: null;
168+
169+
// Use stored token endpoint (from installation) with fallback to discovery
170+
const tokenEndpoint = installation.oauth_token_endpoint || discovery.metadata.token_endpoint;
171+
const tokenEndpointAuthMethod = installation.oauth_token_endpoint_auth_method || 'none';
172+
164173
// Refresh access token
165174
const newTokens = await tokenService.refreshToken({
166175
refreshToken: decryptedRefreshToken,
167176
clientId,
168-
tokenEndpoint: discovery.metadata.token_endpoint,
177+
tokenEndpoint,
178+
clientSecret,
179+
tokenEndpointAuthMethod: tokenEndpointAuthMethod as 'client_secret_post' | 'client_secret_basic' | 'none',
169180
});
170181

171182
// Update encrypted tokens in database

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -466,11 +466,11 @@ export default async function oauthCallbackRoute(server: FastifyInstance) {
466466
oauth_code_verifier: null,
467467
oauth_pending: false,
468468
oauth_pending_expires_at: null,
469-
oauth_client_id: null,
470-
oauth_client_secret: null,
471-
oauth_provider_id: null,
472-
oauth_token_endpoint: null,
473-
oauth_token_endpoint_auth_method: null,
469+
oauth_client_id: flow.oauth_client_id,
470+
oauth_client_secret: flow.oauth_client_secret,
471+
oauth_provider_id: flow.oauth_provider_id || null,
472+
oauth_token_endpoint: flow.oauth_token_endpoint,
473+
oauth_token_endpoint_auth_method: flow.oauth_token_endpoint_auth_method,
474474
created_at: new Date(),
475475
updated_at: new Date(),
476476
last_used_at: null,

0 commit comments

Comments
 (0)