1515
1616import software .xdev .sessionize .client .Pair ;
1717
18- import java .util .Map ;
1918import java .util .List ;
19+ import java .util .Map ;
20+ import java .util .Optional ;
21+ import java .util .function .Supplier ;
2022
2123@ jakarta .annotation .Generated (value = "org.openapitools.codegen.languages.JavaClientCodegen" )
2224public class HttpBearerAuth implements Authentication {
2325 private final String scheme ;
24- private String bearerToken ;
26+ private Supplier < String > tokenSupplier ;
2527
2628 public HttpBearerAuth (String scheme ) {
2729 this .scheme = scheme ;
@@ -33,7 +35,7 @@ public HttpBearerAuth(String scheme) {
3335 * @return The bearer token
3436 */
3537 public String getBearerToken () {
36- return bearerToken ;
38+ return tokenSupplier . get () ;
3739 }
3840
3941 /**
@@ -42,12 +44,22 @@ public String getBearerToken() {
4244 * @param bearerToken The bearer token to send in the Authorization header
4345 */
4446 public void setBearerToken (String bearerToken ) {
45- this .bearerToken = bearerToken ;
47+ this .tokenSupplier = () -> bearerToken ;
48+ }
49+
50+ /**
51+ * Sets the supplier of tokens, which together with the scheme, will be sent as the value of the Authorization header.
52+ *
53+ * @param tokenSupplier The supplier of bearer tokens to send in the Authorization header
54+ */
55+ public void setBearerToken (Supplier <String > tokenSupplier ) {
56+ this .tokenSupplier = tokenSupplier ;
4657 }
4758
4859 @ Override
4960 public void applyToParams (List <Pair > queryParams , Map <String , String > headerParams , Map <String , String > cookieParams ) {
50- if (bearerToken == null ) {
61+ String bearerToken = Optional .ofNullable (tokenSupplier ).map (Supplier ::get ).orElse (null );
62+ if (bearerToken == null ) {
5163 return ;
5264 }
5365
0 commit comments