コード例 #1
0
 /**
  * {@inheritdoc}
  */
 public function buildAuthorizationHeader($params, $requestUrl, $signatureMethod = self::SIGNATURE_SHA1, $httpMethod = 'POST')
 {
     $required = array("oauth_consumer_key", "oauth_consumer_secret", "oauth_token", "oauth_token_secret");
     $this->_checkRequiredParams($params, $required);
     $consumer = $this->_tokenProvider->getConsumerByKey($params['oauth_consumer_key']);
     $headerParameters = array('oauth_nonce' => $this->_nonceGenerator->generateNonce($consumer), 'oauth_timestamp' => $this->_nonceGenerator->generateTimestamp(), 'oauth_version' => '1.0');
     $headerParameters = array_merge($headerParameters, $params);
     $headerParameters['oauth_signature'] = $this->_httpUtility->sign($params, $signatureMethod, $headerParameters['oauth_consumer_secret'], $headerParameters['oauth_token_secret'], $httpMethod, $requestUrl);
     $authorizationHeader = $this->_httpUtility->toAuthorizationHeader($headerParameters);
     // toAuthorizationHeader adds an optional realm="" which is not required for now.
     // http://tools.ietf.org/html/rfc2617#section-1.2
     return str_replace('realm="",', '', $authorizationHeader);
 }
コード例 #2
0
 /**
  * Test two legged authentication
  */
 public function testAuthenticateTwoLegged()
 {
     $testUserKey = 'foo_user';
     $testUserSecret = 'bar_secret';
     $testUrl = 'http://foo.bar/api/rest/v1/baz';
     // Prepare signature and oAuth parameters
     $utility = new Zend_Oauth_Http_Utility();
     $params = array('oauth_consumer_key' => $testUserKey, 'oauth_nonce' => $utility->generateNonce(), 'oauth_timestamp' => $utility->generateTimestamp(), 'oauth_version' => '1.0', 'oauth_signature_method' => Mage_Oauth_Model_Server::SIGNATURE_PLAIN);
     $params['oauth_signature'] = $utility->sign($params, Mage_Oauth_Model_Server::SIGNATURE_PLAIN, $testUserSecret, '', 'GET', $testUrl);
     $authHeader = $utility->toAuthorizationHeader($params);
     $this->_requestMock->expects($this->at(0))->method('getHeader')->with('Authorization')->will($this->returnValue($authHeader));
     $this->_requestMock->expects($this->at(1))->method('getHeader')->with(Zend_Http_Client::CONTENT_TYPE)->will($this->returnValue('application/json'));
     $this->_requestMock->expects($this->any())->method('getScheme')->with()->will($this->returnValue(Zend_Controller_Request_Http::SCHEME_HTTP));
     $this->_requestMock->expects($this->any())->method('getHttpHost')->with()->will($this->returnValue('foo.bar'));
     $this->_requestMock->expects($this->any())->method('getRequestUri')->with()->will($this->returnValue('/api/rest/v1/baz'));
     $userMock = $this->getMockBuilder('Mage_Webapi_Model_Acl_User')->setMethods(array('loadByKey', 'getId', 'getSecret'))->disableOriginalConstructor()->getMock();
     $this->_consumerFactoryMock->expects($this->once())->method('create')->will($this->returnValue($userMock));
     $userMock->expects($this->once())->method('loadByKey')->with($testUserKey)->will($this->returnSelf());
     $userMock->expects($this->once())->method('getId')->with()->will($this->returnValue(1));
     $userMock->expects($this->once())->method('getSecret')->with()->will($this->returnValue($testUserSecret));
     $this->assertEquals($userMock, $this->_server->authenticateTwoLegged());
 }
コード例 #3
0
ファイル: Pro.php プロジェクト: grrr-amsterdam/garp3
 /**
  * Send a request
  * @param String $method Methodname
  * @param Array $queryParams GET parameters
  * @return Array
  */
 public function request($method, array $queryParams)
 {
     $queryParams['format'] = self::RESPONSE_FORMAT;
     if (!substr($method, 0, 5) != 'vimeo') {
         $method = 'vimeo.' . $method;
     }
     $queryParams['method'] = $method;
     $queryString = http_build_query($queryParams);
     $url = self::VIMEO_API_URL . '?' . $queryString;
     $oAuthHttpUtility = new Zend_Oauth_Http_Utility();
     $params = array('oauth_consumer_key' => $this->getConsumerKey(), 'oauth_nonce' => $oAuthHttpUtility->generateNonce(), 'oauth_timestamp' => $oAuthHttpUtility->generateTimestamp(), 'oauth_signature_method' => 'HMAC-SHA1', 'oauth_version' => '1.0');
     if ($this->getAccessToken()) {
         $params['oauth_token'] = $this->getAccessToken();
     }
     $params['oauth_signature'] = $oAuthHttpUtility->sign(array_merge($queryParams, $params), 'HMAC-SHA1', $this->getConsumerSecret(), $this->getAccessTokenSecret(), Zend_Oauth::GET, self::VIMEO_API_URL);
     $httpClient = $this->getHttpClient()->setHeaders('Authorization', $oAuthHttpUtility->toAuthorizationHeader($params))->setMethod(Zend_Http_Client::GET)->setUri($url);
     $response = $httpClient->request()->getBody();
     $response = json_decode($response, true);
     if ($response['stat'] == 'fail') {
         $error = 'An unknown error occurred at Vimeo.';
         if (!empty($response['err']['expl'])) {
             $error = $response['err']['expl'];
         }
         throw new Garp_Service_Vimeo_Exception($response['err']['expl']);
     }
     return $response;
 }