[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
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 113 additions and 0 deletions

View File

@ -631,6 +631,7 @@ Here are some companies/projects (alphabetical order) using OpenAPI Generator in
- [act coding](https://github.com/actcoding)
- [Adaptant Solutions AG](https://www.adaptant.io/)
- [adesso SE](https://www.adesso.de/)
- [adorsys GmbH & Co.KG](https://adorsys.com/)
- [Adyen](https://www.adyen.com/)
- [Agoda](https://www.agoda.com/)
- [Airthings](https://www.airthings.com/)

View File

@ -44,6 +44,7 @@ import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.TimeZone;
import java.util.function.Supplier;
import {{javaxPackage}}.annotation.Nullable;
@ -240,6 +241,21 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
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

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

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;
@ -220,6 +221,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

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;
@ -220,6 +221,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

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;
@ -226,6 +227,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

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;
@ -226,6 +227,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

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;
@ -226,6 +227,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