Instantiate HttpBearerToken authentications if so declared and add helper methods. (#2485)

This commit is contained in:
davidwcarlson
2019-03-26 23:07:43 -07:00
committed by William Cheng
parent 1c1c1ef9c3
commit 7ab73ff587
19 changed files with 300 additions and 21 deletions

View File

@@ -60,6 +60,7 @@ import java.util.TimeZone;
import org.openapitools.client.auth.Authentication;
import org.openapitools.client.auth.HttpBasicAuth;
import org.openapitools.client.auth.HttpBearerAuth;
import org.openapitools.client.auth.ApiKeyAuth;
import org.openapitools.client.auth.OAuth;
@@ -178,6 +179,20 @@ public class ApiClient {
return authentications.get(authName);
}
/**
* Helper method to set token for HTTP bearer authentication.
* @param bearerToken the token
*/
public void setBearerToken(String bearerToken) {
for (Authentication auth : authentications.values()) {
if (auth instanceof HttpBearerAuth) {
((HttpBearerAuth) auth).setBearerToken(bearerToken);
return;
}
}
throw new RuntimeException("No Bearer authentication configured!");
}
/**
* Helper method to set username for the first HTTP basic authentication.
* @param username the username