gnodet opened a new pull request, #30707:
URL: https://github.com/apache/camel/pull/30707

   ## Summary
   
   The `oauthProfile` token was resolved once at startup and baked into an 
immutable SDK configuration object, so expired tokens continued to be sent 
after they expired.
   
   ## Root cause
   
   All three components called `OAuthHelper.resolveOAuthToken()` during 
endpoint/transport initialization and stored the resulting string in an 
immutable value:
   - **camel-openai**: in `resolveApiKey()` → stored as a plain string in 
`OpenAIOkHttpClient.Builder.apiKey()`, and in `createMcpTransport()` via 
`HttpRequest.newBuilder().header("Authorization", "Bearer " + token)`
   - **camel-langchain4j-agent**: in `buildTransport()` → stored as a 
`Map<String,String>` passed to 
`StreamableHttpMcpTransport.Builder.customHeaders(Map)`
   - **camel-spring-ai-chat**: in `createTransport()` → baked into an 
`HttpRequest.Builder` passed once to the SSE/streamableHttp transport builders
   
   ## Fix
   
   Switch each SDK to its supplier/callback API so the token is re-fetched on 
every outbound request:
   
   - **camel-openai** (`OpenAIEndpoint`): use 
`BearerTokenCredential.create(Supplier<String>)` via `builder.credential()` for 
the OpenAI client, and `McpSyncHttpClientRequestCustomizer` via 
`addHttpRequestCustomizer()` for MCP transports (SSE and streamableHttp).
   - **camel-langchain4j-agent** (`LangChain4jMcpServerDefinition`): use 
`StreamableHttpMcpTransport.Builder.customHeaders(Supplier<Map<String,String>>)`
 instead of `.customHeaders(Map)`.
   - **camel-spring-ai-chat** (`SpringAiChatMcpManager`): use 
`McpSyncHttpClientRequestCustomizer` via `addHttpRequestCustomizer()` for both 
SSE and streamableHttp transports.
   
   ## Testing
   
   Existing unit tests in `camel-openai` pass (pre-existing test-compilation 
errors in the observability-level tests are unrelated to this change). The 
langchain4j-agent and spring-ai-chat modules have similar pre-existing issues.
   
   ---
   _Claude Sonnet 4.6 on behalf of Guillaume Nodet (gnodet)_


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to