Exemple #1
0
 /**
  * oauth_signature is set to the concatenated encoded values of the Consumer Secret and
  * Token Secret, separated by a '&' character (ASCII code 38), even if either secret is
  * empty. The result MUST be encoded again.
  *   - Chapter 9.4.1 ("Generating Signatures")
  *
  * Please note that the second encoding MUST NOT happen in the SignatureMethod, as
  * OAuthRequest handles this!
  */
 public function build_signature($request, $consumer, $token)
 {
     $key_parts = array($consumer->secret, $token ? $token->secret : "");
     $key_parts = TwitterUtils::urlencode_rfc3986($key_parts);
     $key = implode('&', $key_parts);
     $request->base_string = $key;
     return $key;
 }
Exemple #2
0
 public function build_signature($request, $consumer, $token)
 {
     $base_string = $request->get_signature_base_string();
     $request->base_string = $base_string;
     $key_parts = array($consumer->secret, $token ? $token->secret : "");
     $key_parts = TwitterUtils::urlencode_rfc3986($key_parts);
     $key = implode('&', $key_parts);
     return base64_encode(hash_hmac('sha1', $base_string, $key, true));
 }
 /**
  * builds the Authorization: header
  */
 public function to_header($realm = null)
 {
     $first = true;
     if ($realm) {
         $out = 'Authorization: OAuth realm="' . TwitterUtils::urlencode_rfc3986($realm) . '"';
         $first = false;
     } else {
         $out = 'Authorization: OAuth';
     }
     foreach ($this->parameters as $k => $v) {
         if (substr($k, 0, 5) != "oauth") {
             continue;
         }
         if (is_array($v)) {
             throw new TwitterException('Arrays not supported in headers');
         }
         $out .= $first ? ' ' : ',';
         $out .= TwitterUtils::urlencode_rfc3986($k) . '="' . TwitterUtils::urlencode_rfc3986($v) . '"';
         $first = false;
     }
     return $out;
 }
 /**
  * generates the basic string serialization of a token that a server
  * would respond to request_token and access_token calls with
  */
 function to_string()
 {
     return "oauth_token=" . TwitterUtils::urlencode_rfc3986($this->key) . "&oauth_token_secret=" . TwitterUtils::urlencode_rfc3986($this->secret);
 }
 /**
  * One time exchange of username and password for access token and secret.
  *
  * @returns array("oauth_token" => "the-access-token",
  *                "oauth_token_secret" => "the-access-secret",
  *                "user_id" => "9436992",
  *                "screen_name" => "abraham",
  *                "x_auth_expires" => "0")
  */
 function getXAuthToken($username, $password)
 {
     $parameters = array();
     $parameters['x_auth_username'] = $username;
     $parameters['x_auth_password'] = $password;
     $parameters['x_auth_mode'] = 'client_auth';
     $request = $this->oAuthRequest($this->accessTokenURL(), 'POST', $parameters);
     $token = TwitterUtils::parse_parameters($request);
     $this->token = new TwitterConsumer($token['oauth_token'], $token['oauth_token_secret']);
     return $token;
 }