mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-12-04 18:16:12 +00:00
[Java][RestClient] Enable access token refresh (#20733)
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user