Пример #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']);
         $integration = $this->integrationService->findByConsumerId($consumer->getId());
         $integration->setStatus(IntegrationModel::STATUS_ACTIVE);
         $integration->save();
     } catch (\Exception $exception) {
         $response = $this->helper->prepareErrorResponse($exception, $this->getResponse());
     }
     $this->getResponse()->setBody(http_build_query($response));
 }
 /**
  * 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());
         }
     }
 }
Пример #3
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');
 }
Пример #4
0
 /**
  * Test the basic Access action.
  */
 public function testAccessAction()
 {
     $this->request->expects($this->any())->method('getMethod')->willReturn('GET');
     $this->helperMock->expects($this->once())->method('getRequestUrl');
     $this->helperMock->expects($this->once())->method('prepareRequest');
     $this->frameworkOauthSvcMock->expects($this->once())->method('getAccessToken')->willReturn(['response']);
     /** @var \Magento\Integration\Model\Oauth\Consumer|\PHPUnit_Framework_MockObject_MockObject */
     $consumerMock = $this->getMock('Magento\\Integration\\Model\\Oauth\\Consumer', [], [], '', false);
     $consumerMock->expects($this->once())->method('getId');
     $this->intOauthServiceMock->expects($this->once())->method('loadConsumerByKey')->willReturn($consumerMock);
     /** @var \Magento\Integration\Model\Integration|\PHPUnit_Framework_MockObject_MockObject */
     $integrationMock = $this->getMock('Magento\\Integration\\Model\\Integration', [], [], '', false);
     $integrationMock->expects($this->once())->method('save')->willReturnSelf();
     $this->integrationServiceMock->expects($this->once())->method('findByConsumerId')->willReturn($integrationMock);
     $this->response->expects($this->once())->method('setBody');
     $this->accessAction->executeInternal();
 }