Skip to content

Commit 11ab57c

Browse files
committed
fix: Use authorization server URL to get OAuth token, not MCP server URL
1 parent 2db8380 commit 11ab57c

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

e2e_tests/typescript/src/server_clients/automated_oauth.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,18 @@ export class AutomatedOAuthClient extends Server {
367367
{ resourceMetadataUrl }
368368
);
369369

370+
if (
371+
resourceMetadata.authorization_servers &&
372+
resourceMetadata.authorization_servers.length > 0
373+
) {
374+
this.config.authorizationServerUrl =
375+
resourceMetadata.authorization_servers[0];
376+
} else {
377+
throw new Error(
378+
"No authorization server found in OAuth protected resource metadata"
379+
);
380+
}
381+
370382
if (
371383
!resourceMetadata.scopes_supported ||
372384
resourceMetadata.scopes_supported.length === 0
@@ -419,7 +431,9 @@ export class AutomatedOAuthClient extends Server {
419431
logger.debug("Performing client credentials flow...");
420432

421433
// Discover OAuth metadata
422-
const metadata = await discoverOAuthMetadata(this.config.serverUrl);
434+
const metadata = await discoverOAuthMetadata(
435+
this.config.authorizationServerUrl
436+
);
423437

424438
if (!metadata?.token_endpoint) {
425439
throw new Error("No token endpoint found in OAuth metadata");

examples/servers/cat-facts/lib/cat-facts-mcp-server.function.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export const handler: Handler = async (
2828
event: APIGatewayProxyEventV2WithIAMAuthorizer,
2929
context: Context
3030
): Promise<APIGatewayProxyResultV2> => {
31-
// To customize the handler based on the caller's identity, you can use:
31+
// To customize the handler based on the caller's identity, you can use properties in:
3232
// event.requestContext.authorizer.iam
3333

3434
return requestHandler.handle(event, context);

examples/servers/dog-facts/lib/dog-facts-mcp-server.function.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {
22
Handler,
33
Context,
4-
APIGatewayProxyEvent,
4+
APIGatewayProxyWithCognitoAuthorizerEvent,
55
APIGatewayProxyResult,
66
} from "aws-lambda";
77
import {
@@ -25,11 +25,11 @@ const requestHandler = new APIGatewayProxyEventHandler(
2525
);
2626

2727
export const handler: Handler = async (
28-
event: APIGatewayProxyEvent,
28+
event: APIGatewayProxyWithCognitoAuthorizerEvent,
2929
context: Context
3030
): Promise<APIGatewayProxyResult> => {
31-
// To customize the handler based on the caller's identity, you can use:
32-
// event.requestContext.authorizer.iam
31+
// To customize the handler based on the caller's identity, you can use properties like:
32+
// event.requestContext.authorizer.claims["cognito:username"]
3333

3434
return requestHandler.handle(event, context);
3535
};

0 commit comments

Comments
 (0)