gnodet-bot commented on code in PR #31135:
URL: https://github.com/apache/camel/pull/31135#discussion_r4742896242


##########
components/camel-http/src/main/java/org/apache/camel/component/http/HttpProducer.java:
##########
@@ -267,6 +268,22 @@ public void process(Exchange exchange) throws Exception {
             httpRequest.addHeader("Connection", HeaderElements.CLOSE);
         }
 
+        // If an oauthProfile is set, resolve a bearer token per exchange and 
inject it.
+        // The token is only attached to requests directed at the endpoint's 
own authority;
+        // redirects to a different host or port will not carry it because we 
set the header
+        // only once here — the OAuth2ClientConfigurer interceptor pattern is 
not used for
+        // profile-based tokens.
+        String oauthProfile = getEndpoint().getOauthProfile();
+        if (oauthProfile != null && !oauthProfile.isBlank()) {
+            if (OAuth2ClientConfigurer.isTargetAuthority(httpRequest, 
defaultUri)) {
+                String token = 
OAuthHelper.resolveOAuthToken(exchange.getContext(), oauthProfile);
+                httpRequest.setHeader(HttpHeaders.AUTHORIZATION, "Bearer " + 
token);

Review Comment:
   **Null token not guarded.** If `OAuthHelper.resolveOAuthToken()` returns 
`null` (a factory implementation returning null instead of throwing), the 
header becomes `Authorization: Bearer null` — syntactically valid but 
semantically nonsensical, and difficult to diagnose. Add a null/blank guard:
   
   ```suggestion
                   String token = 
OAuthHelper.resolveOAuthToken(exchange.getContext(), oauthProfile);
                   if (token == null || token.isBlank()) {
                       throw new CamelExchangeException(
                               "OAuth profile '" + oauthProfile + "' resolved a 
null or blank token", exchange);
                   }
                   httpRequest.setHeader(HttpHeaders.AUTHORIZATION, "Bearer " + 
token);
   ```



##########
components/camel-http/src/main/java/org/apache/camel/component/http/HttpEndpoint.java:
##########
@@ -220,6 +220,14 @@ public class HttpEndpoint extends HttpCommonEndpoint 
implements LineNumberAware
               description = "To use a custom strategy to compute the key of 
cached OAuth2 tokens when oauth2CacheTokens is"
                             + " enabled. When set, oauth2CachedTokensKey is 
not used.")
     private OAuth2CachedTokensKeyResolver oauth2CachedTokensKeyResolver;
+    @UriParam(label = "producer,security",
+              description = "The name of a camel-oauth profile to use for 
outgoing requests."
+                            + " When set, a bearer token is resolved per 
exchange using the named profile"
+                            + " (properties under camel.oauth.{profileName}.*) 
and injected as an"

Review Comment:
   **Inconsistent placeholder style.** The `@UriParam` description uses 
`{profileName}` (line 226), while the setter Javadoc (line 943) and the 
AsciiDoc docs both use `<profileName>`. Curly braces resemble Camel's Simple 
expression `${...}` syntax and could confuse users reading the auto-generated 
endpoint reference.
   
   ```suggestion
                               + " (properties under 
camel.oauth.<profileName>.*) and injected as an"
   ```



-- 
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