Skip to content

Commit 7820571

Browse files
amikofalvyclaude
andauthored
fix: propagate baseUrl correctly in API key authentication (#446)
Fix bug where baseUrl was not properly propagated through the authentication chain, causing remote deployments to fall back to localhost:3003 instead of using the actual deployment URL. Changes: - Update extractContextFromApiKey to accept and pass baseUrl parameter - Update all calls to extractContextFromApiKey to pass baseUrl from request - Improve error logging in A2AClient to show actual error details This ensures A2A agent card fetches use the correct deployment URL in production environments. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude <noreply@anthropic.com>
1 parent 1581a53 commit 7820571

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

agents-run-api/src/a2a/client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ export class A2AClient {
186186
this.serviceEndpointUrl = agentCard.url; // Cache the service endpoint URL from the agent card
187187
return agentCard;
188188
} catch (error) {
189-
console.error('Error fetching or parsing Agent Card:');
189+
console.error('Error fetching or parsing Agent Card:', error);
190190
// Allow the promise to reject so users of agentCardPromise can handle it.
191191
throw error;
192192
}

agents-run-api/src/middleware/api-key-auth.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export const apiKeyAuth = () =>
3737

3838
if (authHeader?.startsWith('Bearer ')) {
3939
try {
40-
executionContext = await extractContextFromApiKey(authHeader.substring(7));
40+
executionContext = await extractContextFromApiKey(authHeader.substring(7), baseUrl);
4141
executionContext.agentId = agentId;
4242
logger.info({}, 'Development/test environment - API key authenticated successfully');
4343
} catch {
@@ -115,7 +115,7 @@ export const apiKeyAuth = () =>
115115
await next();
116116
return;
117117
} else if (apiKey) {
118-
const executionContext = await extractContextFromApiKey(apiKey);
118+
const executionContext = await extractContextFromApiKey(apiKey, baseUrl);
119119
executionContext.agentId = agentId;
120120

121121
c.set('executionContext', executionContext);
@@ -141,7 +141,7 @@ export const apiKeyAuth = () =>
141141
}
142142

143143
try {
144-
const executionContext = await extractContextFromApiKey(apiKey);
144+
const executionContext = await extractContextFromApiKey(apiKey, baseUrl);
145145
executionContext.agentId = agentId;
146146

147147
c.set('executionContext', executionContext);
@@ -172,7 +172,7 @@ export const apiKeyAuth = () =>
172172
}
173173
});
174174

175-
export const extractContextFromApiKey = async (apiKey: string) => {
175+
export const extractContextFromApiKey = async (apiKey: string, baseUrl?: string) => {
176176
const apiKeyRecord = await validateAndGetApiKey(apiKey, dbClient);
177177

178178
if (!apiKeyRecord) {
@@ -187,6 +187,7 @@ export const extractContextFromApiKey = async (apiKey: string) => {
187187
projectId: apiKeyRecord.projectId,
188188
graphId: apiKeyRecord.graphId,
189189
apiKeyId: apiKeyRecord.id,
190+
baseUrl: baseUrl,
190191
});
191192
};
192193
/**

0 commit comments

Comments
 (0)