Beispiel #1
0
 /**
  * {@inheritDoc}
  */
 public function buildSignature(Request $request, Consumer $consumer, Token $token = null)
 {
     $signatureBase = $request->getSignatureBaseString();
     $parts = [$consumer->secret, null !== $token ? $token->secret : ""];
     $parts = Util::urlencodeRfc3986($parts);
     $key = implode('&', $parts);
     return base64_encode(hash_hmac('sha1', $signatureBase, $key, true));
 }
Beispiel #2
0
 /**
  * pretty much a helper function to set up the request
  *
  * @param Consumer $consumer
  * @param Token    $token
  * @param string   $httpMethod
  * @param string   $httpUrl
  * @param array    $parameters
  *
  * @return Request
  */
 public static function fromConsumerAndToken(Consumer $consumer, Token $token = null, $httpMethod, $httpUrl, array $parameters = [])
 {
     $defaults = ["oauth_version" => Request::$version, "oauth_nonce" => Request::generateNonce(), "oauth_timestamp" => time(), "oauth_consumer_key" => $consumer->key];
     if (null !== $token) {
         $defaults['oauth_token'] = $token->key;
     }
     $parameters = array_merge($defaults, $parameters);
     return new Request($httpMethod, $httpUrl, $parameters);
 }
Beispiel #3
0
 /**
  * Format and sign an OAuth / API request
  *
  * @param string $url
  * @param string $method
  * @param array  $parameters
  *
  * @return string
  * @throws TwitterOAuthException
  */
 private function oAuthRequest($url, $method, array $parameters)
 {
     $request = Request::fromConsumerAndToken($this->consumer, $this->token, $method, $url, $parameters);
     if (array_key_exists('oauth_callback', $parameters)) {
         // Twitter doesn't like oauth_callback as a parameter.
         unset($parameters['oauth_callback']);
     }
     if ($this->bearer === null) {
         $request->signRequest($this->signatureMethod, $this->consumer, $this->token);
         $authorization = $request->toHeader();
     } else {
         $authorization = 'Authorization: Bearer ' . $this->bearer;
     }
     return $this->request($request->getNormalizedHttpUrl(), $method, $authorization, $parameters);
 }