diff --git a/classes/kohana/oauth.php b/classes/kohana/oauth.php index a5e5e44..505ca95 100755 --- a/classes/kohana/oauth.php +++ b/classes/kohana/oauth.php @@ -3,7 +3,7 @@ * OAuth Library * * @package Kohana/OAuth - * @package Base + * @category Base * @author Kohana Team * @copyright (c) 2010 Kohana Team * @license http://kohanaframework.org/license @@ -86,8 +86,14 @@ public static function urldecode($input) * @return string * @uses OAuth::urlencode */ - public static function normalize_params(array $params) + public static function normalize_params(array $params = NULL) { + if ( ! $params) + { + // Nothing to do + return ''; + } + // Encode the parameter keys and values $keys = OAuth::urlencode(array_keys($params)); $values = OAuth::urlencode(array_values($params)); @@ -124,18 +130,6 @@ public static function normalize_params(array $params) return implode('&', $query); } - public static function normalize_post(array $params) - { - $query = array(); - - foreach ($params as $field => $value) - { - $query[] = $field.'='.$value; - } - - return implode('&', $query); - } - /** * Parse the query string out of the URL and return it as parameters. * All GET parameters must be removed from the request URL when building diff --git a/classes/kohana/oauth/consumer.php b/classes/kohana/oauth/consumer.php index 47b31f8..f8791da 100755 --- a/classes/kohana/oauth/consumer.php +++ b/classes/kohana/oauth/consumer.php @@ -3,7 +3,7 @@ * OAuth Consumer * * @package Kohana/OAuth - * @package Base + * @category Base * @author Kohana Team * @copyright (c) 2010 Kohana Team * @license http://kohanaframework.org/license diff --git a/classes/kohana/oauth/provider.php b/classes/kohana/oauth/provider.php index a13dfb3..d1ebbd1 100644 --- a/classes/kohana/oauth/provider.php +++ b/classes/kohana/oauth/provider.php @@ -28,6 +28,11 @@ public static function factory($name, array $options = NULL) return new $class($options); } + /** + * @var string provider name + */ + public $name; + /** * @var array additional request parameters to be used for remote requests */ @@ -58,6 +63,12 @@ public function __construct(array $options = NULL) // Convert the signature name into an object $this->signature = OAuth_Signature::factory($this->signature); } + + if ( ! $this->name) + { + // Attempt to guess the name from the class name + $this->name = strtolower(substr(get_class($this), strlen('OAuth_Provider_'))); + } } /** diff --git a/classes/kohana/oauth/provider/google.php b/classes/kohana/oauth/provider/google.php index f3e0c6f..609f252 100644 --- a/classes/kohana/oauth/provider/google.php +++ b/classes/kohana/oauth/provider/google.php @@ -19,6 +19,8 @@ */ class Kohana_OAuth_Provider_Google extends OAuth_Provider { + public $name = 'google'; + protected $signature = 'HMAC-SHA1'; public function url_request_token() diff --git a/classes/kohana/oauth/provider/twitter.php b/classes/kohana/oauth/provider/twitter.php index a2b6638..46fa52d 100644 --- a/classes/kohana/oauth/provider/twitter.php +++ b/classes/kohana/oauth/provider/twitter.php @@ -17,6 +17,8 @@ */ class Kohana_OAuth_Provider_Twitter extends OAuth_Provider { + public $name = 'twitter'; + protected $signature = 'HMAC-SHA1'; public function url_request_token() diff --git a/classes/kohana/oauth/request.php b/classes/kohana/oauth/request.php index ac3288c..bfaaf5c 100755 --- a/classes/kohana/oauth/request.php +++ b/classes/kohana/oauth/request.php @@ -64,11 +64,6 @@ public static function factory($type, $method, $url = NULL, array $params = NULL */ protected $required = array(); - /** - * @var array POST body - */ - protected $post = array(); - /** * Set the request URL, method, and parameters. * @@ -179,7 +174,6 @@ public function nonce() * @param OAuth_Request request to sign * @return string * @uses OAuth::urlencode - * @uses OAuth::normalize_post * @uses OAuth::normalize_params */ public function base_string() @@ -189,12 +183,6 @@ public function base_string() // Get the request parameters $params = $this->params; - if ($this->post) - { - // Add the POST fields to the parameters - $params += $this->post; - } - // "oauth_signature" is never included in the base string! unset($params['oauth_signature']); @@ -281,30 +269,6 @@ public function params(array $params, $duplicate = FALSE) return $this; } - /** - * Get and set POST fields. Adding a value will cause the request to be - * sent with the HTTP POST method. - * - * $request->post($field, $value); - * - * @param string field name - * @param string field value - * @return string when getting - * @return $this when setting - * @uses Arr::get - */ - public function post($field, $value = NULL) - { - if (func_num_args() < 2) - { - return Arr::get($this->post, $field); - } - - $this->post[$field] = $value; - - return $this; - } - /** * Get and set required parameters. * @@ -343,9 +307,12 @@ public function as_header() foreach ($this->params as $name => $value) { - // OAuth Spec 5.4.1 - // "Parameter names and values are encoded per Parameter Encoding [RFC 3986]." - $header[] = OAuth::urlencode($name).'="'.OAuth::urlencode($value).'"'; + if (strpos($name, 'oauth_') === 0) + { + // OAuth Spec 5.4.1 + // "Parameter names and values are encoded per Parameter Encoding [RFC 3986]." + $header[] = OAuth::urlencode($name).'="'.OAuth::urlencode($value).'"'; + } } return 'OAuth '.implode(', ', $header); @@ -359,11 +326,32 @@ public function as_header() * * [!!] This method implements [OAuth 1.0 Spec 5.2 (2,3)](http://oauth.net/core/1.0/#rfc.section.5.2). * + * @param boolean include oauth parameters * @return string */ - public function as_query() + public function as_query($include_oauth = NULL) { - return OAuth::normalize_params($this->params); + if ($include_oauth !== TRUE AND $this->send_header) + { + // If we are sending a header, OAuth parameters should not be + // included in the query string. + + $params = array(); + foreach ($this->params as $name => $value) + { + if (strpos($name, 'oauth_') !== 0) + { + // This is not an OAuth parameter + $params[$name] = $value; + } + } + } + else + { + $params = $this->params; + } + + return OAuth::normalize_params($params); } /** @@ -376,7 +364,7 @@ public function as_query() */ public function as_url() { - return $this->url.'?'.$this->as_query(); + return $this->url.'?'.$this->as_query(TRUE); } /** @@ -466,23 +454,23 @@ public function execute(array $options = NULL) // Store the new headers $options[CURLOPT_HTTPHEADER] = $headers; } - elseif ($query = $this->as_query()) - { - // Append the parameters to the query string - $url = "{$url}?{$query}"; - } if ($this->method === 'POST') { // Send the request as a POST $options[CURLOPT_POST] = TRUE; - if ($this->post) + if ($post = $this->as_query()) { // Attach the post fields to the request - $options[CURLOPT_POSTFIELDS] = OAuth::normalize_post($this->post); + $options[CURLOPT_POSTFIELDS] = $post; } } + elseif ($query = $this->as_query()) + { + // Append the parameters to the query string + $url = "{$url}?{$query}"; + } return Remote::get($url, $options); } diff --git a/classes/kohana/oauth/response.php b/classes/kohana/oauth/response.php index 668004b..1fa1db7 100755 --- a/classes/kohana/oauth/response.php +++ b/classes/kohana/oauth/response.php @@ -3,7 +3,7 @@ * OAuth Response * * @package Kohana/OAuth - * @package Base + * @category Base * @author Kohana Team * @copyright (c) 2010 Kohana Team * @license http://kohanaframework.org/license