wgtmac commented on code in PR #646:
URL: https://github.com/apache/iceberg-cpp/pull/646#discussion_r3304315308


##########
src/iceberg/catalog/rest/auth/token_refresh_scheduler.h:
##########
@@ -0,0 +1,109 @@
+/*
+ * 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.
+ */
+
+#pragma once
+
+#include <chrono>
+#include <condition_variable>
+#include <cstdint>
+#include <functional>
+#include <mutex>
+#include <thread>
+#include <vector>
+
+#include "iceberg/catalog/rest/iceberg_rest_export.h"
+
+/// \file iceberg/catalog/rest/auth/token_refresh_scheduler.h
+/// \brief Global scheduler for OAuth2 token refresh tasks.
+
+namespace iceberg::rest::auth {
+
+/// \brief A process-global scheduler for delayed token refresh tasks.
+///
+/// Uses a single background thread that sleeps until the next task is due.
+/// All OAuth2AuthSession instances share this scheduler. Tasks are lightweight
+/// (a single HTTP POST to refresh a token), so one thread is sufficient.
+///
+/// Thread safety: All public methods are thread-safe.
+class ICEBERG_REST_EXPORT TokenRefreshScheduler {

Review Comment:
   @HuaHuaY is working on the adding a thread pool abstraction and it would be 
good to reuse that once available. The main issue of current design is that 
only a single thread is working on token refresh and a slow request would 
starve all other tasks.



##########
src/iceberg/util/transform_util.h:
##########
@@ -139,6 +140,19 @@ class ICEBERG_EXPORT TransformUtil {
 
   /// \brief Base64 encode a string
   static std::string Base64Encode(std::string_view str_to_encode);
+
+  /// \brief Base64 decode a string (standard alphabet: +/).
+  ///
+  /// Handles optional padding ('=').
+  /// \return Decoded string, or an error if the input contains invalid 
characters.
+  static Result<std::string> Base64Decode(std::string_view encoded);

Review Comment:
   nit: we can refactor a separate `iceberg/util/base64.h` for these 
`Base64XXX` functions.



##########
src/iceberg/util/transform_util.h:
##########
@@ -139,6 +140,19 @@ class ICEBERG_EXPORT TransformUtil {
 
   /// \brief Base64 encode a string
   static std::string Base64Encode(std::string_view str_to_encode);
+
+  /// \brief Base64 decode a string (standard alphabet: +/).
+  ///
+  /// Handles optional padding ('=').
+  /// \return Decoded string, or an error if the input contains invalid 
characters.
+  static Result<std::string> Base64Decode(std::string_view encoded);
+
+  /// \brief Base64url decode a string (URL-safe alphabet: -_).
+  ///
+  /// Handles optional padding ('='). This variant uses '-' and '_' instead of
+  /// '+' and '/' per RFC 4648 ยง5.
+  /// \return Decoded string, or an error if the input contains invalid 
characters.
+  static Result<std::string> Base64UrlDecode(std::string_view encoded);

Review Comment:
   Do we need to add a `Base64UrlEncode` for parity?



##########
src/iceberg/catalog/rest/auth/auth_session.cc:
##########
@@ -44,6 +51,183 @@ class DefaultAuthSession : public AuthSession {
   std::unordered_map<std::string, std::string> headers_;
 };
 
+/// \brief OAuth2 session with automatic token refresh.
+class OAuth2AuthSession : public AuthSession,
+                          public 
std::enable_shared_from_this<OAuth2AuthSession> {
+ public:
+  struct Config {
+    std::string token_endpoint;
+    std::string client_id;
+    std::string client_secret;
+    std::string scope;
+    bool keep_refreshed;
+  };
+
+  /// \brief Create an OAuth2 session and optionally schedule refresh.
+  static std::shared_ptr<OAuth2AuthSession> Create(

Review Comment:
   ```suggestion
     static std::shared_ptr<OAuth2AuthSession> Make(
   ```
   
   nit: rename it to Make to be consistent with this repo.



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to