Skip to content

Commit 3509194

Browse files
committed
Core: Stop fetchToken from sending the Authorization header
1 parent c22bac8 commit 3509194

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

core/src/main/java/org/apache/iceberg/rest/auth/OAuth2Util.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import java.util.concurrent.TimeUnit;
3535
import java.util.concurrent.atomic.AtomicReference;
3636
import java.util.regex.Pattern;
37+
import java.util.stream.Collectors;
3738
import org.apache.iceberg.relocated.com.google.common.annotations.VisibleForTesting;
3839
import org.apache.iceberg.relocated.com.google.common.base.Joiner;
3940
import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
@@ -243,7 +244,14 @@ public static OAuthTokenResponse fetchToken(
243244
oauth2ServerUri,
244245
request,
245246
OAuthTokenResponse.class,
246-
headers,
247+
// RFC 6749 proposes two ways to send a credential: HTTP Basic authentication or
248+
// request-body. Historically, the Iceberg library prefers the latter one for
249+
// compatibility while the RFC recommends the former one. As sending both the
250+
// Authorization header and the request-body parameters might confuse some authorization
251+
// servers, the following line is excluding the Authorization header.
252+
headers.entrySet().stream()
253+
.filter(entry -> !AUTHORIZATION_HEADER.equals(entry.getKey()))
254+
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)),
247255
ErrorHandlers.oauthErrorHandler());
248256
response.validate();
249257

core/src/test/java/org/apache/iceberg/rest/auth/TestOAuth2Manager.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ void contextualSessionCredentialsProvided() {
230230
SessionCatalog.SessionContext context =
231231
new SessionCatalog.SessionContext(
232232
"test", "test", Map.of(OAuth2Properties.CREDENTIAL, "client:secret"), Map.of());
233-
Map<String, String> properties = Map.of();
233+
Map<String, String> properties = Map.of(OAuth2Properties.CREDENTIAL, "client:secret");
234234
try (OAuth2Manager manager = new OAuth2Manager("test");
235235
OAuth2Util.AuthSession catalogSession = manager.catalogSession(client, properties);
236236
OAuth2Util.AuthSession contextualSession =
@@ -243,7 +243,7 @@ void contextualSessionCredentialsProvided() {
243243
.as("should create session cache for context with credentials")
244244
.satisfies(cache -> assertThat(cache.sessionCache().asMap()).hasSize(1));
245245
}
246-
Mockito.verify(client)
246+
Mockito.verify(client, times(2))
247247
.postForm(
248248
any(),
249249
eq(
@@ -255,7 +255,7 @@ void contextualSessionCredentialsProvided() {
255255
eq(OAuthTokenResponse.class),
256256
eq(Map.of()),
257257
any());
258-
Mockito.verify(client).withAuthSession(any());
258+
Mockito.verify(client, times(2)).withAuthSession(any());
259259
Mockito.verifyNoMoreInteractions(client);
260260
}
261261

0 commit comments

Comments
 (0)