forked from loafle/openapi-generator-original
[Java][resttemplate] Enable access token refresh (#16485)
* use supplier to enable refreshing token * update samples * fix param name and doc * update samples
This commit is contained in:
parent
47a85e880b
commit
09704951f0
@ -62,6 +62,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.TimeZone;
|
||||
import java.util.function.Supplier;
|
||||
{{#jsr310}}
|
||||
import java.time.OffsetDateTime;
|
||||
{{/jsr310}}
|
||||
@ -192,9 +193,18 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
|
||||
* @param bearerToken the token
|
||||
*/
|
||||
public void setBearerToken(String bearerToken) {
|
||||
setBearerToken(() -> bearerToken);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to set the token supplier for HTTP 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(bearerToken);
|
||||
((HttpBearerAuth) auth).setBearerToken(tokenSupplier);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -1,27 +1,34 @@
|
||||
package {{invokerPackage}}.auth;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.function.Supplier;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
|
||||
{{>generatedAnnotation}}
|
||||
public class HttpBearerAuth implements Authentication {
|
||||
private final String scheme;
|
||||
private String bearerToken;
|
||||
private Supplier<String> tokenSupplier;
|
||||
|
||||
public HttpBearerAuth(String scheme) {
|
||||
this.scheme = scheme;
|
||||
}
|
||||
|
||||
public String getBearerToken() {
|
||||
return bearerToken;
|
||||
return tokenSupplier.get();
|
||||
}
|
||||
|
||||
public void setBearerToken(String bearerToken) {
|
||||
this.bearerToken = bearerToken;
|
||||
this.tokenSupplier = () -> bearerToken;
|
||||
}
|
||||
|
||||
public void setBearerToken(Supplier<String> tokenSupplier) {
|
||||
this.tokenSupplier = tokenSupplier;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyToParams(MultiValueMap<String, String> queryParams, HttpHeaders headerParams, MultiValueMap<String, String> cookieParams) {
|
||||
String bearerToken = Optional.ofNullable(tokenSupplier).map(Supplier::get).orElse(null);
|
||||
if (bearerToken == null) {
|
||||
return;
|
||||
}
|
||||
|
@ -51,6 +51,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.TimeZone;
|
||||
import java.util.function.Supplier;
|
||||
import java.time.OffsetDateTime;
|
||||
|
||||
import org.openapitools.client.auth.Authentication;
|
||||
|
@ -1,27 +1,34 @@
|
||||
package org.openapitools.client.auth;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.function.Supplier;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
|
||||
@jakarta.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen")
|
||||
public class HttpBearerAuth implements Authentication {
|
||||
private final String scheme;
|
||||
private String bearerToken;
|
||||
private Supplier<String> tokenSupplier;
|
||||
|
||||
public HttpBearerAuth(String scheme) {
|
||||
this.scheme = scheme;
|
||||
}
|
||||
|
||||
public String getBearerToken() {
|
||||
return bearerToken;
|
||||
return tokenSupplier.get();
|
||||
}
|
||||
|
||||
public void setBearerToken(String bearerToken) {
|
||||
this.bearerToken = bearerToken;
|
||||
this.tokenSupplier = () -> bearerToken;
|
||||
}
|
||||
|
||||
public void setBearerToken(Supplier<String> tokenSupplier) {
|
||||
this.tokenSupplier = tokenSupplier;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyToParams(MultiValueMap<String, String> queryParams, HttpHeaders headerParams, MultiValueMap<String, String> cookieParams) {
|
||||
String bearerToken = Optional.ofNullable(tokenSupplier).map(Supplier::get).orElse(null);
|
||||
if (bearerToken == null) {
|
||||
return;
|
||||
}
|
||||
|
@ -51,6 +51,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.TimeZone;
|
||||
import java.util.function.Supplier;
|
||||
import java.time.OffsetDateTime;
|
||||
|
||||
import org.openapitools.client.auth.Authentication;
|
||||
|
@ -1,27 +1,34 @@
|
||||
package org.openapitools.client.auth;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.function.Supplier;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
|
||||
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen")
|
||||
public class HttpBearerAuth implements Authentication {
|
||||
private final String scheme;
|
||||
private String bearerToken;
|
||||
private Supplier<String> tokenSupplier;
|
||||
|
||||
public HttpBearerAuth(String scheme) {
|
||||
this.scheme = scheme;
|
||||
}
|
||||
|
||||
public String getBearerToken() {
|
||||
return bearerToken;
|
||||
return tokenSupplier.get();
|
||||
}
|
||||
|
||||
public void setBearerToken(String bearerToken) {
|
||||
this.bearerToken = bearerToken;
|
||||
this.tokenSupplier = () -> bearerToken;
|
||||
}
|
||||
|
||||
public void setBearerToken(Supplier<String> tokenSupplier) {
|
||||
this.tokenSupplier = tokenSupplier;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyToParams(MultiValueMap<String, String> queryParams, HttpHeaders headerParams, MultiValueMap<String, String> cookieParams) {
|
||||
String bearerToken = Optional.ofNullable(tokenSupplier).map(Supplier::get).orElse(null);
|
||||
if (bearerToken == null) {
|
||||
return;
|
||||
}
|
||||
|
@ -51,6 +51,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.TimeZone;
|
||||
import java.util.function.Supplier;
|
||||
import java.time.OffsetDateTime;
|
||||
|
||||
import org.openapitools.client.auth.Authentication;
|
||||
|
@ -1,27 +1,34 @@
|
||||
package org.openapitools.client.auth;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.function.Supplier;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
|
||||
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen")
|
||||
public class HttpBearerAuth implements Authentication {
|
||||
private final String scheme;
|
||||
private String bearerToken;
|
||||
private Supplier<String> tokenSupplier;
|
||||
|
||||
public HttpBearerAuth(String scheme) {
|
||||
this.scheme = scheme;
|
||||
}
|
||||
|
||||
public String getBearerToken() {
|
||||
return bearerToken;
|
||||
return tokenSupplier.get();
|
||||
}
|
||||
|
||||
public void setBearerToken(String bearerToken) {
|
||||
this.bearerToken = bearerToken;
|
||||
this.tokenSupplier = () -> bearerToken;
|
||||
}
|
||||
|
||||
public void setBearerToken(Supplier<String> tokenSupplier) {
|
||||
this.tokenSupplier = tokenSupplier;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyToParams(MultiValueMap<String, String> queryParams, HttpHeaders headerParams, MultiValueMap<String, String> cookieParams) {
|
||||
String bearerToken = Optional.ofNullable(tokenSupplier).map(Supplier::get).orElse(null);
|
||||
if (bearerToken == null) {
|
||||
return;
|
||||
}
|
||||
|
@ -56,6 +56,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.TimeZone;
|
||||
import java.util.function.Supplier;
|
||||
import java.time.OffsetDateTime;
|
||||
|
||||
import org.openapitools.client.auth.Authentication;
|
||||
@ -170,9 +171,18 @@ public class ApiClient extends JavaTimeFormatter {
|
||||
* @param bearerToken the token
|
||||
*/
|
||||
public void setBearerToken(String bearerToken) {
|
||||
setBearerToken(() -> bearerToken);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to set the token supplier for HTTP 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(bearerToken);
|
||||
((HttpBearerAuth) auth).setBearerToken(tokenSupplier);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -1,27 +1,34 @@
|
||||
package org.openapitools.client.auth;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.function.Supplier;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
|
||||
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen")
|
||||
public class HttpBearerAuth implements Authentication {
|
||||
private final String scheme;
|
||||
private String bearerToken;
|
||||
private Supplier<String> tokenSupplier;
|
||||
|
||||
public HttpBearerAuth(String scheme) {
|
||||
this.scheme = scheme;
|
||||
}
|
||||
|
||||
public String getBearerToken() {
|
||||
return bearerToken;
|
||||
return tokenSupplier.get();
|
||||
}
|
||||
|
||||
public void setBearerToken(String bearerToken) {
|
||||
this.bearerToken = bearerToken;
|
||||
this.tokenSupplier = () -> bearerToken;
|
||||
}
|
||||
|
||||
public void setBearerToken(Supplier<String> tokenSupplier) {
|
||||
this.tokenSupplier = tokenSupplier;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyToParams(MultiValueMap<String, String> queryParams, HttpHeaders headerParams, MultiValueMap<String, String> cookieParams) {
|
||||
String bearerToken = Optional.ofNullable(tokenSupplier).map(Supplier::get).orElse(null);
|
||||
if (bearerToken == null) {
|
||||
return;
|
||||
}
|
||||
|
@ -51,6 +51,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.TimeZone;
|
||||
import java.util.function.Supplier;
|
||||
import java.time.OffsetDateTime;
|
||||
|
||||
import org.openapitools.client.auth.Authentication;
|
||||
@ -165,9 +166,18 @@ public class ApiClient extends JavaTimeFormatter {
|
||||
* @param bearerToken the token
|
||||
*/
|
||||
public void setBearerToken(String bearerToken) {
|
||||
setBearerToken(() -> bearerToken);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to set the token supplier for HTTP 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(bearerToken);
|
||||
((HttpBearerAuth) auth).setBearerToken(tokenSupplier);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -1,27 +1,34 @@
|
||||
package org.openapitools.client.auth;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.function.Supplier;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
|
||||
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen")
|
||||
public class HttpBearerAuth implements Authentication {
|
||||
private final String scheme;
|
||||
private String bearerToken;
|
||||
private Supplier<String> tokenSupplier;
|
||||
|
||||
public HttpBearerAuth(String scheme) {
|
||||
this.scheme = scheme;
|
||||
}
|
||||
|
||||
public String getBearerToken() {
|
||||
return bearerToken;
|
||||
return tokenSupplier.get();
|
||||
}
|
||||
|
||||
public void setBearerToken(String bearerToken) {
|
||||
this.bearerToken = bearerToken;
|
||||
this.tokenSupplier = () -> bearerToken;
|
||||
}
|
||||
|
||||
public void setBearerToken(Supplier<String> tokenSupplier) {
|
||||
this.tokenSupplier = tokenSupplier;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyToParams(MultiValueMap<String, String> queryParams, HttpHeaders headerParams, MultiValueMap<String, String> cookieParams) {
|
||||
String bearerToken = Optional.ofNullable(tokenSupplier).map(Supplier::get).orElse(null);
|
||||
if (bearerToken == null) {
|
||||
return;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user