[ 
https://issues.apache.org/jira/browse/CAMEL-27125?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Work on CAMEL-27125 started by Guillaume Nodet.
-----------------------------------------------
> camel-openai, camel-langchain4j-agent, camel-spring-ai-chat - the 
> oauthProfile token is resolved once at startup and still sent after it expired
> ------------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: CAMEL-27125
>                 URL: https://issues.apache.org/jira/browse/CAMEL-27125
>             Project: Camel
>          Issue Type: Bug
>          Components: camel-ai, camel-langchain4j-agent, camel-openai, 
> camel-spring-ai
>            Reporter: Federico Mariani
>            Assignee: Guillaume Nodet
>            Priority: Major
>              Labels: ai, oauth
>
> The {{oauthProfile}} option of the AI components resolves the token once, 
> when the endpoint starts, and hands the string to the SDK client. camel-oauth 
> caches the token and fetches a new one once it expires, but the component 
> never asks again: after the token lifetime (5 minutes by default in Keycloak) 
> every request fails with HTTP 401 until the route is restarted.
> Affected:
> * camel-openai: {{OpenAIEndpoint.createClient()}} passes the token to 
> {{builder.apiKey(...)}}; the MCP client ({{mcpServer.<name>.oauthProfile}}) 
> sets it once on the transport request builder.
> * camel-langchain4j-agent: {{LangChain4jMcpServerDefinition}} passes a fixed 
> header map to {{customHeaders(Map)}}.
> * camel-spring-ai-chat: {{SpringAiChatMcpManager}} sets the header once on 
> the transport request builder.
> * Same pattern, each needs a fix for its SDK: camel-docling, 
> camel-huggingface, camel-ibm-watsonx-ai and camel-ibm-watsonx-data write the 
> token into the endpoint configuration at startup. watsonx passes it as the 
> IBM Cloud API key, which the watsonx SDK exchanges with IAM itself, so an 
> OAuth access token may not fit there at all.
> Reproducer (camel-openai): register an {{OAuthClientAuthenticationFactory}} 
> that returns a new token on each resolution, as camel-oauth does after 
> expiry, and send two requests through
> {code:java}
> from("direct:chat")
>     .to("openai:chat-completion?model=gpt-5&oauthProfile=idp&baseUrl=" + 
> mockBaseUrl + "/v1");
> {code}
> Both requests carry {{Authorization: Bearer token-1}}, the token fetched at 
> startup.
> Expected: the token is resolved for each request. The SDKs support it: 
> openai-java {{BearerTokenCredential.create(Supplier<String>)}} (evaluated for 
> each request), MCP Java SDK {{addHttpRequestCustomizer}}, langchain4j 
> {{StreamableHttpMcpTransport.Builder.customHeaders(Supplier<Map<String, 
> String>>)}}. Short-lived tokens, such as a workload identity federation token 
> (see the parent issue), depend on this.
> _Claude Code on behalf of Federico Mariani_



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to