From c062c3baad513d418dc78e08d43a9ae8f1986ec9 Mon Sep 17 00:00:00 2001 From: "brunobg@corollarium.com" Date: Wed, 24 Nov 2010 13:23:07 +0000 Subject: [PATCH] New patch for issue 83, dealing with oauth_token and signing --- library/OAuthRequest.php | 7 ++++--- library/OAuthRequestSigner.php | 8 ++++---- library/OAuthRequester.php | 6 +++--- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/library/OAuthRequest.php b/library/OAuthRequest.php index f126067..1caffee 100644 --- a/library/OAuthRequest.php +++ b/library/OAuthRequest.php @@ -174,6 +174,7 @@ function signatureBaseString () * * @param string consumer_secret * @param string token_secret + * @param string token_type * @exception when not all parts available * @return string */ @@ -186,11 +187,11 @@ function calculateSignature ( $consumer_secret, $token_secret, $token_type = 'ac 'oauth_nonce' ); - /* removed as per in issue 83 - if ($token_type !== false) + // removed as per in issue 83 + if ($token_type != 'request') { $required[] = 'oauth_token'; - } */ + } foreach ($required as $req) { diff --git a/library/OAuthRequestSigner.php b/library/OAuthRequestSigner.php index 0ed54f7..93a0beb 100644 --- a/library/OAuthRequestSigner.php +++ b/library/OAuthRequestSigner.php @@ -102,7 +102,7 @@ function setUnsigned () * @exception OAuthException2 when there is no oauth relation with the server * @exception OAuthException2 when we don't support the signing methods of the server */ - function sign ( $usr_id = 0, $secrets = null, $name = '' ) + function sign ( $usr_id = 0, $secrets = null, $name = '', $token_type = null) { $url = $this->getRequestUrl(); if (empty($secrets)) @@ -128,8 +128,8 @@ function sign ( $usr_id = 0, $secrets = null, $name = '' ) $this->setParam('oauth_signature', ''); $this->setParam('oauth_nonce', !empty($secrets['nonce']) ? $secrets['nonce'] : uniqid('')); $this->setParam('oauth_timestamp', !empty($secrets['timestamp']) ? $secrets['timestamp'] : time()); - // removed as mentioned in issue 83 - // $this->setParam('oauth_token', $token); + if ($oauth_token != 'request') + $this->setParam('oauth_token', $token); $this->setParam('oauth_consumer_key', $secrets['consumer_key']); $this->setParam('oauth_version', '1.0'); @@ -141,7 +141,7 @@ function sign ( $usr_id = 0, $secrets = null, $name = '' ) $this->setParam('xoauth_body_signature', $body_signature, true); } - $signature = $this->calculateSignature($secrets['consumer_secret'], $token_secret); + $signature = $this->calculateSignature($secrets['consumer_secret'], $token_secret, $token_type); $this->setParam('oauth_signature', $signature, true); $this->signed = true; diff --git a/library/OAuthRequester.php b/library/OAuthRequester.php index 8649de3..ee0ce0c 100644 --- a/library/OAuthRequester.php +++ b/library/OAuthRequester.php @@ -109,7 +109,7 @@ function doRequest ( $usr_id = 0, $curl_options = array(), $options = array() ) $this->setBody($body); $curl_options = $this->prepareCurlOptions($curl_options, $extra_headers); } - $this->sign($usr_id, null, $name); + $this->sign($usr_id, null, $name, 'request'); $text = $this->curl_raw($curl_options); $result = $this->curl_parse($text); if ($result['code'] >= 400) @@ -156,7 +156,7 @@ static function requestRequestToken ( $consumer_key, $usr_id, $params = null, $m $uri = $r['request_token_uri']; $oauth = new OAuthRequester($uri, $method, $params); - $oauth->sign($usr_id, $r); + $oauth->sign($usr_id, $r, '', 'request'); $text = $oauth->curl_raw($curl_options); if (empty($text)) @@ -245,7 +245,7 @@ static function requestAccessToken ( $consumer_key, $token, $usr_id, $method = ' OAuthRequestLogger::setRequestObject($oauth); - $oauth->sign($usr_id, $r); + $oauth->sign($usr_id, $r, '', 'access'); $text = $oauth->curl_raw($curl_options); if (empty($text)) {