Example #1
0
 /**
  * pretty much a helper function to set up the request
  */
 public static function from_consumer_and_token($consumer, $token, $http_method, $http_url, $parameters = NULL)
 {
     $parameters = $parameters ? $parameters : array();
     $defaults = array("oauth_version" => Sputnik_OAuth_Request::$version, "oauth_nonce" => Sputnik_OAuth_Request::generate_nonce(), "oauth_timestamp" => Sputnik_OAuth_Request::generate_timestamp(), "oauth_consumer_key" => $consumer->key);
     if ($token) {
         $defaults['oauth_token'] = $token->key;
     }
     $parameters = array_merge($defaults, $parameters);
     return new Sputnik_OAuth_Request($http_method, $http_url, $parameters);
 }
Example #2
0
 /**
  * Format and sign an OAuth / API request
  */
 public function get_auth_header($url, $method = 'GET', $parameters = array())
 {
     if (strpos($url, 'http') !== 0) {
         $url = Sputnik::API_BASE . $url;
     }
     $request = Sputnik_OAuth_Request::from_consumer_and_token($this->consumer, $this->token, $method, $url, $parameters);
     $request->sign_request($this->sha1_method, $this->consumer, $this->token);
     $header = $request->to_header($this->sha1_method, $this->consumer, $this->token);
     // We want to remove the 'Authorization' bit from the start
     return substr($header, 15);
 }
Example #3
0
 /**
  * Format and sign an OAuth / API request
  *
  * @internal Converted OAuth* to Sputnik_OAuth_*
  */
 function oAuthRequest($url, $method, $parameters)
 {
     if (strrpos($url, 'https://') !== 0 && strrpos($url, 'http://') !== 0) {
         $url = "{$this->host}{$url}.{$this->format}";
     }
     $request = Sputnik_OAuth_Request::from_consumer_and_token($this->consumer, $this->token, $method, $url, $parameters);
     $request->sign_request($this->sha1_method, $this->consumer, $this->token);
     switch ($method) {
         case 'GET':
             return $this->http($request->to_url(), 'GET');
         default:
             return $this->http($request->get_normalized_http_url(), $method, $request->to_postdata());
     }
 }