/**
  * {@inheritdoc}
  */
 public function generate(OAuthRequest $request, $consumerSecret, $tokenSecret = null)
 {
     if (($privateKey = openssl_pkey_get_private($this->getPrivateCertificate())) === false) {
         throw new \RuntimeException('The certificate private key cannot be fetched.');
     }
     if (openssl_sign($request->getSignature(), $signature, $privateKey) === false) {
         // @codeCoverageIgnoreStart
         throw new \RuntimeException('The signature cannot be generated.');
         // @codeCoverageIgnoreEnd
     }
     openssl_free_key($privateKey);
     return base64_encode($signature);
 }
示例#2
0
 /**
  * Creates an OAuth request according to the current request.
  *
  * @return \Widop\Twitter\OAuth\OAuthRequest The OAuth request.
  */
 public function createOAuthRequest()
 {
     $this->validateOptionBag($this->optionBag);
     $request = new OAuthRequest();
     $request->setPath($this->getPath());
     $request->setMethod($this->getMethod());
     foreach ($this->optionBag as $option) {
         if (!$option->hasValue()) {
             continue;
         }
         switch ($option->getType()) {
             case OptionInterface::TYPE_PATH:
                 $request->setPathParameter(':' . $option->getName(), $option->getNormalizedValue());
                 break;
             case OptionInterface::TYPE_GET:
                 $request->setGetParameter($option->getName(), $option->getNormalizedValue());
                 break;
             case OptionInterface::TYPE_POST:
                 $request->setPostParameter($option->getName(), $option->getNormalizedValue());
                 break;
             case OptionInterface::TYPE_FILE:
                 $request->setFileParameter($option->getName() . '[]', $option->getNormalizedValue());
                 break;
         }
     }
     return $request;
 }
示例#3
0
 public function testSignatureWithFileParameters()
 {
     $this->request->setBaseUrl('https://api.twitter.com/oauth');
     $this->request->setPath('/statuses/show.json');
     $this->request->setMethod('POST');
     $this->request->setOAuthParameters(array('oauth_nonce' => 'abcde', 'oauth_timestamp' => '1380373886', 'oauth_version' => '1.0', 'oauth_token' => 'oauth_token'));
     $this->request->setFileParameter('file', __FILE__);
     $this->assertSame('POST&https%3A%2F%2Fapi.twitter.com%2Foauth%2Fstatuses%2Fshow.json&oauth_nonce%3Dabcde%26oauth_timestamp%3D1380373886%26oauth_token%3Doauth_token%26oauth_version%3D1.0', $this->request->getSignature());
 }
示例#4
0
 /**
  * {@inheritdoc}
  */
 public function signRequest(OAuthRequest $request, OAuth $oauth)
 {
     $request->setOAuthParameter('oauth_version', $oauth->getVersion());
     $request->setOAuthParameter('oauth_consumer_key', $oauth->getConsumer()->getKey());
     $request->setOAuthParameter('oauth_signature_method', $oauth->getSignature()->getName());
     if ($this->getKey() !== null) {
         $request->setOAuthParameter('oauth_token', $this->getKey());
     }
     $request->setOAuthParameter('oauth_signature', $oauth->getSignature()->generate($request, $oauth->getConsumer()->getSecret(), $this->getSecret()));
     $authorization = array();
     foreach ($request->getOAuthParameters() as $key => $value) {
         $authorization[] = sprintf('%s="%s"', $key, $value);
     }
     $request->setHeader('Authorization', sprintf('OAuth %s', implode(', ', $authorization)));
 }
示例#5
0
 /**
  * Creates an OAuth request.
  *
  * @param string $path           The OAuth path.
  * @param string $responseFormat The response format.
  *
  * @return \Widop\Twitter\OAuth\OAuthRequest The OAuth request.
  */
 private function createRequest($path, $responseFormat = OAuthResponse::FORMAT_JSON)
 {
     $request = new OAuthRequest();
     $request->setBaseUrl($this->getUrl());
     $request->setPath($path);
     $request->setMethod(OAuthRequest::METHOD_POST);
     $request->setResponseFormat($responseFormat);
     return $request;
 }
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     $this->request = $this->getMock('Widop\\Twitter\\OAuth\\OAuthRequest');
     $this->request->expects($this->any())->method('getSignature')->will($this->returnValue('signature'));
     $this->signature = new OAuthPlaintextSignature();
 }
示例#7
0
 /**
  * {@inheritdoc}
  */
 public function signRequest(OAuthRequest $request, OAuth $oauth)
 {
     $request->setHeader('Authorization', sprintf('Bearer %s', $this->getValue()));
 }
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     $this->request = $this->getMock('Widop\\Twitter\\OAuth\\OAuthRequest');
     $this->request->expects($this->any())->method('getSignature')->will($this->returnValue('signature'));
     $this->signature = $this->getMockForAbstractClass('Widop\\Twitter\\OAuth\\Signature\\AbstractOAuthRsaSha1Signature');
 }
 /**
  * {@inheritdoc}
  */
 public function generate(OAuthRequest $request, $consumerSecret, $tokenSecret = null)
 {
     return base64_encode(hash_hmac('sha1', $request->getSignature(), rawurlencode($consumerSecret) . '&' . rawurlencode($tokenSecret), true));
 }
示例#10
0
 /**
  * {@inheritdoc}
  */
 public function signRequest(OAuthRequest $request, OAuth $oauth)
 {
     $request->setHeader('Authorization', sprintf('Basic %s', base64_encode(rawurlencode($oauth->getConsumer()->getKey()) . ':' . rawurlencode($oauth->getConsumer()->getSecret()))));
 }