update auth for php to skip empty apikey/username,password

This commit is contained in:
wing328 2015-11-22 18:35:45 +08:00
parent c6021da8a1
commit e11a3d468e
5 changed files with 43 additions and 23 deletions

View File

@ -166,12 +166,18 @@ use \{{invokerPackage}}\ObjectSerializer;
$httpBody = $formParams; // for HTTP post (form) $httpBody = $formParams; // for HTTP post (form)
} }
{{#authMethods}}{{#isApiKey}} {{#authMethods}}{{#isApiKey}}
// this endpoint requires API key authentication
$apiKey = $this->apiClient->getApiKeyWithPrefix('{{keyParamName}}'); $apiKey = $this->apiClient->getApiKeyWithPrefix('{{keyParamName}}');
if (isset($apiKey)) { if ($apiKey !== null) {
{{#isKeyInHeader}}$headerParams['{{keyParamName}}'] = $apiKey;{{/isKeyInHeader}}{{#isKeyInQuery}}$queryParams['{{keyParamName}}'] = $apiKey;{{/isKeyInQuery}} {{#isKeyInHeader}}$headerParams['{{keyParamName}}'] = $apiKey;{{/isKeyInHeader}}{{#isKeyInQuery}}$queryParams['{{keyParamName}}'] = $apiKey;{{/isKeyInQuery}}
}{{/isApiKey}} }{{/isApiKey}}
{{#isBasic}}$headerParams['Authorization'] = 'Basic ' . base64_encode($this->apiClient->getConfig()->getUsername() . ":" . $this->apiClient->getConfig()->getPassword());{{/isBasic}} {{#isBasic}}// this endpoint requires HTTP basic authentication
{{#isOAuth}}$headerParams['Authorization'] = 'Bearer ' . $this->apiClient->getConfig()->getAccessToken();{{/isOAuth}} if ($this->apiClient->getConfig()->getUsername() !== null or $this->apiClient->getConfig()->getPassword() !== null) {
$headerParams['Authorization'] = 'Basic ' . base64_encode($this->apiClient->getConfig()->getUsername() . ":" . $this->apiClient->getConfig()->getPassword());
}{{/isBasic}}{{#isOAuth}}// this endpoint requires OAuth (access token)
if ($this->apiClient->getConfig()->getAccessToken() !== null) {
$headerParams['Authorization'] = 'Bearer ' . $this->apiClient->getConfig()->getAccessToken();
}{{/isOAuth}}
{{/authMethods}} {{/authMethods}}
// make the API Call // make the API Call
try try

View File

@ -135,8 +135,10 @@ class PetApi
$httpBody = $formParams; // for HTTP post (form) $httpBody = $formParams; // for HTTP post (form)
} }
// this endpoint requires OAuth (access token)
if ($this->apiClient->getConfig()->getAccessToken() !== null) {
$headerParams['Authorization'] = 'Bearer ' . $this->apiClient->getConfig()->getAccessToken(); $headerParams['Authorization'] = 'Bearer ' . $this->apiClient->getConfig()->getAccessToken();
}
// make the API Call // make the API Call
try try
@ -200,8 +202,10 @@ class PetApi
$httpBody = $formParams; // for HTTP post (form) $httpBody = $formParams; // for HTTP post (form)
} }
// this endpoint requires OAuth (access token)
if ($this->apiClient->getConfig()->getAccessToken() !== null) {
$headerParams['Authorization'] = 'Bearer ' . $this->apiClient->getConfig()->getAccessToken(); $headerParams['Authorization'] = 'Bearer ' . $this->apiClient->getConfig()->getAccessToken();
}
// make the API Call // make the API Call
try try
@ -264,8 +268,10 @@ class PetApi
$httpBody = $formParams; // for HTTP post (form) $httpBody = $formParams; // for HTTP post (form)
} }
// this endpoint requires OAuth (access token)
if ($this->apiClient->getConfig()->getAccessToken() !== null) {
$headerParams['Authorization'] = 'Bearer ' . $this->apiClient->getConfig()->getAccessToken(); $headerParams['Authorization'] = 'Bearer ' . $this->apiClient->getConfig()->getAccessToken();
}
// make the API Call // make the API Call
try try
@ -340,8 +346,10 @@ class PetApi
$httpBody = $formParams; // for HTTP post (form) $httpBody = $formParams; // for HTTP post (form)
} }
// this endpoint requires OAuth (access token)
if ($this->apiClient->getConfig()->getAccessToken() !== null) {
$headerParams['Authorization'] = 'Bearer ' . $this->apiClient->getConfig()->getAccessToken(); $headerParams['Authorization'] = 'Bearer ' . $this->apiClient->getConfig()->getAccessToken();
}
// make the API Call // make the API Call
try try
@ -424,13 +432,13 @@ class PetApi
$httpBody = $formParams; // for HTTP post (form) $httpBody = $formParams; // for HTTP post (form)
} }
// this endpoint requires API key authentication
$apiKey = $this->apiClient->getApiKeyWithPrefix('api_key'); $apiKey = $this->apiClient->getApiKeyWithPrefix('api_key');
if (isset($apiKey)) { if ($apiKey !== null) {
$headerParams['api_key'] = $apiKey; $headerParams['api_key'] = $apiKey;
} }
// make the API Call // make the API Call
try try
{ {
@ -526,8 +534,10 @@ class PetApi
$httpBody = $formParams; // for HTTP post (form) $httpBody = $formParams; // for HTTP post (form)
} }
// this endpoint requires OAuth (access token)
if ($this->apiClient->getConfig()->getAccessToken() !== null) {
$headerParams['Authorization'] = 'Bearer ' . $this->apiClient->getConfig()->getAccessToken(); $headerParams['Authorization'] = 'Bearer ' . $this->apiClient->getConfig()->getAccessToken();
}
// make the API Call // make the API Call
try try
@ -602,8 +612,10 @@ class PetApi
$httpBody = $formParams; // for HTTP post (form) $httpBody = $formParams; // for HTTP post (form)
} }
// this endpoint requires OAuth (access token)
if ($this->apiClient->getConfig()->getAccessToken() !== null) {
$headerParams['Authorization'] = 'Bearer ' . $this->apiClient->getConfig()->getAccessToken(); $headerParams['Authorization'] = 'Bearer ' . $this->apiClient->getConfig()->getAccessToken();
}
// make the API Call // make the API Call
try try
@ -694,8 +706,10 @@ class PetApi
$httpBody = $formParams; // for HTTP post (form) $httpBody = $formParams; // for HTTP post (form)
} }
// this endpoint requires OAuth (access token)
if ($this->apiClient->getConfig()->getAccessToken() !== null) {
$headerParams['Authorization'] = 'Bearer ' . $this->apiClient->getConfig()->getAccessToken(); $headerParams['Authorization'] = 'Bearer ' . $this->apiClient->getConfig()->getAccessToken();
}
// make the API Call // make the API Call
try try

