Fix #20370 by adding an OAuth access token supplier (#21800)

This commit is contained in:
GregDThomas
2025-08-26 07:41:45 +01:00
committed by GitHub
parent 3d93cc05ec
commit 814f406472
5 changed files with 60 additions and 10 deletions

View File

@@ -389,10 +389,20 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
* @param accessToken the access token
*/
public void setAccessToken(String accessToken) {
setAccessToken(() -> accessToken);
}
/**
* Helper method to set the supplier of access tokens for OAuth2 authentication.
*
* @param tokenSupplier The supplier of access tokens
* @return ApiClient this client
*/
public ApiClient setAccessToken(Supplier<String> tokenSupplier) {
for (Authentication auth : authentications.values()) {
if (auth instanceof OAuth) {
((OAuth) auth).setAccessToken(accessToken);
return;
((OAuth) auth).setAccessToken(tokenSupplier);
return this;
}
}
throw new RuntimeException("No OAuth2 authentication configured!");

View File

@@ -386,10 +386,20 @@ public class ApiClient extends JavaTimeFormatter {
* @param accessToken the access token
*/
public void setAccessToken(String accessToken) {
setAccessToken(() -> accessToken);
}
/**
* Helper method to set the supplier of access tokens for OAuth2 authentication.
*
* @param tokenSupplier The supplier of access tokens
* @return ApiClient this client
*/
public ApiClient setAccessToken(Supplier<String> tokenSupplier) {
for (Authentication auth : authentications.values()) {
if (auth instanceof OAuth) {
((OAuth) auth).setAccessToken(accessToken);
return;
((OAuth) auth).setAccessToken(tokenSupplier);
return this;
}
}
throw new RuntimeException("No OAuth2 authentication configured!");

View File

@@ -386,10 +386,20 @@ public class ApiClient extends JavaTimeFormatter {
* @param accessToken the access token
*/
public void setAccessToken(String accessToken) {
setAccessToken(() -> accessToken);
}
/**
* Helper method to set the supplier of access tokens for OAuth2 authentication.
*
* @param tokenSupplier The supplier of access tokens
* @return ApiClient this client
*/
public ApiClient setAccessToken(Supplier<String> tokenSupplier) {
for (Authentication auth : authentications.values()) {
if (auth instanceof OAuth) {
((OAuth) auth).setAccessToken(accessToken);
return;
((OAuth) auth).setAccessToken(tokenSupplier);
return this;
}
}
throw new RuntimeException("No OAuth2 authentication configured!");

View File

@@ -386,10 +386,20 @@ public class ApiClient extends JavaTimeFormatter {
* @param accessToken the access token
*/
public void setAccessToken(String accessToken) {
setAccessToken(() -> accessToken);
}
/**
* Helper method to set the supplier of access tokens for OAuth2 authentication.
*
* @param tokenSupplier The supplier of access tokens
* @return ApiClient this client
*/
public ApiClient setAccessToken(Supplier<String> tokenSupplier) {
for (Authentication auth : authentications.values()) {
if (auth instanceof OAuth) {
((OAuth) auth).setAccessToken(accessToken);
return;
((OAuth) auth).setAccessToken(tokenSupplier);
return this;
}
}
throw new RuntimeException("No OAuth2 authentication configured!");

View File

@@ -386,10 +386,20 @@ public class ApiClient extends JavaTimeFormatter {
* @param accessToken the access token
*/
public void setAccessToken(String accessToken) {
setAccessToken(() -> accessToken);
}
/**
* Helper method to set the supplier of access tokens for OAuth2 authentication.
*
* @param tokenSupplier The supplier of access tokens
* @return ApiClient this client
*/
public ApiClient setAccessToken(Supplier<String> tokenSupplier) {
for (Authentication auth : authentications.values()) {
if (auth instanceof OAuth) {
((OAuth) auth).setAccessToken(accessToken);
return;
((OAuth) auth).setAccessToken(tokenSupplier);
return this;
}
}
throw new RuntimeException("No OAuth2 authentication configured!");