mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-12-07 12:16:10 +00:00
Instantiate HttpBearerToken authentications if so declared and add helper methods. (#2485)
This commit is contained in:
committed by
William Cheng
parent
1c1c1ef9c3
commit
7ab73ff587
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user