View File

@ -130,13 +130,13 @@ class StoreApi
$httpBody = $formParams; // for HTTP post (form) $httpBody = $formParams; // for HTTP post (form)
} }
// this endpoint requires API key authentication
$apiKey = $this->apiClient->getApiKeyWithPrefix('api_key'); $apiKey = $this->apiClient->getApiKeyWithPrefix('api_key');
if (isset($apiKey)) { if ($apiKey !== null) {
$headerParams['api_key'] = $apiKey; $headerParams['api_key'] = $apiKey;
} }
// make the API Call // make the API Call
try try
{ {

View File

@ -69,7 +69,7 @@ class ApiClient
* Constructor of the class * Constructor of the class
* @param Configuration $config config for this ApiClient * @param Configuration $config config for this ApiClient
*/ */
function __construct(Configuration $config = null) public function __construct(Configuration $config = null)
{ {
if ($config == null) { if ($config == null) {
$config = Configuration::getDefaultConfiguration(); $config = Configuration::getDefaultConfiguration();

View File

@ -193,7 +193,7 @@ class ObjectSerializer
$deserialized = $values; $deserialized = $values;
} elseif ($class === '\DateTime') { } elseif ($class === '\DateTime') {
$deserialized = new \DateTime($data); $deserialized = new \DateTime($data);
} elseif (in_array($class, array('void', 'bool', 'string', 'double', 'byte', 'mixed', 'integer', 'float', 'int', 'DateTime', 'number', 'boolean', 'object'))) { } elseif (in_array($class, array('integer', 'int', 'void', 'number', 'object', 'double', 'float', 'byte', 'DateTime', 'string', 'mixed', 'boolean', 'bool'))) {
settype($data, $class); settype($data, $class);
$deserialized = $data; $deserialized = $data;
} elseif ($class === '\SplFileObject') { } elseif ($class === '\SplFileObject') {