add oauth support for php

This commit is contained in:
wing328 2015-10-27 19:22:25 +08:00
parent 2e6199ac3b
commit 67815ed5f2
4 changed files with 42 additions and 9 deletions

View File

@ -333,6 +333,9 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig {
// Note: backslash ("\\") is allowed for e.g. "\\DateTime"
name = name.replaceAll("[^\\w\\\\]+", "_");
// remove dollar sign
name = name.replaceAll("$", "");
// model name cannot use reserved keyword
if (reservedWords.contains(name)) {
escapeReservedWord(name); // e.g. return => _return

View File

@ -170,8 +170,8 @@ use \{{invokerPackage}}\ObjectSerializer;
if (isset($apiKey)) {
{{#isKeyInHeader}}$headerParams['{{keyParamName}}'] = $apiKey;{{/isKeyInHeader}}{{#isKeyInQuery}}$queryParams['{{keyParamName}}'] = $apiKey;{{/isKeyInQuery}}
}{{/isApiKey}}
{{#isBasic}}$headerParams['Authorization'] = 'Basic '.base64_encode($this->apiClient->getConfig()->getUsername().":".$this->apiClient->getConfig()->getPassword());{{/isBasic}}
{{#isOAuth}}//TODO support oauth{{/isOAuth}}
{{#isBasic}}$headerParams['Authorization'] = 'Basic ' . base64_encode($this->apiClient->getConfig()->getUsername(). ":" .$this->apiClient->getConfig()->getPassword());{{/isBasic}}
{{#isOAuth}}$headerParams['Authorization'] = 'Bearer ' . $this->apiClient->getConfig()->getAuthToken();{{/isOAuth}}
{{/authMethods}}
// make the API Call
try

View File

@ -63,6 +63,13 @@ class Configuration
*/
protected $apiKeyPrefixes = array();
/**
* Token for OAuth
*
* @var string
*/
protected $authToken = '';
/**
* Username for HTTP basic authentication
*
@ -195,6 +202,29 @@ class Configuration
return isset($this->apiKeyPrefixes[$apiKeyIdentifier]) ? $this->apiKeyPrefixes[$apiKeyIdentifier] : null;
}
/**
* Sets the token for OAuth
*
* @param string $authToken Token for OAuth
*
* @return Configuration
*/
public function setAuthToken($authToken)
{
$this->$authToken = $authToken;
return $this;
}
/**
* Gets the token for OAuth
*
* @return string Token for OAuth
*/
public function getAuthToken()
{
return $this->authToken;
}
/**
* Sets the username for HTTP basic authentication
*

View File

@ -136,7 +136,7 @@ class PetApi
}
//TODO support oauth
$headerParams['Authorization'] = 'Bearer ' . $this->apiClient->getConfig()->getAuthToken();
// make the API Call
try
@ -201,7 +201,7 @@ class PetApi
}
//TODO support oauth
$headerParams['Authorization'] = 'Bearer ' . $this->apiClient->getConfig()->getAuthToken();
// make the API Call
try
@ -265,7 +265,7 @@ class PetApi
}
//TODO support oauth
$headerParams['Authorization'] = 'Bearer ' . $this->apiClient->getConfig()->getAuthToken();
// make the API Call
try
@ -341,7 +341,7 @@ class PetApi
}
//TODO support oauth
$headerParams['Authorization'] = 'Bearer ' . $this->apiClient->getConfig()->getAuthToken();
// make the API Call
try
@ -527,7 +527,7 @@ class PetApi
}
//TODO support oauth
$headerParams['Authorization'] = 'Bearer ' . $this->apiClient->getConfig()->getAuthToken();
// make the API Call
try
@ -603,7 +603,7 @@ class PetApi
}
//TODO support oauth
$headerParams['Authorization'] = 'Bearer ' . $this->apiClient->getConfig()->getAuthToken();
// make the API Call
try
@ -695,7 +695,7 @@ class PetApi
}
//TODO support oauth
$headerParams['Authorization'] = 'Bearer ' . $this->apiClient->getConfig()->getAuthToken();
// make the API Call
try