Source for file Consumer.php
Documentation is available at Consumer.php
* Implementation of the OAuth specification
* LICENSE: This source file is subject to the New BSD license that is
* available through the world-wide-web at the following URI:
* http://www.opensource.org/licenses/bsd-license.php. If you did not receive
* a copy of the New BSD License and are unable to obtain it through the web,
* please send a note to license@php.net so we can mail you a copy immediately.
* @author Jeff Hodsdon <jeffhodsdon@gmail.com>
* @copyright 2009 Jeff Hodsdon <jeffhodsdon@gmail.com>
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
* @link http://pear.php.net/package/HTTP_OAuth
* @link http://github.com/jeffhodsdon/HTTP_OAuth
require_once 'HTTP/OAuth.php';
require_once 'HTTP/OAuth/Consumer/Request.php';
require_once 'HTTP/OAuth/Consumer/Exception/InvalidResponse.php';
* Main consumer class that assists consumers in establishing OAuth
* creditials and making OAuth requests.
* $consumer = new HTTP_OAuth_Consumer('key', 'secret');
* $consumer->getRequestToken('http://example.com/oauth/request_token, $callback);
* $_SESSION['token'] = $consumer->getToken();
* $_SESSION['token_secret'] = $consumer->getTokenSecret();
* $url = $consumer->getAuthorizationUrl('http://example.com/oauth/authorize');
* http_redirect($url); // function from pecl_http
* // When they come back via the $callback url
* $consumer = new HTTP_OAuth_Consumer('key', 'secret', $_SESSION['token'],
* $_SESSION['token_secret']);
* $consumer->getAccessToken('http://example.com/oauth/access_token');
* $_SESSION['token'] = $consumer->getToken();
* $_SESSION['token_secret'] = $consumer->getTokenSecret();
* // $response is an instance of HTTP_OAuth_Consumer_Response
* $response = $consumer->sendRequest('http://example.com/oauth/protected_resource');
* @author Jeff Hodsdon <jeffhodsdon@gmail.com>
* @copyright 2009 Jeff Hodsdon <jeffhodsdon@gmail.com>
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
* @link http://pear.php.net/package/HTTP_OAuth
* @link http://github.com/jeffhodsdon/HTTP_OAuth
* @var string $key Consumer key
* @var string $secret Consumer secret
* @var string Access/Request token
* @var string $tokenSecret Access/Request token secret
* @var string $signatureMethod Signature method
* Instance of HTTP_OAuth_Consumer_Request
* @see getOAuthConsumerRequest()
* @var HTTP_OAuth_Consumer_Request
* Instance of the last request made
* @var HTTP_OAuth_Consumer_Request $lastRequest The last request made
* @param string $key Consumer key
* @param string $secret Consumer secret
* @param string $token Access/Reqest token
* @param string $tokenSecret Access/Reqest token secret
public function __construct($key, $secret, $token = null , $tokenSecret = null )
* @param string $url Request token url
* @param string $callback Callback url
* @param array $additional Additional parameters to be in the request
* recommended in the spec.
* @param string $method HTTP method to use for the request
* @throws HTTP_OAuth_Consumer_Exception_InvalidResponse Missing token/secret
array $additional = array (), $method = 'POST'
$this->debug('Getting request token from ' . $url);
$additional['oauth_callback'] = $callback;
$this->debug('callback: ' . $callback);
$response = $this->sendRequest($url, $additional, $method);
$data = $response->getDataFromBody ();
if (empty ($data['oauth_token']) || empty ($data['oauth_token_secret'])) {
'Failed getting token and token secret from response', $response
* @param string $url Access token url
* @param string $verifier OAuth verifier from the provider
* @param array $additional Additional parameters to be in the request
* recommended in the spec.
* @param string $method HTTP method to use for the request
* @return array Token and token secret
* @throws HTTP_OAuth_Consumer_Exception_InvalidResponse Mising token/secret
array $additional = array (), $method = 'POST'
$this->debug('Getting access token from ' . $url);
$additional['oauth_verifier'] = $verifier;
$this->debug('verifier: ' . $verifier);
$response = $this->sendRequest($url, $additional, $method);
$data = $response->getDataFromBody ();
if (empty ($data['oauth_token']) || empty ($data['oauth_token_secret'])) {
'Failed getting token and token secret from response', $response
* @param string $url Authorization url
* @param array $additional Additional parameters for the auth url
* @return string Authorization url
$params = array ('oauth_token' => $this->getToken());
* @param string $url URL of the protected resource
* @param array $additional Additional parameters
* @param string $method HTTP method to use
* @return HTTP_OAuth_Consumer_Response Instance of a response class
public function sendRequest($url, array $additional = array (), $method = 'POST')
'oauth_consumer_key' => $this->key,
$params['oauth_token'] = $this->getToken();
$req->setMethod ($method);
$req->setParameters ($params);
* @return string Consumer key
* @return string Consumer secret
* @param string $token Request/Access token
$this->debug('token is now: ' . $token);
* @return string Accessoken secret
* @param string $secret Token secret
$this->debug('token_secret is now: ' . $secret);
* @return string Signature method
* @param string $method Signature method to use
* @return array Array possible secrets
* Accepts a custom instance of HTTP_OAuth_Consumer_Request.
* @param HTTP_OAuth_Consumer_Request $object Custom instance
* @see getOAuthConsumerRequest()
public function accept($object)
case 'HTTP_OAuth_Consumer_Request':
* Gets instance of HTTP_OAuth_Consumer_Request
* @return HTTP_OAuth_Consumer_Request
* @return null|HTTP_OAuth_Consumer_RequestInstance of the last request
* @see self::sendRequest()
Documentation generated on Mon, 30 Nov 2009 23:00:04 +0000 by phpDocumentor 1.4.3. PEAR Logo Copyright © PHP Group 2004.
|