Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge commit 'origin/master' into docs

  • Loading branch information...
commit 059df80b7e5a7727997639c1afb42375289d33d0 2 parents b0d8669 + a3dfdef
@bluehawk bluehawk authored
View
22 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
View
2  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
View
11 classes/kohana/oauth/provider.php
@@ -29,6 +29,11 @@ public static function factory($name, array $options = NULL)
}
/**
+ * @var string provider name
+ */
+ public $name;
+
+ /**
* @var array additional request parameters to be used for remote requests
*/
protected $params = array();
@@ -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_')));
+ }
}
/**
View
2  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()
View
2  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()
View
86 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);
@@ -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);
}
View
2  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
Please sign in to comment.
Something went wrong with that request. Please try again.