Example #1
0
 /**
  * Initiate AccessToken request operation
  *
  * @return void
  */
 public function execute()
 {
     try {
         $requestUrl = $this->_helper->getRequestUrl($this->getRequest());
         $request = $this->_helper->prepareRequest($this->getRequest(), $requestUrl);
         // Request access token in exchange of a pre-authorized token
         $response = $this->_oauthService->getAccessToken($request, $requestUrl, $this->getRequest()->getMethod());
         //After sending the access token, update the integration status to active;
         $consumer = $this->_intOauthService->loadConsumerByKey($request['oauth_consumer_key']);
         $this->_integrationService->findByConsumerId($consumer->getId())->setStatus(IntegrationModel::STATUS_ACTIVE)->save();
     } catch (\Exception $exception) {
         $response = $this->_helper->prepareErrorResponse($exception, $this->getResponse());
     }
     $this->getResponse()->setBody(http_build_query($response));
 }
Example #2
0
 public function testPostToConsumer()
 {
     $consumerId = 1;
     $key = $this->_generateRandomString(\Magento\Framework\Oauth\Helper\Oauth::LENGTH_CONSUMER_KEY);
     $secret = $this->_generateRandomString(\Magento\Framework\Oauth\Helper\Oauth::LENGTH_CONSUMER_SECRET);
     $oauthVerifier = $this->_generateRandomString(\Magento\Framework\Oauth\Helper\Oauth::LENGTH_TOKEN_VERIFIER);
     $consumerData = ['entity_id' => $consumerId, 'key' => $key, 'secret' => $secret];
     $this->_consumerMock->expects($this->once())->method('load')->with($this->equalTo($consumerId))->will($this->returnSelf());
     $this->_consumerMock->expects($this->once())->method('getId')->will($this->returnValue($consumerId));
     $this->_consumerMock->expects($this->once())->method('getData')->will($this->returnValue($consumerData));
     $this->_httpClientMock->expects($this->once())->method('setUri')->with('http://www.magento.com')->will($this->returnSelf());
     $this->_httpClientMock->expects($this->once())->method('setParameterPost')->will($this->returnSelf());
     $this->_tokenMock->expects($this->once())->method('createVerifierToken')->with($consumerId)->will($this->returnSelf());
     $this->_tokenMock->expects($this->any())->method('getVerifier')->will($this->returnValue($oauthVerifier));
     $this->_dataHelper->expects($this->once())->method('getConsumerPostMaxRedirects')->will($this->returnValue(5));
     $this->_dataHelper->expects($this->once())->method('getConsumerPostTimeout')->will($this->returnValue(120));
     $verifier = $this->_oauthService->postToConsumer($consumerId, 'http://www.magento.com');
     $this->assertEquals($oauthVerifier, $verifier, 'Checking Oauth Verifier');
 }
Example #3
0
 /**
  * Add oAuth token and token secret.
  *
  * @param IntegrationModel $integration
  * @return void
  */
 protected function _addOauthTokenData(IntegrationModel $integration)
 {
     if ($integration->getId()) {
         $accessToken = $this->_oauthService->getAccessToken($integration->getConsumerId());
         if ($accessToken) {
             $integration->setData('token', $accessToken->getToken());
             $integration->setData('token_secret', $accessToken->getSecret());
         }
     }
 }