File tree Expand file tree Collapse file tree 3 files changed +8
-22
lines changed 
source/cdk/ecs-and-lambda 
sample-ecs-weather-streamablehttp-stateless-nodejs-express/src 
sample-lambda-weather-streamablehttp-stateless-nodejs-express/src Expand file tree Collapse file tree 3 files changed +8
-22
lines changed Original file line number Diff line number Diff line change @@ -118,25 +118,11 @@ export class SecurityStack extends cdk.Stack {
118118        ] , 
119119        callbackUrls : [ 
120120          "http://localhost:2299/callback" ,  // for local development/testing with sample-auth-python server 
121-           "http://localhost:2299" ,  // for local development/testing with sample-auth-python server 
122-           "https://${this.region}.console.aws.amazon.com/cognito/oauth2/idpresponse" , 
123-         ] , 
124-         logoutUrls : [ 
125-           "http://localhost:2299/callback" ,  // for local development/testing with sample-auth-python server 
126-           "http://localhost:2299" ,  // for local development/testing with sample-auth-python server 
127-           "https://${this.region}.console.aws.amazon.com/cognito/oauth2" , 
128121        ] , 
129122      } , 
130123      preventUserExistenceErrors : true , 
131124    } ) ; 
132125
133-     // Output user client ID 
134-     new  cdk . CfnOutput ( this ,  "UserPoolUserClientId" ,  { 
135-       value : this . appClientUser . userPoolClientId , 
136-       description :
137-         "The Client ID for the Cognito User Pool Client (User Authentication)" , 
138-     } ) ; 
139- 
140126    // Create WAF Web ACL 
141127    this . webAcl  =  new  wafv2 . CfnWebACL ( this ,  "MCPServerWAF" ,  { 
142128      name : "mcp-server-waf" , 
Original file line number Diff line number Diff line change @@ -249,8 +249,8 @@ app.use(express.json());
249249 * Get WWW-Authenticate header for 401 responses. 
250250 */ 
251251function  getWWWAuthenticateHeader ( req : Request ) : string  { 
252-   const  baseUrl   = 
253-      process . env . BASE_URL  ||  `${ req . protocol }  ://${ req . get ( "host" ) }  ` ; 
252+   const  protocol   =   req . get ( "X-Forwarded-Proto" )   ||   req . protocol ; 
253+   const   baseUrl   =   process . env . BASE_URL  ||  `${ protocol }  ://${ req . get ( "host" ) }  ` ; 
254254  const  val  =  `Bearer realm="mcp-server", resource_metadata="${ baseUrl }  /weather-nodejs/.well-known/oauth-protected-resource"` ; 
255255  console . log ( val ) ; 
256256  return  val ; 
@@ -314,8 +314,8 @@ app.get(
314314  ( req : Request ,  res : Response )  =>  { 
315315    const  region  =  process . env . AWS_REGION  ||  "us-west-2" ; 
316316    const  user_pool_id  =  process . env . COGNITO_USER_POOL_ID ; 
317-     const  baseUrl   = 
318-        process . env . BASE_URL  ||  `${ req . protocol }  ://${ req . get ( "host" ) }  ` ; 
317+     const  protocol   =   req . get ( "X-Forwarded-Proto" )   ||   req . protocol ; 
318+     const   baseUrl   =   process . env . BASE_URL  ||  `${ protocol }  ://${ req . get ( "host" ) }  ` ; 
319319
320320    res . json ( { 
321321      resource : `${ baseUrl }  /weather-nodejs/mcp` , 
Original file line number Diff line number Diff line change @@ -249,8 +249,9 @@ app.use(express.json());
249249 * Get WWW-Authenticate header for 401 responses. 
250250 */ 
251251function  getWWWAuthenticateHeader ( req : Request ) : string  { 
252-   const  baseUrl  = 
253-     process . env . BASE_URL  ||  `${ req . protocol }  ://${ req . get ( "host" ) }  ` ; 
252+   // Check X-Forwarded-Proto from ALB/CloudFront, fallback to req.protocol for local testing 
253+   const  protocol  =  req . get ( "X-Forwarded-Proto" )  ||  req . protocol ; 
254+   const  baseUrl  =  process . env . BASE_URL  ||  `${ protocol }  ://${ req . get ( "host" ) }  ` ; 
254255  const  val  =  `Bearer realm="mcp-server", resource_metadata="${ baseUrl }  /weather-nodejs-lambda/.well-known/oauth-protected-resource"` ; 
255256  console . log ( val ) ; 
256257  return  val ; 
@@ -314,8 +315,7 @@ app.get(
314315  ( req : Request ,  res : Response )  =>  { 
315316    const  region  =  process . env . AWS_REGION  ||  "us-west-2" ; 
316317    const  user_pool_id  =  process . env . COGNITO_USER_POOL_ID ; 
317-     const  baseUrl  = 
318-       process . env . BASE_URL  ||  `${ req . protocol }  ://${ req . get ( "host" ) }  ` ; 
318+     const  baseUrl  =  process . env . BASE_URL  ||  `https://${ req . get ( "host" ) }  ` ; 
319319
320320    res . json ( { 
321321      resource : `${ baseUrl }  /weather-nodejs-lambda/mcp` , 
    
 
   
 
     
   
   
          
     
  
    
     
 
    
      
     
 
     
    You can’t perform that action at this time.
  
 
    
  
     
    
      
        
     
 
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments