lishuxu commented on code in PR #600:
URL: https://github.com/apache/iceberg-cpp/pull/600#discussion_r2979761023


##########
src/iceberg/catalog/rest/auth/auth_properties.cc:
##########
@@ -75,7 +79,25 @@ Result<AuthProperties> AuthProperties::FromProperties(
     }
   }
 
-  // TODO(lishuxu): Parse JWT exp claim from token to set expires_at_millis_.
+  // Parse JWT exp claim from token to set expires_at_millis_.
+  if (auto token = config.token(); !token.empty()) {
+    auto first_dot = token.find('.');
+    auto last_dot = token.find('.', first_dot + 1);
+    if (first_dot != std::string::npos && last_dot != std::string::npos) {
+      auto payload_encoded = token.substr(first_dot + 1, last_dot - first_dot 
- 1);
+      auto payload_decoded = TransformUtil::Base64UrlDecode(payload_encoded);
+      if (payload_decoded.has_value()) {
+        try {
+          auto payload_json = nlohmann::json::parse(payload_decoded.value());
+          if (payload_json.contains("exp") && payload_json["exp"].is_number()) 
{
+            config.expires_at_millis_ = payload_json["exp"].get<int64_t>() * 
1000;

Review Comment:
     `is_number()` returns true for both integers and floats, but 
`get<int64_t>()`
     throws `nlohmann::json::type_error` when the value is a float (e.g. 
`"exp": 1735689600.0`).
     This exception is not caught by the `parse_error` handler, so it would 
propagate
     unexpectedly.



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