This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch camel-4.18.x
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/camel-4.18.x by this push:
     new d4b113cfc841 [backport camel-4.18.x] CAMEL-27226: camel-google-drive, 
camel-google-mail - the OAuth access token is sent only in the Authorization 
header (#30419)
d4b113cfc841 is described below

commit d4b113cfc8415e15cdb41c389eece8a3493559fe
Author: Claus Ibsen <[email protected]>
AuthorDate: Thu Nov 19 15:13:22 2026 +0100

    [backport camel-4.18.x] CAMEL-27226: camel-google-drive, camel-google-mail 
- the OAuth access token is sent only in the Authorization header (#30419)
    
    The producers and consumers of google-sheets, google-drive, google-mail and
    google-calendar set the options and headers of the exchange on the request
    of the Google API client. The credential options (clientId, clientSecret,
    accessToken, refreshToken, serviceAccountKey, delegate, and p12FileName for
    google-calendar) are no longer set on the request, matched ignoring case, so
    an accessToken option or header does not become the access_token query
    parameter. The client already sends the token in the Authorization header.
    
    The google-sheets part is CAMEL-27220 (only its credential handling; the
    change of the x-struct transformer is not part of this backport).
    
    (backport of #30364 and #30369, adapted for camel-4.18.x)
    
    Co-Authored-By: Claude Opus 5.5 <[email protected]>
    Signed-off-by: Claus Ibsen <[email protected]>
---
 .../google/calendar/GoogleCalendarConsumer.java    |   9 +-
 .../google/calendar/GoogleCalendarEndpoint.java    |  35 +++++
 .../google/calendar/GoogleCalendarProducer.java    |   9 +-
 .../GoogleCalendarRequestCredentialTest.java       | 136 +++++++++++++++++++
 .../google/drive/GoogleDriveConsumer.java          |   9 +-
 .../google/drive/GoogleDriveEndpoint.java          |  34 +++++
 .../google/drive/GoogleDriveProducer.java          |   9 +-
 .../drive/GoogleDriveRequestCredentialTest.java    | 150 +++++++++++++++++++++
 .../component/google/mail/GoogleMailConsumer.java  |   9 +-
 .../component/google/mail/GoogleMailEndpoint.java  |  34 +++++
 .../component/google/mail/GoogleMailProducer.java  |   9 +-
 .../mail/GoogleMailRequestCredentialTest.java      | 136 +++++++++++++++++++
 .../google/sheets/GoogleSheetsConsumer.java        |   9 +-
 .../google/sheets/GoogleSheetsEndpoint.java        |  34 +++++
 .../google/sheets/GoogleSheetsProducer.java        |   9 +-
 .../sheets/GoogleSheetsRequestCredentialTest.java  | 116 ++++++++++++++++
 16 files changed, 683 insertions(+), 64 deletions(-)

diff --git 
a/components/camel-google/camel-google-calendar/src/main/java/org/apache/camel/component/google/calendar/GoogleCalendarConsumer.java
 
b/components/camel-google/camel-google-calendar/src/main/java/org/apache/camel/component/google/calendar/GoogleCalendarConsumer.java
index 231b076c0b07..fedff02d0066 100644
--- 
a/components/camel-google/camel-google-calendar/src/main/java/org/apache/camel/component/google/calendar/GoogleCalendarConsumer.java
+++ 
b/components/camel-google/camel-google-calendar/src/main/java/org/apache/camel/component/google/calendar/GoogleCalendarConsumer.java
@@ -17,14 +17,11 @@
 package org.apache.camel.component.google.calendar;
 
 import java.util.Map;
-import java.util.Map.Entry;
 
 import com.google.api.client.googleapis.services.AbstractGoogleClientRequest;
 import org.apache.camel.Processor;
 import org.apache.camel.RuntimeCamelException;
 import 
org.apache.camel.component.google.calendar.internal.GoogleCalendarApiName;
-import org.apache.camel.spi.BeanIntrospection;
-import org.apache.camel.support.PluginHelper;
 import org.apache.camel.support.component.AbstractApiConsumer;
 
 /**
@@ -40,11 +37,7 @@ public class GoogleCalendarConsumer extends 
AbstractApiConsumer<GoogleCalendarAp
     protected Object doInvokeMethod(Map<String, Object> properties) throws 
RuntimeCamelException {
         AbstractGoogleClientRequest request = (AbstractGoogleClientRequest) 
super.doInvokeMethod(properties);
         try {
-            BeanIntrospection beanIntrospection
-                    = 
PluginHelper.getBeanIntrospection(getEndpoint().getCamelContext());
-            for (Entry<String, Object> p : properties.entrySet()) {
-                beanIntrospection.setProperty(getEndpoint().getCamelContext(), 
request, p.getKey(), p.getValue());
-            }
+            ((GoogleCalendarEndpoint) getEndpoint()).configureRequest(request, 
properties);
             return request.execute();
         } catch (Exception e) {
             throw new RuntimeCamelException(e);
diff --git 
a/components/camel-google/camel-google-calendar/src/main/java/org/apache/camel/component/google/calendar/GoogleCalendarEndpoint.java
 
b/components/camel-google/camel-google-calendar/src/main/java/org/apache/camel/component/google/calendar/GoogleCalendarEndpoint.java
index 18bb41040a40..d77d0eb53337 100644
--- 
a/components/camel-google/camel-google-calendar/src/main/java/org/apache/camel/component/google/calendar/GoogleCalendarEndpoint.java
+++ 
b/components/camel-google/camel-google-calendar/src/main/java/org/apache/camel/component/google/calendar/GoogleCalendarEndpoint.java
@@ -16,7 +16,11 @@
  */
 package org.apache.camel.component.google.calendar;
 
+import java.util.Collections;
+import java.util.List;
 import java.util.Map;
+import java.util.Set;
+import java.util.TreeSet;
 import java.util.concurrent.locks.Lock;
 import java.util.concurrent.locks.ReentrantLock;
 
@@ -29,9 +33,11 @@ import 
org.apache.camel.component.google.calendar.internal.GoogleCalendarApiColl
 import 
org.apache.camel.component.google.calendar.internal.GoogleCalendarApiName;
 import 
org.apache.camel.component.google.calendar.internal.GoogleCalendarConstants;
 import 
org.apache.camel.component.google.calendar.internal.GoogleCalendarPropertiesHelper;
+import org.apache.camel.spi.BeanIntrospection;
 import org.apache.camel.spi.EndpointServiceLocation;
 import org.apache.camel.spi.UriEndpoint;
 import org.apache.camel.spi.UriParam;
+import org.apache.camel.support.PluginHelper;
 import org.apache.camel.support.component.AbstractApiEndpoint;
 import org.apache.camel.support.component.ApiMethod;
 import org.apache.camel.support.component.ApiMethodPropertiesHelper;
@@ -46,6 +52,21 @@ import org.apache.camel.util.ObjectHelper;
 public class GoogleCalendarEndpoint extends 
AbstractApiEndpoint<GoogleCalendarApiName, GoogleCalendarConfiguration>
         implements EndpointServiceLocation {
 
+    /**
+     * The options that make up the credential of the client. The client sends 
the credential in the Authorization
+     * header, so they are not set on the request, where accessToken would 
become the access_token query parameter.
+     * p12FileName is the key file of a service account. The names are matched 
ignoring case, as a header such as
+     * CamelGoogleCalendar.AccessToken sets the same property as accessToken.
+     */
+    private static final Set<String> CREDENTIAL_OPTIONS;
+
+    static {
+        Set<String> options = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
+        options.addAll(List.of("clientId", "clientSecret", "accessToken", 
"refreshToken", "serviceAccountKey", "delegate",
+                "p12FileName"));
+        CREDENTIAL_OPTIONS = Collections.unmodifiableSet(options);
+    }
+
     @UriParam
     private GoogleCalendarConfiguration configuration;
     private final Lock clientLock = new ReentrantLock();
@@ -140,6 +161,20 @@ public class GoogleCalendarEndpoint extends 
AbstractApiEndpoint<GoogleCalendarAp
         return answer;
     }
 
+    /**
+     * Sets the options and headers on the request of the method, such as the 
optional parameters of the method and the
+     * standard parameters of the Google API, except the options of the 
credential, which the client already sends in
+     * the Authorization header.
+     */
+    void configureRequest(Object request, Map<String, Object> properties) 
throws Exception {
+        BeanIntrospection beanIntrospection = 
PluginHelper.getBeanIntrospection(getCamelContext());
+        for (Map.Entry<String, Object> p : properties.entrySet()) {
+            if (!CREDENTIAL_OPTIONS.contains(p.getKey())) {
+                beanIntrospection.setProperty(getCamelContext(), request, 
p.getKey(), p.getValue());
+            }
+        }
+    }
+
     @Override
     public Object getApiProxy(ApiMethod method, Map<String, Object> args) {
         return apiProxy;
diff --git 
a/components/camel-google/camel-google-calendar/src/main/java/org/apache/camel/component/google/calendar/GoogleCalendarProducer.java
 
b/components/camel-google/camel-google-calendar/src/main/java/org/apache/camel/component/google/calendar/GoogleCalendarProducer.java
index b415066b3402..f3b6b93456db 100644
--- 
a/components/camel-google/camel-google-calendar/src/main/java/org/apache/camel/component/google/calendar/GoogleCalendarProducer.java
+++ 
b/components/camel-google/camel-google-calendar/src/main/java/org/apache/camel/component/google/calendar/GoogleCalendarProducer.java
@@ -17,14 +17,11 @@
 package org.apache.camel.component.google.calendar;
 
 import java.util.Map;
-import java.util.Map.Entry;
 
 import com.google.api.client.googleapis.services.AbstractGoogleClientRequest;
 import org.apache.camel.RuntimeCamelException;
 import 
org.apache.camel.component.google.calendar.internal.GoogleCalendarApiName;
 import 
org.apache.camel.component.google.calendar.internal.GoogleCalendarPropertiesHelper;
-import org.apache.camel.spi.BeanIntrospection;
-import org.apache.camel.support.PluginHelper;
 import org.apache.camel.support.component.AbstractApiProducer;
 import org.apache.camel.support.component.ApiMethod;
 
@@ -42,11 +39,7 @@ public class GoogleCalendarProducer extends 
AbstractApiProducer<GoogleCalendarAp
             throws RuntimeCamelException {
         AbstractGoogleClientRequest request = (AbstractGoogleClientRequest) 
super.doInvokeMethod(method, properties);
         try {
-            BeanIntrospection beanIntrospection
-                    = 
PluginHelper.getBeanIntrospection(getEndpoint().getCamelContext());
-            for (Entry<String, Object> p : properties.entrySet()) {
-                beanIntrospection.setProperty(getEndpoint().getCamelContext(), 
request, p.getKey(), p.getValue());
-            }
+            ((GoogleCalendarEndpoint) getEndpoint()).configureRequest(request, 
properties);
             return request.execute();
         } catch (Exception e) {
             throw new RuntimeCamelException(e);
diff --git 
a/components/camel-google/camel-google-calendar/src/test/java/org/apache/camel/component/google/calendar/GoogleCalendarRequestCredentialTest.java
 
b/components/camel-google/camel-google-calendar/src/test/java/org/apache/camel/component/google/calendar/GoogleCalendarRequestCredentialTest.java
new file mode 100644
index 000000000000..b139a8a73486
--- /dev/null
+++ 
b/components/camel-google/camel-google-calendar/src/test/java/org/apache/camel/component/google/calendar/GoogleCalendarRequestCredentialTest.java
@@ -0,0 +1,136 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.google.calendar;
+
+import java.util.Collection;
+import java.util.List;
+import java.util.concurrent.CopyOnWriteArrayList;
+
+import com.google.api.client.auth.oauth2.BearerToken;
+import com.google.api.client.auth.oauth2.Credential;
+import com.google.api.client.json.Json;
+import com.google.api.client.json.JsonFactory;
+import com.google.api.client.json.gson.GsonFactory;
+import com.google.api.client.testing.http.MockHttpTransport;
+import com.google.api.client.testing.http.MockLowLevelHttpRequest;
+import com.google.api.client.testing.http.MockLowLevelHttpResponse;
+import com.google.api.services.calendar.Calendar;
+import org.apache.camel.CamelContext;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+/**
+ * The client sends the OAuth access token in the Authorization header; the 
request URL does not carry it.
+ */
+class GoogleCalendarRequestCredentialTest {
+
+    private static final String OAUTH = 
"clientId=id&clientSecret=secret&accessToken=atoken";
+
+    private final RecordingTransport transport = new RecordingTransport();
+
+    @Test
+    void shouldSendTheAccessTokenOfTheProducerOnlyInTheAuthorizationHeader() 
throws Exception {
+        try (CamelContext context = createContext()) {
+            Object body = context.createProducerTemplate()
+                    
.requestBody("google-calendar://calendars/get?calendarId=primary&" + OAUTH, 
(Object) null);
+
+            assertNotNull(body);
+            assertSentWithTheTokenInTheHeaderOnly(transport.requests.get(0));
+        }
+    }
+
+    @Test
+    void shouldSendTheAccessTokenOfTheConsumerOnlyInTheAuthorizationHeader() 
throws Exception {
+        try (CamelContext context = createContext()) {
+            MockEndpoint mock = context.getEndpoint("mock:result", 
MockEndpoint.class);
+            mock.expectedMinimumMessageCount(1);
+            context.addRoutes(new RouteBuilder() {
+                @Override
+                public void configure() {
+                    
from("google-calendar://calendars/get?calendarId=primary&delay=100&" + 
OAUTH).to("mock:result");
+                }
+            });
+
+            mock.assertIsSatisfied();
+            assertSentWithTheTokenInTheHeaderOnly(transport.requests.get(0));
+        }
+    }
+
+    private static void 
assertSentWithTheTokenInTheHeaderOnly(MockLowLevelHttpRequest request) {
+        assertFalse(request.getUrl().contains("access_token"), 
request.getUrl());
+        assertFalse(request.getUrl().contains("atoken"), request.getUrl());
+        assertEquals("Bearer atoken", 
request.getFirstHeaderValue("Authorization"));
+    }
+
+    private CamelContext createContext() {
+        CamelContext context = new DefaultCamelContext();
+        context.getComponent("google-calendar", GoogleCalendarComponent.class)
+                .setClientFactory(new OAuthClientFactory(transport));
+        context.start();
+        return context;
+    }
+
+    /**
+     * Creates the client with the access token as the client factory of the 
component does, on a transport that records
+     * the requests.
+     */
+    private static final class OAuthClientFactory implements 
GoogleCalendarClientFactory {
+
+        private final JsonFactory jsonFactory = 
GsonFactory.getDefaultInstance();
+        private final MockHttpTransport transport;
+
+        private OAuthClientFactory(MockHttpTransport transport) {
+            this.transport = transport;
+        }
+
+        @Override
+        public Calendar makeClient(
+                String clientId, String clientSecret, Collection<String> 
scopes, String applicationName, String refreshToken,
+                String accessToken, String emailAddress, String p12FileName, 
String user) {
+            // a bearer token credential, as the client factory of the 
component sets the accessToken on its credential
+            Credential credential = new 
Credential(BearerToken.authorizationHeaderAccessMethod()).setAccessToken(accessToken);
+            return new Calendar.Builder(transport, jsonFactory, 
credential).setApplicationName("test").build();
+        }
+
+        @Override
+        public Calendar makeClient(
+                CamelContext camelContext, String serviceAccountKey, 
Collection<String> scopes, String applicationName,
+                String delegate) {
+            throw new UnsupportedOperationException("OAuth only");
+        }
+    }
+
+    private static final class RecordingTransport extends MockHttpTransport {
+
+        private final List<MockLowLevelHttpRequest> requests = new 
CopyOnWriteArrayList<>();
+
+        @Override
+        public MockLowLevelHttpRequest buildRequest(String method, String url) 
{
+            MockLowLevelHttpRequest request = new MockLowLevelHttpRequest(url);
+            request.setResponse(new 
MockLowLevelHttpResponse().setContentType(Json.MEDIA_TYPE)
+                    .setContent("{\"id\":\"primary\"}"));
+            requests.add(request);
+            return request;
+        }
+    }
+}
diff --git 
a/components/camel-google/camel-google-drive/src/main/java/org/apache/camel/component/google/drive/GoogleDriveConsumer.java
 
b/components/camel-google/camel-google-drive/src/main/java/org/apache/camel/component/google/drive/GoogleDriveConsumer.java
index 62b0cebd74ef..2a25919db5d5 100644
--- 
a/components/camel-google/camel-google-drive/src/main/java/org/apache/camel/component/google/drive/GoogleDriveConsumer.java
+++ 
b/components/camel-google/camel-google-drive/src/main/java/org/apache/camel/component/google/drive/GoogleDriveConsumer.java
@@ -17,14 +17,11 @@
 package org.apache.camel.component.google.drive;
 
 import java.util.Map;
-import java.util.Map.Entry;
 
 import com.google.api.client.googleapis.services.AbstractGoogleClientRequest;
 import org.apache.camel.Processor;
 import org.apache.camel.RuntimeCamelException;
 import org.apache.camel.component.google.drive.internal.GoogleDriveApiName;
-import org.apache.camel.spi.BeanIntrospection;
-import org.apache.camel.support.PluginHelper;
 import org.apache.camel.support.component.AbstractApiConsumer;
 
 /**
@@ -39,11 +36,7 @@ public class GoogleDriveConsumer extends 
AbstractApiConsumer<GoogleDriveApiName,
     protected Object doInvokeMethod(Map<String, Object> properties) throws 
RuntimeCamelException {
         AbstractGoogleClientRequest request = (AbstractGoogleClientRequest) 
super.doInvokeMethod(properties);
         try {
-            BeanIntrospection beanIntrospection
-                    = 
PluginHelper.getBeanIntrospection(getEndpoint().getCamelContext());
-            for (Entry<String, Object> p : properties.entrySet()) {
-                beanIntrospection.setProperty(getEndpoint().getCamelContext(), 
request, p.getKey(), p.getValue());
-            }
+            ((GoogleDriveEndpoint) getEndpoint()).configureRequest(request, 
properties);
             return request.execute();
         } catch (Exception e) {
             throw new RuntimeCamelException(e);
diff --git 
a/components/camel-google/camel-google-drive/src/main/java/org/apache/camel/component/google/drive/GoogleDriveEndpoint.java
 
b/components/camel-google/camel-google-drive/src/main/java/org/apache/camel/component/google/drive/GoogleDriveEndpoint.java
index def2ac80d3c5..44b762ed7915 100644
--- 
a/components/camel-google/camel-google-drive/src/main/java/org/apache/camel/component/google/drive/GoogleDriveEndpoint.java
+++ 
b/components/camel-google/camel-google-drive/src/main/java/org/apache/camel/component/google/drive/GoogleDriveEndpoint.java
@@ -16,7 +16,11 @@
  */
 package org.apache.camel.component.google.drive;
 
+import java.util.Collections;
+import java.util.List;
 import java.util.Map;
+import java.util.Set;
+import java.util.TreeSet;
 import java.util.concurrent.locks.Lock;
 import java.util.concurrent.locks.ReentrantLock;
 
@@ -26,9 +30,11 @@ import 
org.apache.camel.component.google.drive.internal.GoogleDriveApiCollection
 import org.apache.camel.component.google.drive.internal.GoogleDriveApiName;
 import org.apache.camel.component.google.drive.internal.GoogleDriveConstants;
 import 
org.apache.camel.component.google.drive.internal.GoogleDrivePropertiesHelper;
+import org.apache.camel.spi.BeanIntrospection;
 import org.apache.camel.spi.EndpointServiceLocation;
 import org.apache.camel.spi.UriEndpoint;
 import org.apache.camel.spi.UriParam;
+import org.apache.camel.support.PluginHelper;
 import org.apache.camel.support.component.AbstractApiEndpoint;
 import org.apache.camel.support.component.ApiMethod;
 import org.apache.camel.support.component.ApiMethodPropertiesHelper;
@@ -42,6 +48,20 @@ import org.apache.camel.util.ObjectHelper;
              consumerPrefix = "consumer", category = { Category.FILE, 
Category.CLOUD, Category.API })
 public class GoogleDriveEndpoint extends 
AbstractApiEndpoint<GoogleDriveApiName, GoogleDriveConfiguration>
         implements EndpointServiceLocation {
+
+    /**
+     * The options that make up the credential of the client. The client sends 
the credential in the Authorization
+     * header, so they are not set on the request, where accessToken would 
become the access_token query parameter. The
+     * names are matched ignoring case, as a header such as 
CamelGoogleDrive.AccessToken sets the same property as
+     * accessToken.
+     */
+    private static final Set<String> CREDENTIAL_OPTIONS;
+
+    static {
+        Set<String> options = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
+        options.addAll(List.of("clientId", "clientSecret", "accessToken", 
"refreshToken", "serviceAccountKey", "delegate"));
+        CREDENTIAL_OPTIONS = Collections.unmodifiableSet(options);
+    }
     private Object apiProxy;
 
     @UriParam
@@ -144,6 +164,20 @@ public class GoogleDriveEndpoint extends 
AbstractApiEndpoint<GoogleDriveApiName,
         return answer;
     }
 
+    /**
+     * Sets the options and headers on the request of the method, such as the 
optional parameters of the method and the
+     * standard parameters of the Google API, except the options of the 
credential, which the client already sends in
+     * the Authorization header.
+     */
+    void configureRequest(Object request, Map<String, Object> properties) 
throws Exception {
+        BeanIntrospection beanIntrospection = 
PluginHelper.getBeanIntrospection(getCamelContext());
+        for (Map.Entry<String, Object> p : properties.entrySet()) {
+            if (!CREDENTIAL_OPTIONS.contains(p.getKey())) {
+                beanIntrospection.setProperty(getCamelContext(), request, 
p.getKey(), p.getValue());
+            }
+        }
+    }
+
     @Override
     public Object getApiProxy(ApiMethod method, Map<String, Object> args) {
         return apiProxy;
diff --git 
a/components/camel-google/camel-google-drive/src/main/java/org/apache/camel/component/google/drive/GoogleDriveProducer.java
 
b/components/camel-google/camel-google-drive/src/main/java/org/apache/camel/component/google/drive/GoogleDriveProducer.java
index f689131a8586..c4c9c0ab4ea8 100644
--- 
a/components/camel-google/camel-google-drive/src/main/java/org/apache/camel/component/google/drive/GoogleDriveProducer.java
+++ 
b/components/camel-google/camel-google-drive/src/main/java/org/apache/camel/component/google/drive/GoogleDriveProducer.java
@@ -17,15 +17,12 @@
 package org.apache.camel.component.google.drive;
 
 import java.util.Map;
-import java.util.Map.Entry;
 
 import com.google.api.client.googleapis.services.AbstractGoogleClientRequest;
 import org.apache.camel.RuntimeCamelException;
 import org.apache.camel.component.google.drive.internal.GoogleDriveApiName;
 import org.apache.camel.component.google.drive.internal.GoogleDriveConstants;
 import 
org.apache.camel.component.google.drive.internal.GoogleDrivePropertiesHelper;
-import org.apache.camel.spi.BeanIntrospection;
-import org.apache.camel.support.PluginHelper;
 import org.apache.camel.support.component.AbstractApiProducer;
 import org.apache.camel.support.component.ApiMethod;
 
@@ -43,11 +40,7 @@ public class GoogleDriveProducer extends 
AbstractApiProducer<GoogleDriveApiName,
             throws RuntimeCamelException {
         AbstractGoogleClientRequest request = (AbstractGoogleClientRequest) 
super.doInvokeMethod(method, properties);
         try {
-            BeanIntrospection beanIntrospection
-                    = 
PluginHelper.getBeanIntrospection(getEndpoint().getCamelContext());
-            for (Entry<String, Object> p : properties.entrySet()) {
-                beanIntrospection.setProperty(getEndpoint().getCamelContext(), 
request, p.getKey(), p.getValue());
-            }
+            ((GoogleDriveEndpoint) getEndpoint()).configureRequest(request, 
properties);
             return request.execute();
         } catch (Exception e) {
             throw new RuntimeCamelException(e);
diff --git 
a/components/camel-google/camel-google-drive/src/test/java/org/apache/camel/component/google/drive/GoogleDriveRequestCredentialTest.java
 
b/components/camel-google/camel-google-drive/src/test/java/org/apache/camel/component/google/drive/GoogleDriveRequestCredentialTest.java
new file mode 100644
index 000000000000..cac3d13b8806
--- /dev/null
+++ 
b/components/camel-google/camel-google-drive/src/test/java/org/apache/camel/component/google/drive/GoogleDriveRequestCredentialTest.java
@@ -0,0 +1,150 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.google.drive;
+
+import java.util.Collection;
+import java.util.List;
+import java.util.concurrent.CopyOnWriteArrayList;
+
+import com.google.api.client.auth.oauth2.BearerToken;
+import com.google.api.client.auth.oauth2.Credential;
+import com.google.api.client.json.Json;
+import com.google.api.client.json.JsonFactory;
+import com.google.api.client.json.gson.GsonFactory;
+import com.google.api.client.testing.http.MockHttpTransport;
+import com.google.api.client.testing.http.MockLowLevelHttpRequest;
+import com.google.api.client.testing.http.MockLowLevelHttpResponse;
+import com.google.api.services.drive.Drive;
+import org.apache.camel.CamelContext;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+/**
+ * The client sends the OAuth access token in the Authorization header; the 
request URL does not carry it.
+ */
+class GoogleDriveRequestCredentialTest {
+
+    private static final String OAUTH = 
"clientId=id&clientSecret=secret&accessToken=atoken";
+
+    private final RecordingTransport transport = new RecordingTransport();
+
+    @Test
+    void shouldSendTheAccessTokenOfTheProducerOnlyInTheAuthorizationHeader() 
throws Exception {
+        try (CamelContext context = createContext()) {
+            Object body
+                    = 
context.createProducerTemplate().requestBody("google-drive://drive-files/list?" 
+ OAUTH, (Object) null);
+
+            assertNotNull(body);
+            assertSentWithTheTokenInTheHeaderOnly(transport.requests.get(0));
+        }
+    }
+
+    @Test
+    void shouldNotSendAnAccessTokenHeaderOnTheRequestWhateverItsCase() throws 
Exception {
+        for (String header : List.of("CamelGoogleDrive.accessToken", 
"CamelGoogleDrive.AccessToken")) {
+            transport.requests.clear();
+            try (CamelContext context = createContext()) {
+                context.createProducerTemplate().requestBodyAndHeader(
+                        "google-drive://drive-files/list?" + OAUTH, null, 
header, "htoken");
+
+                String url = transport.requests.get(0).getUrl();
+                assertFalse(url.contains("access_token"), header + " -> " + 
url);
+                assertFalse(url.contains("htoken"), header + " -> " + url);
+            }
+        }
+    }
+
+    @Test
+    void shouldSendTheAccessTokenOfTheConsumerOnlyInTheAuthorizationHeader() 
throws Exception {
+        try (CamelContext context = createContext()) {
+            MockEndpoint mock = context.getEndpoint("mock:result", 
MockEndpoint.class);
+            mock.expectedMinimumMessageCount(1);
+            context.addRoutes(new RouteBuilder() {
+                @Override
+                public void configure() {
+                    from("google-drive://drive-files/list?delay=100&" + 
OAUTH).to("mock:result");
+                }
+            });
+
+            mock.assertIsSatisfied();
+            assertSentWithTheTokenInTheHeaderOnly(transport.requests.get(0));
+        }
+    }
+
+    private static void 
assertSentWithTheTokenInTheHeaderOnly(MockLowLevelHttpRequest request) {
+        assertFalse(request.getUrl().contains("access_token"), 
request.getUrl());
+        assertFalse(request.getUrl().contains("atoken"), request.getUrl());
+        assertEquals("Bearer atoken", 
request.getFirstHeaderValue("Authorization"));
+    }
+
+    private CamelContext createContext() {
+        CamelContext context = new DefaultCamelContext();
+        context.getComponent("google-drive", 
GoogleDriveComponent.class).setClientFactory(new OAuthClientFactory(transport));
+        context.start();
+        return context;
+    }
+
+    /**
+     * Creates the client with the access token as the client factory of the 
component does, on a transport that records
+     * the requests.
+     */
+    private static final class OAuthClientFactory implements 
GoogleDriveClientFactory {
+
+        private final JsonFactory jsonFactory = 
GsonFactory.getDefaultInstance();
+        private final MockHttpTransport transport;
+
+        private OAuthClientFactory(MockHttpTransport transport) {
+            this.transport = transport;
+        }
+
+        @Override
+        public Drive makeClient(
+                String clientId, String clientSecret, Collection<String> 
scopes, String applicationName, String refreshToken,
+                String accessToken) {
+            // a bearer token credential, as the client factory of the 
component sets the accessToken on its credential
+            Credential credential = new 
Credential(BearerToken.authorizationHeaderAccessMethod()).setAccessToken(accessToken);
+            return new Drive.Builder(transport, jsonFactory, 
credential).setApplicationName("test").build();
+        }
+
+        @Override
+        public Drive makeClient(
+                CamelContext camelContext, String serviceAccountKey, 
Collection<String> scopes, String applicationName,
+                String delegate) {
+            throw new UnsupportedOperationException("OAuth only");
+        }
+    }
+
+    private static final class RecordingTransport extends MockHttpTransport {
+
+        private final List<MockLowLevelHttpRequest> requests = new 
CopyOnWriteArrayList<>();
+
+        @Override
+        public MockLowLevelHttpRequest buildRequest(String method, String url) 
{
+            MockLowLevelHttpRequest request = new MockLowLevelHttpRequest(url);
+            request.setResponse(new 
MockLowLevelHttpResponse().setContentType(Json.MEDIA_TYPE)
+                    .setContent("{\"files\":[]}"));
+            requests.add(request);
+            return request;
+        }
+    }
+}
diff --git 
a/components/camel-google/camel-google-mail/src/main/java/org/apache/camel/component/google/mail/GoogleMailConsumer.java
 
b/components/camel-google/camel-google-mail/src/main/java/org/apache/camel/component/google/mail/GoogleMailConsumer.java
index c66b5c783c0e..f0eb4c440572 100644
--- 
a/components/camel-google/camel-google-mail/src/main/java/org/apache/camel/component/google/mail/GoogleMailConsumer.java
+++ 
b/components/camel-google/camel-google-mail/src/main/java/org/apache/camel/component/google/mail/GoogleMailConsumer.java
@@ -17,14 +17,11 @@
 package org.apache.camel.component.google.mail;
 
 import java.util.Map;
-import java.util.Map.Entry;
 
 import com.google.api.client.googleapis.services.AbstractGoogleClientRequest;
 import org.apache.camel.Processor;
 import org.apache.camel.RuntimeCamelException;
 import org.apache.camel.component.google.mail.internal.GoogleMailApiName;
-import org.apache.camel.spi.BeanIntrospection;
-import org.apache.camel.support.PluginHelper;
 import org.apache.camel.support.component.AbstractApiConsumer;
 
 /**
@@ -40,11 +37,7 @@ public class GoogleMailConsumer extends 
AbstractApiConsumer<GoogleMailApiName, G
     protected Object doInvokeMethod(Map<String, Object> properties) throws 
RuntimeCamelException {
         AbstractGoogleClientRequest request = (AbstractGoogleClientRequest) 
super.doInvokeMethod(properties);
         try {
-            BeanIntrospection beanIntrospection
-                    = 
PluginHelper.getBeanIntrospection(getEndpoint().getCamelContext());
-            for (Entry<String, Object> p : properties.entrySet()) {
-                beanIntrospection.setProperty(getEndpoint().getCamelContext(), 
request, p.getKey(), p.getValue());
-            }
+            ((GoogleMailEndpoint) getEndpoint()).configureRequest(request, 
properties);
             return request.execute();
         } catch (Exception e) {
             throw new RuntimeCamelException(e);
diff --git 
a/components/camel-google/camel-google-mail/src/main/java/org/apache/camel/component/google/mail/GoogleMailEndpoint.java
 
b/components/camel-google/camel-google-mail/src/main/java/org/apache/camel/component/google/mail/GoogleMailEndpoint.java
index 91887d07f231..6095198200ae 100644
--- 
a/components/camel-google/camel-google-mail/src/main/java/org/apache/camel/component/google/mail/GoogleMailEndpoint.java
+++ 
b/components/camel-google/camel-google-mail/src/main/java/org/apache/camel/component/google/mail/GoogleMailEndpoint.java
@@ -16,7 +16,11 @@
  */
 package org.apache.camel.component.google.mail;
 
+import java.util.Collections;
+import java.util.List;
 import java.util.Map;
+import java.util.Set;
+import java.util.TreeSet;
 import java.util.concurrent.locks.Lock;
 import java.util.concurrent.locks.ReentrantLock;
 
@@ -29,9 +33,11 @@ import 
org.apache.camel.component.google.mail.internal.GoogleMailApiCollection;
 import org.apache.camel.component.google.mail.internal.GoogleMailApiName;
 import org.apache.camel.component.google.mail.internal.GoogleMailConstants;
 import 
org.apache.camel.component.google.mail.internal.GoogleMailPropertiesHelper;
+import org.apache.camel.spi.BeanIntrospection;
 import org.apache.camel.spi.EndpointServiceLocation;
 import org.apache.camel.spi.UriEndpoint;
 import org.apache.camel.spi.UriParam;
+import org.apache.camel.support.PluginHelper;
 import org.apache.camel.support.component.AbstractApiEndpoint;
 import org.apache.camel.support.component.ApiMethod;
 import org.apache.camel.support.component.ApiMethodPropertiesHelper;
@@ -50,6 +56,20 @@ import org.apache.camel.util.ObjectHelper;
 public class GoogleMailEndpoint extends AbstractApiEndpoint<GoogleMailApiName, 
GoogleMailConfiguration>
         implements EndpointServiceLocation {
 
+    /**
+     * The options that make up the credential of the client. The client sends 
the credential in the Authorization
+     * header, so they are not set on the request, where accessToken would 
become the access_token query parameter. The
+     * names are matched ignoring case, as a header such as 
CamelGoogleMail.AccessToken sets the same property as
+     * accessToken.
+     */
+    private static final Set<String> CREDENTIAL_OPTIONS;
+
+    static {
+        Set<String> options = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
+        options.addAll(List.of("clientId", "clientSecret", "accessToken", 
"refreshToken", "serviceAccountKey", "delegate"));
+        CREDENTIAL_OPTIONS = Collections.unmodifiableSet(options);
+    }
+
     private Object apiProxy;
 
     @UriParam
@@ -140,6 +160,20 @@ public class GoogleMailEndpoint extends 
AbstractApiEndpoint<GoogleMailApiName, G
         return answer;
     }
 
+    /**
+     * Sets the options and headers on the request of the method, such as the 
optional parameters of the method and the
+     * standard parameters of the Google API, except the options of the 
credential, which the client already sends in
+     * the Authorization header.
+     */
+    void configureRequest(Object request, Map<String, Object> properties) 
throws Exception {
+        BeanIntrospection beanIntrospection = 
PluginHelper.getBeanIntrospection(getCamelContext());
+        for (Map.Entry<String, Object> p : properties.entrySet()) {
+            if (!CREDENTIAL_OPTIONS.contains(p.getKey())) {
+                beanIntrospection.setProperty(getCamelContext(), request, 
p.getKey(), p.getValue());
+            }
+        }
+    }
+
     @Override
     public Object getApiProxy(ApiMethod method, Map<String, Object> args) {
         return apiProxy;
diff --git 
a/components/camel-google/camel-google-mail/src/main/java/org/apache/camel/component/google/mail/GoogleMailProducer.java
 
b/components/camel-google/camel-google-mail/src/main/java/org/apache/camel/component/google/mail/GoogleMailProducer.java
index 447570d76d09..8d72d5e9f10f 100644
--- 
a/components/camel-google/camel-google-mail/src/main/java/org/apache/camel/component/google/mail/GoogleMailProducer.java
+++ 
b/components/camel-google/camel-google-mail/src/main/java/org/apache/camel/component/google/mail/GoogleMailProducer.java
@@ -17,14 +17,11 @@
 package org.apache.camel.component.google.mail;
 
 import java.util.Map;
-import java.util.Map.Entry;
 
 import com.google.api.client.googleapis.services.AbstractGoogleClientRequest;
 import org.apache.camel.RuntimeCamelException;
 import org.apache.camel.component.google.mail.internal.GoogleMailApiName;
 import 
org.apache.camel.component.google.mail.internal.GoogleMailPropertiesHelper;
-import org.apache.camel.spi.BeanIntrospection;
-import org.apache.camel.support.PluginHelper;
 import org.apache.camel.support.component.AbstractApiProducer;
 import org.apache.camel.support.component.ApiMethod;
 
@@ -42,11 +39,7 @@ public class GoogleMailProducer extends 
AbstractApiProducer<GoogleMailApiName, G
             throws RuntimeCamelException {
         AbstractGoogleClientRequest request = (AbstractGoogleClientRequest) 
super.doInvokeMethod(method, properties);
         try {
-            BeanIntrospection beanIntrospection
-                    = 
PluginHelper.getBeanIntrospection(getEndpoint().getCamelContext());
-            for (Entry<String, Object> p : properties.entrySet()) {
-                beanIntrospection.setProperty(getEndpoint().getCamelContext(), 
request, p.getKey(), p.getValue());
-            }
+            ((GoogleMailEndpoint) getEndpoint()).configureRequest(request, 
properties);
             return request.execute();
         } catch (Exception e) {
             throw new RuntimeCamelException(e);
diff --git 
a/components/camel-google/camel-google-mail/src/test/java/org/apache/camel/component/google/mail/GoogleMailRequestCredentialTest.java
 
b/components/camel-google/camel-google-mail/src/test/java/org/apache/camel/component/google/mail/GoogleMailRequestCredentialTest.java
new file mode 100644
index 000000000000..7d182007eb32
--- /dev/null
+++ 
b/components/camel-google/camel-google-mail/src/test/java/org/apache/camel/component/google/mail/GoogleMailRequestCredentialTest.java
@@ -0,0 +1,136 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.google.mail;
+
+import java.util.Collection;
+import java.util.List;
+import java.util.concurrent.CopyOnWriteArrayList;
+
+import com.google.api.client.auth.oauth2.BearerToken;
+import com.google.api.client.auth.oauth2.Credential;
+import com.google.api.client.json.Json;
+import com.google.api.client.json.JsonFactory;
+import com.google.api.client.json.gson.GsonFactory;
+import com.google.api.client.testing.http.MockHttpTransport;
+import com.google.api.client.testing.http.MockLowLevelHttpRequest;
+import com.google.api.client.testing.http.MockLowLevelHttpResponse;
+import com.google.api.services.gmail.Gmail;
+import org.apache.camel.CamelContext;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+/**
+ * The client sends the OAuth access token in the Authorization header; the 
request URL does not carry it.
+ */
+class GoogleMailRequestCredentialTest {
+
+    private static final String OAUTH = 
"clientId=id&clientSecret=secret&accessToken=atoken";
+
+    private final RecordingTransport transport = new RecordingTransport();
+
+    @Test
+    void shouldSendTheAccessTokenOfTheProducerOnlyInTheAuthorizationHeader() 
throws Exception {
+        try (CamelContext context = createContext()) {
+            Object body
+                    = 
context.createProducerTemplate().requestBody("google-mail://users/getProfile?userId=me&"
 + OAUTH,
+                            (Object) null);
+
+            assertNotNull(body);
+            assertSentWithTheTokenInTheHeaderOnly(transport.requests.get(0));
+        }
+    }
+
+    @Test
+    void shouldSendTheAccessTokenOfTheConsumerOnlyInTheAuthorizationHeader() 
throws Exception {
+        try (CamelContext context = createContext()) {
+            MockEndpoint mock = context.getEndpoint("mock:result", 
MockEndpoint.class);
+            mock.expectedMinimumMessageCount(1);
+            context.addRoutes(new RouteBuilder() {
+                @Override
+                public void configure() {
+                    from("google-mail://users/getProfile?userId=me&delay=100&" 
+ OAUTH).to("mock:result");
+                }
+            });
+
+            mock.assertIsSatisfied();
+            assertSentWithTheTokenInTheHeaderOnly(transport.requests.get(0));
+        }
+    }
+
+    private static void 
assertSentWithTheTokenInTheHeaderOnly(MockLowLevelHttpRequest request) {
+        assertFalse(request.getUrl().contains("access_token"), 
request.getUrl());
+        assertFalse(request.getUrl().contains("atoken"), request.getUrl());
+        assertEquals("Bearer atoken", 
request.getFirstHeaderValue("Authorization"));
+    }
+
+    private CamelContext createContext() {
+        CamelContext context = new DefaultCamelContext();
+        context.getComponent("google-mail", 
GoogleMailComponent.class).setClientFactory(new OAuthClientFactory(transport));
+        context.start();
+        return context;
+    }
+
+    /**
+     * Creates the client with the access token as the client factory of the 
component does, on a transport that records
+     * the requests.
+     */
+    private static final class OAuthClientFactory implements 
GoogleMailClientFactory {
+
+        private final JsonFactory jsonFactory = 
GsonFactory.getDefaultInstance();
+        private final MockHttpTransport transport;
+
+        private OAuthClientFactory(MockHttpTransport transport) {
+            this.transport = transport;
+        }
+
+        @Override
+        public Gmail makeClient(
+                String clientId, String clientSecret, Collection<String> 
scopes, String applicationName, String refreshToken,
+                String accessToken) {
+            // a bearer token credential, as the client factory of the 
component sets the accessToken on its credential
+            Credential credential = new 
Credential(BearerToken.authorizationHeaderAccessMethod()).setAccessToken(accessToken);
+            return new Gmail.Builder(transport, jsonFactory, 
credential).setApplicationName("test").build();
+        }
+
+        @Override
+        public Gmail makeClient(
+                CamelContext camelContext, String serviceAccountKey, 
Collection<String> scopes, String applicationName,
+                String delegate) {
+            throw new UnsupportedOperationException("OAuth only");
+        }
+    }
+
+    private static final class RecordingTransport extends MockHttpTransport {
+
+        private final List<MockLowLevelHttpRequest> requests = new 
CopyOnWriteArrayList<>();
+
+        @Override
+        public MockLowLevelHttpRequest buildRequest(String method, String url) 
{
+            MockLowLevelHttpRequest request = new MockLowLevelHttpRequest(url);
+            request.setResponse(new 
MockLowLevelHttpResponse().setContentType(Json.MEDIA_TYPE)
+                    .setContent("{\"emailAddress\":\"[email protected]\"}"));
+            requests.add(request);
+            return request;
+        }
+    }
+}
diff --git 
a/components/camel-google/camel-google-sheets/src/main/java/org/apache/camel/component/google/sheets/GoogleSheetsConsumer.java
 
b/components/camel-google/camel-google-sheets/src/main/java/org/apache/camel/component/google/sheets/GoogleSheetsConsumer.java
index f175f3406398..0faebbfca783 100644
--- 
a/components/camel-google/camel-google-sheets/src/main/java/org/apache/camel/component/google/sheets/GoogleSheetsConsumer.java
+++ 
b/components/camel-google/camel-google-sheets/src/main/java/org/apache/camel/component/google/sheets/GoogleSheetsConsumer.java
@@ -17,14 +17,11 @@
 package org.apache.camel.component.google.sheets;
 
 import java.util.Map;
-import java.util.Map.Entry;
 
 import com.google.api.client.googleapis.services.AbstractGoogleClientRequest;
 import org.apache.camel.Processor;
 import org.apache.camel.RuntimeCamelException;
 import org.apache.camel.component.google.sheets.internal.GoogleSheetsApiName;
-import org.apache.camel.spi.BeanIntrospection;
-import org.apache.camel.support.PluginHelper;
 import org.apache.camel.support.component.AbstractApiConsumer;
 
 /**
@@ -40,11 +37,7 @@ public class GoogleSheetsConsumer extends 
AbstractApiConsumer<GoogleSheetsApiNam
     protected Object doInvokeMethod(Map<String, Object> properties) throws 
RuntimeCamelException {
         AbstractGoogleClientRequest<?> request = (AbstractGoogleClientRequest) 
super.doInvokeMethod(properties);
         try {
-            BeanIntrospection beanIntrospection
-                    = 
PluginHelper.getBeanIntrospection(getEndpoint().getCamelContext());
-            for (Entry<String, Object> p : properties.entrySet()) {
-                beanIntrospection.setProperty(getEndpoint().getCamelContext(), 
request, p.getKey(), p.getValue());
-            }
+            ((GoogleSheetsEndpoint) getEndpoint()).configureRequest(request, 
properties);
             return request.execute();
         } catch (Exception e) {
             throw new RuntimeCamelException(e);
diff --git 
a/components/camel-google/camel-google-sheets/src/main/java/org/apache/camel/component/google/sheets/GoogleSheetsEndpoint.java
 
b/components/camel-google/camel-google-sheets/src/main/java/org/apache/camel/component/google/sheets/GoogleSheetsEndpoint.java
index 334cce5fdcd8..3718dd157392 100644
--- 
a/components/camel-google/camel-google-sheets/src/main/java/org/apache/camel/component/google/sheets/GoogleSheetsEndpoint.java
+++ 
b/components/camel-google/camel-google-sheets/src/main/java/org/apache/camel/component/google/sheets/GoogleSheetsEndpoint.java
@@ -16,10 +16,15 @@
  */
 package org.apache.camel.component.google.sheets;
 
+import java.util.Collections;
+import java.util.List;
 import java.util.Map;
+import java.util.Set;
+import java.util.TreeSet;
 import java.util.concurrent.locks.Lock;
 import java.util.concurrent.locks.ReentrantLock;
 
+import com.google.api.client.googleapis.services.AbstractGoogleClientRequest;
 import com.google.api.services.sheets.v4.Sheets;
 import org.apache.camel.Category;
 import org.apache.camel.Consumer;
@@ -29,9 +34,11 @@ import 
org.apache.camel.component.google.sheets.internal.GoogleSheetsApiCollecti
 import org.apache.camel.component.google.sheets.internal.GoogleSheetsApiName;
 import org.apache.camel.component.google.sheets.internal.GoogleSheetsConstants;
 import 
org.apache.camel.component.google.sheets.internal.GoogleSheetsPropertiesHelper;
+import org.apache.camel.spi.BeanIntrospection;
 import org.apache.camel.spi.EndpointServiceLocation;
 import org.apache.camel.spi.UriEndpoint;
 import org.apache.camel.spi.UriParam;
+import org.apache.camel.support.PluginHelper;
 import org.apache.camel.support.component.AbstractApiEndpoint;
 import org.apache.camel.support.component.ApiMethod;
 import org.apache.camel.support.component.ApiMethodPropertiesHelper;
@@ -46,6 +53,20 @@ import org.apache.camel.util.ObjectHelper;
 public class GoogleSheetsEndpoint extends 
AbstractApiEndpoint<GoogleSheetsApiName, GoogleSheetsConfiguration>
         implements EndpointServiceLocation {
 
+    /**
+     * The options that make up the credential of the client. The client sends 
the credential in the Authorization
+     * header, so they are not set on the request, where accessToken would 
become the access_token query parameter. The
+     * names are matched ignoring case, as a header such as 
CamelGoogleSheets.AccessToken sets the same property.
+     */
+    private static final Set<String> CREDENTIAL_OPTIONS;
+
+    static {
+        Set<String> options = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
+        options.addAll(
+                List.of("clientId", "clientSecret", "accessToken", 
"refreshToken", "serviceAccountKey", "delegate"));
+        CREDENTIAL_OPTIONS = Collections.unmodifiableSet(options);
+    }
+
     @UriParam
     private GoogleSheetsConfiguration configuration;
     private final Lock clientLock = new ReentrantLock();
@@ -120,6 +141,19 @@ public class GoogleSheetsEndpoint extends 
AbstractApiEndpoint<GoogleSheetsApiNam
         return answer;
     }
 
+    /**
+     * Sets the options and headers on the request of the method, such as the 
standard parameters of the Google API,
+     * except the options of the credential, which the client already sends in 
the Authorization header.
+     */
+    void configureRequest(AbstractGoogleClientRequest<?> request, Map<String, 
Object> properties) throws Exception {
+        BeanIntrospection beanIntrospection = 
PluginHelper.getBeanIntrospection(getCamelContext());
+        for (Map.Entry<String, Object> p : properties.entrySet()) {
+            if (!CREDENTIAL_OPTIONS.contains(p.getKey())) {
+                beanIntrospection.setProperty(getCamelContext(), request, 
p.getKey(), p.getValue());
+            }
+        }
+    }
+
     @Override
     public Object getApiProxy(ApiMethod method, Map<String, Object> args) {
         return apiProxy;
diff --git 
a/components/camel-google/camel-google-sheets/src/main/java/org/apache/camel/component/google/sheets/GoogleSheetsProducer.java
 
b/components/camel-google/camel-google-sheets/src/main/java/org/apache/camel/component/google/sheets/GoogleSheetsProducer.java
index 15ed352b7fa3..6398ebd68357 100644
--- 
a/components/camel-google/camel-google-sheets/src/main/java/org/apache/camel/component/google/sheets/GoogleSheetsProducer.java
+++ 
b/components/camel-google/camel-google-sheets/src/main/java/org/apache/camel/component/google/sheets/GoogleSheetsProducer.java
@@ -17,14 +17,11 @@
 package org.apache.camel.component.google.sheets;
 
 import java.util.Map;
-import java.util.Map.Entry;
 
 import com.google.api.client.googleapis.services.AbstractGoogleClientRequest;
 import org.apache.camel.RuntimeCamelException;
 import org.apache.camel.component.google.sheets.internal.GoogleSheetsApiName;
 import 
org.apache.camel.component.google.sheets.internal.GoogleSheetsPropertiesHelper;
-import org.apache.camel.spi.BeanIntrospection;
-import org.apache.camel.support.PluginHelper;
 import org.apache.camel.support.component.AbstractApiProducer;
 import org.apache.camel.support.component.ApiMethod;
 
@@ -43,11 +40,7 @@ public class GoogleSheetsProducer extends 
AbstractApiProducer<GoogleSheetsApiNam
         AbstractGoogleClientRequest<?> request
                 = (AbstractGoogleClientRequest) super.doInvokeMethod(method, 
properties);
         try {
-            BeanIntrospection beanIntrospection
-                    = 
PluginHelper.getBeanIntrospection(getEndpoint().getCamelContext());
-            for (Entry<String, Object> p : properties.entrySet()) {
-                beanIntrospection.setProperty(getEndpoint().getCamelContext(), 
request, p.getKey(), p.getValue());
-            }
+            ((GoogleSheetsEndpoint) getEndpoint()).configureRequest(request, 
properties);
             return request.execute();
         } catch (Exception e) {
             throw new RuntimeCamelException(e);
diff --git 
a/components/camel-google/camel-google-sheets/src/test/java/org/apache/camel/component/google/sheets/GoogleSheetsRequestCredentialTest.java
 
b/components/camel-google/camel-google-sheets/src/test/java/org/apache/camel/component/google/sheets/GoogleSheetsRequestCredentialTest.java
new file mode 100644
index 000000000000..ae6518173899
--- /dev/null
+++ 
b/components/camel-google/camel-google-sheets/src/test/java/org/apache/camel/component/google/sheets/GoogleSheetsRequestCredentialTest.java
@@ -0,0 +1,116 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.google.sheets;
+
+import java.util.List;
+import java.util.concurrent.CopyOnWriteArrayList;
+
+import com.google.api.client.json.Json;
+import com.google.api.client.testing.http.MockHttpTransport;
+import com.google.api.client.testing.http.MockLowLevelHttpRequest;
+import com.google.api.client.testing.http.MockLowLevelHttpResponse;
+import com.google.api.services.sheets.v4.model.ValueRange;
+import org.apache.camel.CamelContext;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+
+/**
+ * The client sends the OAuth access token in the Authorization header; the 
request URL does not carry it.
+ */
+class GoogleSheetsRequestCredentialTest {
+
+    private static final String OAUTH = 
"clientId=id&clientSecret=secret&accessToken=atoken";
+
+    private final RecordingTransport transport = new RecordingTransport();
+
+    @Test
+    void shouldSendTheAccessTokenOfTheProducerOnlyInTheAuthorizationHeader() 
throws Exception {
+        try (CamelContext context = createContext()) {
+            ValueRange body = context.createProducerTemplate().requestBody(
+                    "google-sheets://data/get?spreadsheetId=abc&range=A1:B1&" 
+ OAUTH, null, ValueRange.class);
+
+            assertEquals(List.of(List.of("a", "b")), body.getValues());
+            assertSentWithTheTokenInTheHeaderOnly(transport.requests.get(0));
+        }
+    }
+
+    @Test
+    void shouldNotSendAnAccessTokenHeaderOnTheRequestWhateverItsCase() throws 
Exception {
+        for (String header : List.of("CamelGoogleSheets.accessToken", 
"CamelGoogleSheets.AccessToken")) {
+            transport.requests.clear();
+            try (CamelContext context = createContext()) {
+                context.createProducerTemplate().requestBodyAndHeader(
+                        
"google-sheets://data/get?spreadsheetId=abc&range=A1:B1&" + OAUTH, null, 
header, "htoken");
+
+                String url = transport.requests.get(0).getUrl();
+                assertFalse(url.contains("access_token"), header + " -> " + 
url);
+                assertFalse(url.contains("htoken"), header + " -> " + url);
+            }
+        }
+    }
+
+    @Test
+    void shouldSendTheAccessTokenOfTheConsumerOnlyInTheAuthorizationHeader() 
throws Exception {
+        try (CamelContext context = createContext()) {
+            MockEndpoint mock = context.getEndpoint("mock:result", 
MockEndpoint.class);
+            mock.expectedMinimumMessageCount(1);
+            context.addRoutes(new RouteBuilder() {
+                @Override
+                public void configure() {
+                    
from("google-sheets://data/get?spreadsheetId=abc&range=A1:B1&delay=100&" + 
OAUTH)
+                            .to("mock:result");
+                }
+            });
+
+            mock.assertIsSatisfied();
+            assertSentWithTheTokenInTheHeaderOnly(transport.requests.get(0));
+        }
+    }
+
+    private static void 
assertSentWithTheTokenInTheHeaderOnly(MockLowLevelHttpRequest request) {
+        assertFalse(request.getUrl().contains("access_token"), 
request.getUrl());
+        assertFalse(request.getUrl().contains("atoken"), request.getUrl());
+        assertEquals("Bearer atoken", 
request.getFirstHeaderValue("Authorization"));
+    }
+
+    private CamelContext createContext() throws Exception {
+        CamelContext context = new DefaultCamelContext();
+        context.getComponent("google-sheets", GoogleSheetsComponent.class)
+                .setClientFactory(new 
BatchGoogleSheetsClientFactory(transport));
+        context.start();
+        return context;
+    }
+
+    private static final class RecordingTransport extends MockHttpTransport {
+
+        private final List<MockLowLevelHttpRequest> requests = new 
CopyOnWriteArrayList<>();
+
+        @Override
+        public MockLowLevelHttpRequest buildRequest(String method, String url) 
{
+            MockLowLevelHttpRequest request = new MockLowLevelHttpRequest(url);
+            request.setResponse(new 
MockLowLevelHttpResponse().setContentType(Json.MEDIA_TYPE)
+                    
.setContent("{\"range\":\"Sheet1!A1:B1\",\"majorDimension\":\"ROWS\",\"values\":[[\"a\",\"b\"]]}"));
+            requests.add(request);
+            return request;
+        }
+    }
+}

Reply via email to