dimas-b commented on code in PR #2782:
URL: https://github.com/apache/polaris/pull/2782#discussion_r2422195202


##########
runtime/service/src/main/java/org/apache/polaris/service/credentials/connection/OAuthConnectionCredentialVendor.java:
##########
@@ -0,0 +1,91 @@
+/*
+ * 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.polaris.service.credentials.connection;
+
+import com.google.common.base.Joiner;
+import com.google.common.base.Preconditions;
+import jakarta.annotation.Nonnull;
+import jakarta.annotation.Priority;
+import jakarta.enterprise.context.RequestScoped;
+import jakarta.inject.Inject;
+import java.time.Instant;
+import org.apache.polaris.core.connection.AuthenticationType;
+import org.apache.polaris.core.connection.ConnectionConfigInfoDpo;
+import org.apache.polaris.core.connection.OAuthClientCredentialsParametersDpo;
+import org.apache.polaris.core.credentials.connection.CatalogAccessProperty;
+import 
org.apache.polaris.core.credentials.connection.ConnectionCredentialVendor;
+import org.apache.polaris.core.credentials.connection.ConnectionCredentials;
+import org.apache.polaris.core.secrets.UserSecretsManager;
+
+/**
+ * Connection credential vendor for OAuth 2.0 Client Credentials 
authentication.
+ *
+ * <p>This vendor handles OAuth 2.0 client credentials flow by reading the 
client secret from the
+ * secrets manager and formatting it as an OAuth credential for connecting to 
external catalogs.
+ *
+ * <p>The vendor provides only the OAuth credential (formatted as 
"clientId:clientSecret"). When
+ * connecting to the remote catalog, Iceberg SDK will use this credential to 
fetch OAuth tokens
+ * automatically.
+ *
+ * <p>This is the default implementation with {@code @Priority(100)}. Custom 
implementations can
+ * override this by providing a higher priority value.
+ */
+@RequestScoped
+@AuthType(AuthenticationType.OAUTH)
+@Priority(100)
+public class OAuthConnectionCredentialVendor implements 
ConnectionCredentialVendor {
+
+  private static final Joiner COLON_JOINER = Joiner.on(":");
+
+  private final UserSecretsManager secretsManager;
+
+  @Inject
+  public OAuthConnectionCredentialVendor(UserSecretsManager secretsManager) {
+    this.secretsManager = secretsManager;
+  }
+
+  @Override
+  public @Nonnull ConnectionCredentials getConnectionCredentials(
+      @Nonnull ConnectionConfigInfoDpo connectionConfig) {
+
+    // Validate authentication parameters type
+    Preconditions.checkArgument(
+        connectionConfig.getAuthenticationParameters()
+            instanceof OAuthClientCredentialsParametersDpo,
+        "Expected OAuthClientCredentialsParametersDpo, got: %s",
+        connectionConfig.getAuthenticationParameters().getClass().getName());
+
+    OAuthClientCredentialsParametersDpo oauthParams =
+        (OAuthClientCredentialsParametersDpo) 
connectionConfig.getAuthenticationParameters();
+
+    // Read the client secret from secrets manager
+    String clientSecret = 
secretsManager.readSecret(oauthParams.getClientSecretReference());
+
+    // Format credential as "clientId:clientSecret"
+    String credential = COLON_JOINER.join(oauthParams.getClientId(), 
clientSecret);
+
+    // Return the OAuth credential
+    // OAuth credentials don't expire - set expiration to Instant.MAX to 
indicate infinite validity
+    // If the credential expires, users need to update the catalog entity to 
rotate the credential.
+    return ConnectionCredentials.builder()
+        
.putCredential(CatalogAccessProperty.OAUTH2_CREDENTIAL.getPropertyName(), 
credential)

Review Comment:
   I fully support implementing OAuth2 flows in the future.
   
   However, in its current form this credential vendor provides simple pair of 
values, but claims the type of `AuthenticationType.OAUTH`. I personally find it 
misleading :thinking: 
   
   Even if Polaris supported OAuth2 flows to obtain a credential for a catalog 
connection, this class populates Iceberg's `credential` property, which is not 
a token. This property cannot hold an OAuth2 token. Instead it instruct the 
client to perform some activities internally in order to obtain the access 
token. From the Polaris POV OAuth is not apparent.



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