Skip to content

Commit cca09ff

Browse files
btiernayclaude
andauthored
fix(fastmcp): consolidate ApiClient instances in auth0.ts (#38)
Previously created two separate ApiClient instances with different audiences: - apiClient with AUTH0_AUDIENCE (correct) - exchangeClient with API_AUTH0_AUDIENCE (incorrect) The audience parameter in ApiClient constructor is for validating incoming tokens, not for specifying target audience of exchanged tokens. Both token verification and exchange should use the same client configured with the MCP's own audience (AUTH0_AUDIENCE). Changes: - Removed exchangeClient instance - Added client credentials to single apiClient - Updated exchangeCustomToken to use apiClient - Added comments clarifying audience usage in token exchange - Target audience (API_AUTH0_AUDIENCE) correctly specified in getTokenByExchangeProfile() call Fixes: AIDX-314 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude <noreply@anthropic.com>
1 parent 995b11a commit cca09ff

File tree

1 file changed

+6
-8
lines changed
  • auth-for-mcp/fastmcp-mcp-customtokenexchange-js/src

1 file changed

+6
-8
lines changed

auth-for-mcp/fastmcp-mcp-customtokenexchange-js/src/auth0.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,21 @@ const MCP_AUTH0_SUBJECT_TOKEN_TYPE = process.env.MCP_AUTH0_SUBJECT_TOKEN_TYPE as
1818
const MCP_AUTH0_EXCHANGE_SCOPE = process.env.MCP_AUTH0_EXCHANGE_SCOPE as string;
1919
const API_AUTH0_AUDIENCE = process.env.API_AUTH0_AUDIENCE as string;
2020

21-
21+
// Resource server's OAuth 2.0 client for token verification and exchange
22+
// Configured with the MCP resource server's audience
2223
const apiClient = new ApiClient({
2324
domain: AUTH0_DOMAIN,
2425
audience: AUTH0_AUDIENCE,
25-
});
26-
27-
const exchangeClient = new ApiClient({
28-
domain: AUTH0_DOMAIN,
29-
audience: API_AUTH0_AUDIENCE,
3026
clientId: MCP_AUTH0_CLIENT_ID,
3127
clientSecret: MCP_AUTH0_CLIENT_SECRET,
3228
});
3329

3430
export async function exchangeCustomToken(subjectToken: string) {
35-
return await exchangeClient.getTokenByExchangeProfile(subjectToken, {
31+
// Use the resource server's OAuth 2.0 client to exchange tokens
32+
// The 'audience' parameter specifies the target audience for the exchanged token
33+
return await apiClient.getTokenByExchangeProfile(subjectToken, {
3634
subjectTokenType: MCP_AUTH0_SUBJECT_TOKEN_TYPE,
37-
audience: API_AUTH0_AUDIENCE,
35+
audience: API_AUTH0_AUDIENCE, // Target audience for the exchanged token
3836
...(MCP_AUTH0_EXCHANGE_SCOPE && { scope: MCP_AUTH0_EXCHANGE_SCOPE }),
3937
});
4038
}

0 commit comments

Comments
 (0)