コード例 #1
0
 /**
  * Get a signing key from a consumer and token.
  *
  *     $key = $signature->key($consumer, $token);
  *
  * [!!] This method implements the signing key of [OAuth 1.0 Spec 9](http://oauth.net/core/1.0/#rfc.section.9).
  *
  * @param   Consumer  consumer
  * @param   Token     token
  * @return string
  * @uses    OAuth::urlencode
  */
 public function key(Consumer $consumer, Token $token = null)
 {
     $key = OAuth::urlencode($consumer->secret) . '&';
     if ($token) {
         $key .= OAuth::urlencode($token->secret);
     }
     return $key;
 }
コード例 #2
0
 /**
  * Execute the request and return a response.
  *
  * @param   array    additional cURL options
  * @return string request response body
  * @uses    Request::check
  * @uses    Arr::get
  * @uses    Remote::get
  */
 public function execute(array $options = null)
 {
     // Check that all required fields are set
     $this->check();
     // Get the URL of the request
     $url = $this->url;
     if (!isset($options[CURLOPT_CONNECTTIMEOUT])) {
         // Use the request default timeout
         $options[CURLOPT_CONNECTTIMEOUT] = $this->timeout;
     }
     if ($this->send_header) {
         // Get the the current headers
         $headers = isset($options[CURLOPT_HTTPHEADER]) ? $options[CURLOPT_HTTPHEADER] : array();
         // Add the Authorization header
         $headers[] = 'Authorization: ' . $this->asHeader();
         // Store the new headers
         $options[CURLOPT_HTTPHEADER] = $headers;
     }
     if ($this->method === 'POST') {
         // Send the request as a POST
         $options[CURLOPT_POST] = true;
         if ($post = $this->asQuery(null, empty($this->upload))) {
             // Attach the post fields to the request
             $options[CURLOPT_POSTFIELDS] = $post;
         }
     } elseif ($query = $this->asQuery()) {
         // Append the parameters to the query string
         $url = "{$url}?{$query}";
     }
     return OAuth::remote($url, $options);
 }
コード例 #3
0
 /**
  * Parse the parameters in a string and return an array. Duplicates are
  * converted into indexed arrays.
  *
  *     // Parsed: array('a' => '1', 'b' => '2', 'c' => '3')
  *     $params = OAuth::parseParams('a=1,b=2,c=3');
  *
  *     // Parsed: array('a' => array('1', '2'), 'c' => '3')
  *     $params = OAuth::parseParams('a=1,a=2,c=3');
  *
  * @param   string  parameter string
  * @return array
  */
 public static function parseParams($params)
 {
     // Split the parameters by &
     $params = explode('&', trim($params));
     // Create an array of parsed parameters
     $parsed = array();
     foreach ($params as $param) {
         // Split the parameter into name and value
         list($name, $value) = explode('=', $param, 2);
         // Decode the name and value
         $name = OAuth::urldecode($name);
         $value = OAuth::urldecode($value);
         if (isset($parsed[$name])) {
             if (!is_array($parsed[$name])) {
                 // Convert the parameter to an array
                 $parsed[$name] = array($parsed[$name]);
             }
             // Add a new duplicate parameter
             $parsed[$name][] = $value;
         } else {
             // Add a new parameter
             $parsed[$name] = $value;
         }
     }
     return $parsed;
 }