mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-12-11 01:32:44 +00:00
[Java][apache-httpclient][feign][okhttp-gson] Enable access token refresh (#17086)
* add setter of bearer token supplier * run generate-samples.sh * add test of bearer auth
This commit is contained in:
@@ -166,18 +166,18 @@ public class ApiClient extends JavaTimeFormatter {
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to set token for HTTP bearer authentication.
|
||||
* Helper method to set access token for the first Bearer authentication.
|
||||
*
|
||||
* @param bearerToken the token
|
||||
* @param bearerToken Bearer token
|
||||
*/
|
||||
public void setBearerToken(String bearerToken) {
|
||||
setBearerToken(() -> bearerToken);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to set the token supplier for HTTP bearer authentication.
|
||||
* Helper method to set the supplier of access tokens for Bearer authentication.
|
||||
*
|
||||
* @param tokenSupplier the token supplier function
|
||||
* @param tokenSupplier The supplier of bearer tokens
|
||||
*/
|
||||
public void setBearerToken(Supplier<String> tokenSupplier) {
|
||||
for (Authentication auth : authentications.values()) {
|
||||
|
||||
@@ -14,14 +14,29 @@ public class HttpBearerAuth implements Authentication {
|
||||
this.scheme = scheme;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the token, which together with the scheme, will be sent as the value of the Authorization header.
|
||||
*
|
||||
* @return The bearer token
|
||||
*/
|
||||
public String getBearerToken() {
|
||||
return tokenSupplier.get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the token, which together with the scheme, will be sent as the value of the Authorization header.
|
||||
*
|
||||
* @param bearerToken The bearer token to send in the Authorization header
|
||||
*/
|
||||
public void setBearerToken(String bearerToken) {
|
||||
this.tokenSupplier = () -> bearerToken;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the supplier of tokens, which together with the scheme, will be sent as the value of the Authorization header.
|
||||
*
|
||||
* @param tokenSupplier The supplier of bearer tokens to send in the Authorization header
|
||||
*/
|
||||
public void setBearerToken(Supplier<String> tokenSupplier) {
|
||||
this.tokenSupplier = tokenSupplier;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user