forked from loafle/openapi-generator-original
Instantiate HttpBearerToken authentications if so declared and add helper methods. (#2485)
This commit is contained in:
committed by
William Cheng
parent
1c1c1ef9c3
commit
7ab73ff587
@@ -44,13 +44,16 @@ public class ApiClient {
|
||||
for(String authName : authNames) {
|
||||
RequestInterceptor auth;
|
||||
if ("api_key".equals(authName)) {
|
||||
|
||||
auth = new ApiKeyAuth("header", "api_key");
|
||||
} else if ("api_key_query".equals(authName)) {
|
||||
|
||||
auth = new ApiKeyAuth("query", "api_key_query");
|
||||
} else if ("http_basic_test".equals(authName)) {
|
||||
|
||||
auth = new HttpBasicAuth();
|
||||
} else if ("petstore_auth".equals(authName)) {
|
||||
auth = new OAuth(OAuthFlow.implicit, "http://petstore.swagger.io/api/oauth/dialog", "", "write:pets, read:pets");
|
||||
} else if ("petstore_auth".equals(authName)) {
|
||||
auth = new OAuth(OAuthFlow.implicit, "http://petstore.swagger.io/api/oauth/dialog", "", "write:pets, read:pets");
|
||||
} else {
|
||||
throw new RuntimeException("auth name \"" + authName + "\" not found in available auth names");
|
||||
}
|
||||
@@ -196,6 +199,21 @@ public class ApiClient {
|
||||
return contentTypes[0];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Helper method to configure the bearer token.
|
||||
* @param bearerToken the bearer token.
|
||||
*/
|
||||
public void setBearerToken(String bearerToken) {
|
||||
for(RequestInterceptor apiAuthorization : apiAuthorizations.values()) {
|
||||
if (apiAuthorization instanceof HttpBearerAuth) {
|
||||
((HttpBearerAuth) apiAuthorization).setBearerToken(bearerToken);
|
||||
return;
|
||||
}
|
||||
}
|
||||
throw new RuntimeException("No Bearer authentication configured!");
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to configure the first api key found
|
||||
* @param apiKey API key
|
||||
|
||||
Reference in New Issue
Block a user