Skip to content

Commit bdbc0d2

Browse files
committed
fix: Add more debugging for OAuth flow requests
1 parent 53137e1 commit bdbc0d2

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

e2e_tests/typescript/src/server_clients/automated_oauth.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -470,12 +470,6 @@ export class AutomatedOAuthClient extends Server {
470470
});
471471
const resourceMetadataUrl = extractResourceMetadataUrl(response);
472472

473-
if (!resourceMetadataUrl) {
474-
throw new Error(
475-
"No resource metadata URL found in WWW-Authenticate header"
476-
);
477-
}
478-
479473
logger.debug(`Discovered resource metadata URL: ${resourceMetadataUrl}`);
480474
logger.debug("Fetching OAuth protected resource metadata...");
481475

@@ -530,7 +524,9 @@ export class AutomatedOAuthClient extends Server {
530524
// This is a temporary workaround for AgentCore Gateways,
531525
// which currently return 404 on GET requests, instead of the expected 405
532526
fetch: async (url, init) => {
527+
logger.debug(`Fetch request: ${init?.method || 'GET'} ${url}`);
533528
if (init?.method === "GET") {
529+
logger.debug("Blocking GET request, returning 405");
534530
return new Response(null, {
535531
status: 405,
536532
statusText: "Method Not Allowed",

examples/chatbots/typescript/src/server_clients/interactive_oauth.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,13 @@ export class InteractiveOAuthClient extends Server {
490490
logger.debug("Making initial request to discover OAuth metadata...");
491491

492492
const serverUrl = this.config.serverUrl;
493-
const response = await fetch(serverUrl);
493+
const response = await fetch(serverUrl, {
494+
method: "POST",
495+
headers: {
496+
"Content-Type": "application/json",
497+
},
498+
body: JSON.stringify({ jsonrpc: "2.0", method: "ping", id: 1 }),
499+
});
494500
const resourceMetadataUrl = extractResourceMetadataUrl(response);
495501

496502
logger.debug(`Discovered resource metadata URL: ${resourceMetadataUrl}`);
@@ -526,6 +532,20 @@ export class InteractiveOAuthClient extends Server {
526532
const baseUrl = new URL(this.config.serverUrl);
527533
const transport = new StreamableHTTPClientTransport(baseUrl, {
528534
authProvider: oauthProvider,
535+
// Override fetch to handle POST-only endpoints
536+
// This is a temporary workaround for AgentCore Gateways,
537+
// which currently return 404 on GET requests, instead of the expected 405
538+
fetch: async (url, init) => {
539+
logger.debug(`Fetch request: ${init?.method || 'GET'} ${url}`);
540+
if (init?.method === "GET") {
541+
logger.debug("Blocking GET request, returning 405");
542+
return new Response(null, {
543+
status: 405,
544+
statusText: "Method Not Allowed",
545+
});
546+
}
547+
return fetch(url, init);
548+
},
529549
});
530550

531551
try {

0 commit comments

Comments
 (0)