public function arrayToAccessToken(array $accessTokenArray)
 {
     $accessToken = new AccessToken();
     $accessToken->setToken($accessTokenArray['token']);
     $accessToken->setTokenSecret($accessTokenArray['tokenSecret']);
     return $accessToken;
 }
Beispiel #2
0
 public function testOAuthClientDoesntOverrideExistingHeaders()
 {
     $mock = $this->getMock('ZendOAuth\\Http\\Utility', array('generateTimestamp', 'generateNonce'));
     $mock->expects($this->once())->method('generateTimestamp')->will($this->returnValue('123456789'));
     $mock->expects($this->once())->method('generateNonce')->will($this->returnValue('67648c83ba9a7de429bd1b773fb96091'));
     $token = new Token\Access(null, $mock);
     $token->setToken('123')->setTokenSecret('456');
     $client = new OAuthClient(array('token' => $token), 'http://www.example.com');
     $dummyHeader = Header\ContentType::fromString('Content-Type: application/octet-stream');
     $headers = $client->getRequest()->getHeaders();
     $headers->addHeaders(array($dummyHeader));
     $client->prepareOAuth();
     $this->assertTrue($client->getRequest()->getHeaders()->has('Content-Type'));
     $this->assertEquals($dummyHeader, $client->getRequest()->getHeaders()->get('Content-Type'));
 }
Beispiel #3
0
 public function getToken()
 {
     $token = new AccessToken();
     $token->setToken('abcde');
     return $token;
 }
Beispiel #4
0
 /**
  * Constructor
  *
  * @param  null|array|Traversable $options
  * @param  null|OAuth\Consumer $consumer
  * @param  null|Http\Client $httpClient
  */
 public function __construct($options = null, OAuth\Consumer $consumer = null, Http\Client $httpClient = null)
 {
     if ($options instanceof Traversable) {
         $options = ArrayUtils::iteratorToArray($options);
     }
     if (!is_array($options)) {
         $options = array();
     }
     $this->options = $options;
     if (isset($options['username'])) {
         $this->setUsername($options['username']);
     }
     $accessToken = false;
     if (isset($options['accessToken'])) {
         $accessToken = $options['accessToken'];
     } elseif (isset($options['access_token'])) {
         $accessToken = $options['access_token'];
     }
     $oauthOptions = array();
     if (isset($options['oauthOptions'])) {
         $oauthOptions = $options['oauthOptions'];
     } elseif (isset($options['oauth_options'])) {
         $oauthOptions = $options['oauth_options'];
     }
     $oauthOptions['siteUrl'] = static::OAUTH_BASE_URI;
     $httpClientOptions = array();
     if (isset($options['httpClientOptions'])) {
         $httpClientOptions = $options['httpClientOptions'];
     } elseif (isset($options['http_client_options'])) {
         $httpClientOptions = $options['http_client_options'];
     }
     // If we have an OAuth access token, use the HTTP client it provides
     if ($accessToken && is_array($accessToken) && (isset($accessToken['token']) && isset($accessToken['secret']))) {
         $token = new OAuth\Token\Access();
         $token->setToken($accessToken['token']);
         $token->setTokenSecret($accessToken['secret']);
         $accessToken = $token;
     }
     if ($accessToken && $accessToken instanceof OAuth\Token\Access) {
         $oauthOptions['token'] = $accessToken;
         $this->setHttpClient($accessToken->getHttpClient($oauthOptions, static::OAUTH_BASE_URI, $httpClientOptions));
         return;
     }
     // See if we were passed an http client
     if (isset($options['httpClient']) && null === $httpClient) {
         $httpClient = $options['httpClient'];
     } elseif (isset($options['http_client']) && null === $httpClient) {
         $httpClient = $options['http_client'];
     }
     if ($httpClient instanceof Http\Client) {
         $this->httpClient = $httpClient;
     } else {
         $this->setHttpClient(new Http\Client(null, $httpClientOptions));
     }
     // Set the OAuth consumer
     if ($consumer === null) {
         $consumer = new OAuth\Consumer($oauthOptions);
     }
     $this->oauthConsumer = $consumer;
 }