[Java][RestClient] Enable access token refresh (#20733)

This commit is contained in:
wandi34
2025-02-26 10:05:50 +01:00
committed by GitHub
parent 481c69063d
commit fb7aa580bf
8 changed files with 113 additions and 0 deletions

View File

@@ -46,6 +46,7 @@ import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.TimeZone;
import java.util.function.Supplier;
import jakarta.annotation.Nullable;
@@ -222,6 +223,21 @@ public class ApiClient extends JavaTimeFormatter {
throw new RuntimeException("No Bearer authentication configured!");
}
/**
* Helper method to set the supplier of access tokens for Bearer authentication.
*
* @param tokenSupplier the token supplier function
*/
public void setBearerToken(Supplier<String> tokenSupplier) {
for (Authentication auth : authentications.values()) {
if (auth instanceof HttpBearerAuth) {
((HttpBearerAuth) auth).setBearerToken(tokenSupplier);
return;
}
}
throw new RuntimeException("No Bearer authentication configured!");
}
/**
* Helper method to set username for the first HTTP basic authentication.
* @param username the username