nastra commented on code in PR #6489:
URL: https://github.com/apache/iceberg/pull/6489#discussion_r1072480919


##########
core/src/main/java/org/apache/iceberg/rest/auth/OAuth2Util.java:
##########
@@ -302,17 +317,59 @@ public static OAuthTokenResponse 
tokenResponseFromJson(JsonNode json) {
     return builder.build();
   }
 
+  /**
+   * If the token is a JWT, extracts the expiration timestamp from the ext 
claim or null.
+   *
+   * @param token a token String
+   * @return The epoch millisecond the token expires at or null if it's not a 
valid JWT.
+   */
+  static Long expiresAtMillis(String token) {
+    if (null == token) {
+      return null;
+    }
+
+    String[] parts = token.split("\\.");
+    if (parts.length != 3) {
+      return null;
+    }
+
+    JsonNode node;
+    try {
+      node = 
JsonUtil.mapper().readTree(Base64.getUrlDecoder().decode(parts[1]));
+    } catch (IOException e) {
+      return null;
+    }
+
+    Long expiresAtSeconds = JsonUtil.getLongOrNull("exp", node);
+    if (expiresAtSeconds != null) {
+      return TimeUnit.SECONDS.toMillis(expiresAtSeconds);
+    }
+
+    return null;
+  }
+
   /** Class to handle authorization headers and token refresh. */
   public static class AuthSession {
+    private static final long MAX_REFRESH_WINDOW_MILLIS = 300_000; // 5 minutes
+    private static final long MIN_REFRESH_WAIT_MILLIS = 10;
     private Map<String, String> headers;
     private String token;
     private String tokenType;
+    private Long expiresAtMillis;
+    private final String credential;
     private volatile boolean keepRefreshed = true;
 
     public AuthSession(Map<String, String> baseHeaders, String token, String 
tokenType) {
+      this(baseHeaders, token, tokenType, null);

Review Comment:
   good point, will do that



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