@@ -16,6 +16,35 @@ import { createLogger, type LogContext } from '../utils/logger.js';
1616const SERVER_LOG_CONTEXT : LogContext = 'server' ;
1717const logger = createLogger ( 'OAuthHandler' , SERVER_LOG_CONTEXT ) ;
1818
19+ const OAUTH_CONFIG_FIELDS = new Set ( [
20+ 'clientId' , 'clientSecret' , 'scopes' , 'optionalScopes' , 'redirectUri' ,
21+ 'client_id' , 'client_secret' , 'scope' , 'optional_scope' , 'redirect_uri' ,
22+ 'provider' ,
23+ ] ) ;
24+
25+ function getForwardableProviderConfig ( config ?: Record < string , any > ) : Record < string , string > {
26+ if ( ! config ) {
27+ return { } ;
28+ }
29+
30+ return Object . fromEntries (
31+ Object . entries ( config )
32+ . filter ( ( [ key , value ] ) => value !== undefined && value !== null && ! OAUTH_CONFIG_FIELDS . has ( key ) )
33+ . map ( ( [ key , value ] ) => [ key , String ( value ) ] )
34+ ) ;
35+ }
36+
37+ function getStoredProviderConfig ( config ?: Record < string , any > ) : Record < string , unknown > | undefined {
38+ const baseUrl = config ?. baseUrl || config ?. apiBaseUrl ;
39+ if ( ! baseUrl ) {
40+ return undefined ;
41+ }
42+
43+ return {
44+ baseUrl : String ( baseUrl ) ,
45+ } ;
46+ }
47+
1948/**
2049 * MCP Server URL - managed by Integrate
2150 */
@@ -370,18 +399,9 @@ export class OAuthHandler {
370399 // Add provider-specific config parameters (e.g., Notion's 'owner' parameter)
371400 // Fields already handled explicitly above — skip them if they accidentally
372401 // appear in the provider-specific config (e.g., from a ...config spread)
373- const OAUTH_FIELDS = new Set ( [
374- 'clientId' , 'clientSecret' , 'scopes' , 'optionalScopes' , 'redirectUri' ,
375- 'client_id' , 'client_secret' , 'scope' , 'optional_scope' , 'redirect_uri' ,
376- 'provider' ,
377- ] ) ;
378-
379- if ( providerConfig . config ) {
380- for ( const [ key , value ] of Object . entries ( providerConfig . config ) ) {
381- if ( value !== undefined && value !== null && ! OAUTH_FIELDS . has ( key ) ) {
382- url . searchParams . set ( key , String ( value ) ) ;
383- }
384- }
402+ const extraConfig = getForwardableProviderConfig ( providerConfig . config ) ;
403+ for ( const [ key , value ] of Object . entries ( extraConfig ) ) {
404+ url . searchParams . set ( key , value ) ;
385405 }
386406
387407 // Forward to MCP server
@@ -530,6 +550,7 @@ export class OAuthHandler {
530550 client_id : providerConfig . clientId ,
531551 client_secret : providerConfig . clientSecret ,
532552 redirect_uri : providerConfig . redirectUri ,
553+ ...getForwardableProviderConfig ( providerConfig . config ) ,
533554 } ) ,
534555 } ) ;
535556
@@ -559,6 +580,7 @@ export class OAuthHandler {
559580 scopes : result . scopes
560581 ? result . scopes . flatMap ( ( s : string ) => s . split ( ' ' ) . filter ( Boolean ) )
561582 : result . scopes ,
583+ providerConfig : getStoredProviderConfig ( providerConfig . config ) ,
562584 } ;
563585
564586 // Prefer email returned directly from the callback response (e.g. Google id_token),
@@ -755,6 +777,13 @@ export class OAuthHandler {
755777 body . subdomain = providerConfig . config . subdomain ;
756778 }
757779
780+ const extraConfig = getForwardableProviderConfig ( providerConfig . config ) ;
781+ for ( const [ key , value ] of Object . entries ( extraConfig ) ) {
782+ if ( body [ key ] === undefined ) {
783+ body [ key ] = value ;
784+ }
785+ }
786+
758787 // Forward to MCP server for token refresh
759788 const url = new URL ( '/oauth/refresh' , this . serverUrl ) ;
760789
@@ -790,6 +819,7 @@ export class OAuthHandler {
790819 scopes : result . scopes
791820 ? result . scopes . flatMap ( ( s : string ) => s . split ( ' ' ) . filter ( Boolean ) )
792821 : result . scopes ,
822+ providerConfig : getStoredProviderConfig ( providerConfig . config ) ,
793823 } ;
794824
795825 const email = result . email || await fetchUserEmail ( refreshRequest . provider , tokenData ) ;
0 commit comments