Merge pull request #1446 from wing328/php_improvement1

[PHP] add OAuth support
This commit is contained in:
wing328 2015-10-31 22:46:52 +08:00
commit 7bc523324d
5 changed files with 72 additions and 9 deletions

View File

@ -334,6 +334,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()->getAccessToken();{{/isOAuth}}
{{/authMethods}}
// make the API Call
try

View File

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

View File

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

View File

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