Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixing the handling of GET and POST combined with header, removed OAu…

…th_Request::post (use ::param instead), and removed OAuth::normalize_post (use ::normalize_params)
  • Loading branch information...
commit b3c6e83a9a0c04ee0c45dd0ffa98ca1d0dd97fc8 1 parent 91c004e
@shadowhand shadowhand authored
Showing with 41 additions and 60 deletions.
  1. +7 −13 classes/kohana/oauth.php
  2. +34 −47 classes/kohana/oauth/request.php
View
20 classes/kohana/oauth.php
@@ -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
View
81 classes/kohana/oauth/request.php
@@ -65,11 +65,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.
*
* @param string request method
@@ -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']);
@@ -282,30 +270,6 @@ public function params(array $params, $duplicate = FALSE)
}
/**
- * 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.
*
* $request->required($field, $value);
@@ -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);
@@ -363,7 +330,27 @@ public function as_header()
*/
public function as_query()
{
- return OAuth::normalize_params($this->params);
+ if ($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);
}
/**
@@ -466,23 +453,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);
}
Please sign in to comment.
Something went wrong with that request. Please try again.