Skip to content

Commit 21e76cc

Browse files
committed
fix: Actually initialize the automated oauth clients
1 parent 1f7492f commit 21e76cc

File tree

3 files changed

+36
-9
lines changed

3 files changed

+36
-9
lines changed

e2e_tests/setup/integ-test-authentication.yaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,17 +89,23 @@ Resources:
8989
- "s3:GetEncryptionConfiguration"
9090
Resource:
9191
- "arn:aws:s3:::cdk*"
92-
# Allow integration tests to invoke Lambda functions and Bedrock models
92+
# Allow integration tests to invoke Lambda functions, Bedrock models, and retrieve the OAuth client secret
9393
- Effect: Allow
9494
Action:
9595
- "lambda:InvokeFunction"
96+
- "lambda:InvokeFunctionUrl"
9697
Resource:
9798
- !Sub "arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:mcp-server-*"
9899
- Effect: Allow
99100
Action:
100101
- "bedrock:InvokeModel"
101102
Resource:
102103
- "arn:aws:bedrock:us-west-2::foundation-model/anthropic.claude-3-5-sonnet-20241022-v2:0"
104+
- Effect: Allow
105+
Action:
106+
- "secretsmanager:GetSecretValue"
107+
Resource:
108+
- !Sub "arn:aws:secretsmanager:${AWS::Region}:${AWS::AccountId}:secret:mcp-lambda-examples-user-creds-*"
103109
Roles:
104110
- !Ref IntegrationTestRole
105111

e2e_tests/typescript/src/main.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ import { ChatSession } from "./chat_session.js";
33
import { LLMClient } from "./llm_client.js";
44
import { StdioServer } from "./server_clients/stdio_server.js";
55
import { LambdaFunctionClient } from "./server_clients/lambda_function.js";
6+
import {
7+
AutomatedOAuthClient,
8+
AutomatedOAuthConfig,
9+
} from "./server_clients/automated_oauth.js";
610
import { Server } from "./server_clients/server.js";
711
import logger from "./logger.js";
812

@@ -29,6 +33,15 @@ async function main(): Promise<void> {
2933
);
3034
}
3135

36+
// Initialize automated OAuth servers
37+
for (const [name, srvConfig] of Object.entries(
38+
serverConfig.oAuthServers || {}
39+
)) {
40+
servers.push(
41+
new AutomatedOAuthClient(name, srvConfig as AutomatedOAuthConfig)
42+
);
43+
}
44+
3245
const userUtterances = [
3346
"Hello!",
3447
"What is the current time in Seattle?",

e2e_tests/typescript/src/server_clients/automated_oauth.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import { Server } from "./server.js";
2222
import logger from "../logger.js";
2323

2424
/**
25-
* Configuration interface for AutomatedOAuth
25+
* Configuration interface for AutomatedOAuthClient
2626
*/
2727
export interface AutomatedOAuthConfig {
2828
// Lookup server URL from a CloudFormation stack
@@ -42,7 +42,7 @@ export interface AutomatedOAuthConfig {
4242
* - Client ID: CloudFormation stack output 'AutomatedOAuthClientId' from 'LambdaMcpServer-Auth' stack
4343
* - Client Secret: AWS Secrets Manager secret (ARN from CloudFormation stack output 'OAuthClientSecretArn')
4444
*/
45-
export class AutomatedOAuth extends Server {
45+
export class AutomatedOAuthClient extends Server {
4646
private oauthProvider?: AutomatedOAuthClientProvider;
4747

4848
// Lookup server URL from a CloudFormation stack
@@ -104,7 +104,9 @@ export class AutomatedOAuth extends Server {
104104
logger.debug("Starting automated OAuth flow...");
105105
await this.attemptConnection();
106106
} catch (error) {
107-
logger.error(`Error initializing automated OAuth server ${this.name}: ${error}`);
107+
logger.error(
108+
`Error initializing automated OAuth server ${this.name}: ${error}`
109+
);
108110
throw error;
109111
}
110112
}
@@ -187,7 +189,7 @@ export class AutomatedOAuth extends Server {
187189
try {
188190
// First get the secret ARN from CloudFormation
189191
logger.debug("Retrieving client secret ARN from CloudFormation...");
190-
192+
191193
const cloudFormationClient = new CloudFormationClient({
192194
region: this.authStackRegion,
193195
});
@@ -226,7 +228,7 @@ export class AutomatedOAuth extends Server {
226228

227229
// Now get the secret value from Secrets Manager
228230
logger.debug("Retrieving client secret from Secrets Manager...");
229-
231+
230232
const secretsManagerClient = new SecretsManagerClient({
231233
region: this.authStackRegion,
232234
});
@@ -443,16 +445,22 @@ class AutomatedOAuthClientProvider implements OAuthClientProvider {
443445

444446
redirectToAuthorization(authorizationUrl: URL): void {
445447
// Not used in client credentials flow - no user interaction
446-
throw new Error("redirectToAuthorization should not be called in automated OAuth flow");
448+
throw new Error(
449+
"redirectToAuthorization should not be called in automated OAuth flow"
450+
);
447451
}
448452

449453
saveCodeVerifier(codeVerifier: string): void {
450454
// Not used in client credentials flow
451-
throw new Error("saveCodeVerifier should not be called in automated OAuth flow");
455+
throw new Error(
456+
"saveCodeVerifier should not be called in automated OAuth flow"
457+
);
452458
}
453459

454460
codeVerifier(): string {
455461
// Not used in client credentials flow
456-
throw new Error("codeVerifier should not be called in automated OAuth flow");
462+
throw new Error(
463+
"codeVerifier should not be called in automated OAuth flow"
464+
);
457465
}
458466
}

0 commit comments

Comments
 (0)