web/lib/Zend/Oauth/Client.php
changeset 807 877f952ae2bd
parent 207 621fa6caec0c
child 1230 68c69c656a2c
equal deleted inserted replaced
805:5e7a0fedabdf 807:877f952ae2bd
    12  * obtain it through the world-wide-web, please send an email
    12  * obtain it through the world-wide-web, please send an email
    13  * to license@zend.com so we can send you a copy immediately.
    13  * to license@zend.com so we can send you a copy immediately.
    14  *
    14  *
    15  * @category   Zend
    15  * @category   Zend
    16  * @package    Zend_Oauth
    16  * @package    Zend_Oauth
    17  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
    17  * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
    18  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    18  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    19  * @version    $Id: Client.php 23076 2010-10-10 21:37:20Z padraic $
    19  * @version    $Id: Client.php 25167 2012-12-19 16:28:01Z matthew $
    20  */
    20  */
    21 
    21 
    22 /** Zend_Oauth */
    22 /** Zend_Oauth */
    23 require_once 'Zend/Oauth.php';
    23 require_once 'Zend/Oauth.php';
    24 
    24 
    32 require_once 'Zend/Oauth/Config.php';
    32 require_once 'Zend/Oauth/Config.php';
    33 
    33 
    34 /**
    34 /**
    35  * @category   Zend
    35  * @category   Zend
    36  * @package    Zend_Oauth
    36  * @package    Zend_Oauth
    37  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
    37  * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
    38  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    38  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    39  */
    39  */
    40 class Zend_Oauth_Client extends Zend_Http_Client
    40 class Zend_Oauth_Client extends Zend_Http_Client
    41 {
    41 {
    42     /**
    42     /**
    67      * Constructor; creates a new HTTP Client instance which itself is
    67      * Constructor; creates a new HTTP Client instance which itself is
    68      * just a typical Zend_Http_Client subclass with some OAuth icing to
    68      * just a typical Zend_Http_Client subclass with some OAuth icing to
    69      * assist in automating OAuth parameter generation, addition and
    69      * assist in automating OAuth parameter generation, addition and
    70      * cryptographioc signing of requests.
    70      * cryptographioc signing of requests.
    71      *
    71      *
    72      * @param  array $oauthOptions
    72      * @param  array|Zend_Config $oauthOptions
    73      * @param  string $uri
    73      * @param  string            $uri
    74      * @param  array|Zend_Config $config
    74      * @param  array|Zend_Config $config
    75      * @return void
    75      * @return void
    76      */
    76      */
    77     public function __construct($oauthOptions, $uri = null, $config = null)
    77     public function __construct($oauthOptions, $uri = null, $config = null)
    78     {
    78     {
    79         if (!isset($config['rfc3986_strict'])) {
    79         if ($config instanceof Zend_Config && !isset($config->rfc3986_strict)) {
       
    80             $config                   = $config->toArray();
       
    81             $config['rfc3986_strict'] = true;
       
    82         } else if (null === $config ||
       
    83                    (is_array($config) && !isset($config['rfc3986_strict']))) {
    80             $config['rfc3986_strict'] = true;
    84             $config['rfc3986_strict'] = true;
    81         }
    85         }
    82         parent::__construct($uri, $config);
    86         parent::__construct($uri, $config);
    83         $this->_config = new Zend_Oauth_Config;
    87         $this->_config = new Zend_Oauth_Config;
    84         if ($oauthOptions !== null) {
    88         if ($oauthOptions !== null) {
    85             if ($oauthOptions instanceof Zend_Config) {
    89             if ($oauthOptions instanceof Zend_Config) {
    86                 $oauthOptions = $oauthOptions->toArray();
    90                 $oauthOptions = $oauthOptions->toArray();
    87             }
    91             }
    88             $this->_config->setOptions($oauthOptions);
    92             $this->_config->setOptions($oauthOptions);
    89         }
    93         }
    90     }
       
    91 
       
    92     /**
       
    93      * Return the current connection adapter
       
    94      *
       
    95      * @return Zend_Http_Client_Adapter_Interface|string $adapter
       
    96      */
       
    97     public function getAdapter()
       
    98     {
       
    99         return $this->adapter;
       
   100     }
    94     }
   101 
    95 
   102    /**
    96    /**
   103      * Load the connection adapter
    97      * Load the connection adapter
   104      *
    98      *
   200             $this->setRequestMethod(self::GET);
   194             $this->setRequestMethod(self::GET);
   201         } elseif($method == self::POST) {
   195         } elseif($method == self::POST) {
   202             $this->setRequestMethod(self::POST);
   196             $this->setRequestMethod(self::POST);
   203         } elseif($method == self::PUT) {
   197         } elseif($method == self::PUT) {
   204             $this->setRequestMethod(self::PUT);
   198             $this->setRequestMethod(self::PUT);
   205         }  elseif($method == self::DELETE) {
   199         } elseif($method == self::DELETE) {
   206             $this->setRequestMethod(self::DELETE);
   200             $this->setRequestMethod(self::DELETE);
   207         }   elseif($method == self::HEAD) {
   201         } elseif($method == self::HEAD) {
   208             $this->setRequestMethod(self::HEAD);
   202             $this->setRequestMethod(self::HEAD);
       
   203         } elseif($method == self::OPTIONS) {
       
   204             $this->setRequestMethod(self::OPTIONS);
   209         }
   205         }
   210         return parent::setMethod($method);
   206         return parent::setMethod($method);
   211     }
   207     }
   212 
   208 
   213     /**
   209     /**
   244         $query = null;
   240         $query = null;
   245         if ($requestScheme == Zend_Oauth::REQUEST_SCHEME_HEADER) {
   241         if ($requestScheme == Zend_Oauth::REQUEST_SCHEME_HEADER) {
   246             $oauthHeaderValue = $this->getToken()->toHeader(
   242             $oauthHeaderValue = $this->getToken()->toHeader(
   247                 $this->getUri(true),
   243                 $this->getUri(true),
   248                 $this->_config,
   244                 $this->_config,
   249                 $this->_getSignableParametersAsQueryString()
   245                 $this->_getSignableParametersAsQueryString(),
       
   246                 $this->getRealm()
   250             );
   247             );
   251             $this->setHeaders('Authorization', $oauthHeaderValue);
   248             $this->setHeaders('Authorization', $oauthHeaderValue);
   252         } elseif ($requestScheme == Zend_Oauth::REQUEST_SCHEME_POSTBODY) {
   249         } elseif ($requestScheme == Zend_Oauth::REQUEST_SCHEME_POSTBODY) {
   253             if ($requestMethod == self::GET) {
   250             if ($requestMethod == self::GET) {
   254                 require_once 'Zend/Oauth/Exception.php';
   251                 require_once 'Zend/Oauth/Exception.php';
   264                 $this->_getSignableParametersAsQueryString()
   261                 $this->_getSignableParametersAsQueryString()
   265             );
   262             );
   266             $this->setRawData($raw, 'application/x-www-form-urlencoded');
   263             $this->setRawData($raw, 'application/x-www-form-urlencoded');
   267             $this->paramsPost = array();
   264             $this->paramsPost = array();
   268         } elseif ($requestScheme == Zend_Oauth::REQUEST_SCHEME_QUERYSTRING) {
   265         } elseif ($requestScheme == Zend_Oauth::REQUEST_SCHEME_QUERYSTRING) {
   269             $params = array();
   266             $params = $this->paramsGet;            
   270             $query = $this->getUri()->getQuery();
   267             $query = $this->getUri()->getQuery();
   271             if ($query) {
   268             if ($query) {
   272                 $queryParts = explode('&', $this->getUri()->getQuery());
   269                 $queryParts = explode('&', $this->getUri()->getQuery());
   273                 foreach ($queryParts as $queryPart) {
   270                 foreach ($queryParts as $queryPart) {
   274                     $kvTuple = explode('=', $queryPart);
   271                     $kvTuple = explode('=', $queryPart);
   275                     $params[urldecode($kvTuple[0])] =
   272                     $params[urldecode($kvTuple[0])] =
   276                         (array_key_exists(1, $kvTuple) ? urldecode($kvTuple[1]) : NULL);
   273                         (array_key_exists(1, $kvTuple) ? urldecode($kvTuple[1]) : null);
   277                 }
   274                 }
   278             }
   275             }
   279             if (!empty($this->paramsPost)) {
   276             if (!empty($this->paramsPost)) {
   280                 $params = array_merge($params, $this->paramsPost);
   277                 $params = array_merge($params, $this->paramsPost);
   281                 $query  = $this->getToken()->toQueryString(
   278                 $query  = $this->getToken()->toQueryString(