예제 #1
0
 /**
  * {@inheritdoc}
  */
 public function postToConsumer($consumerId, $endpointUrl)
 {
     try {
         $consumer = $this->_consumerFactory->create()->load($consumerId);
         if (!$consumer->getId()) {
             throw new \Magento\Framework\Oauth\Exception(__('A consumer with ID %1 does not exist', $consumerId), OauthInterface::ERR_PARAMETER_REJECTED);
         }
         $consumerData = $consumer->getData();
         $verifier = $this->_tokenFactory->create()->createVerifierToken($consumerId);
         $storeBaseUrl = $this->_storeManager->getStore()->getBaseUrl();
         $this->_httpClient->setUri($endpointUrl);
         $this->_httpClient->setParameterPost(array('oauth_consumer_key' => $consumerData['key'], 'oauth_consumer_secret' => $consumerData['secret'], 'store_base_url' => $storeBaseUrl, 'oauth_verifier' => $verifier->getVerifier()));
         $maxredirects = $this->_dataHelper->getConsumerPostMaxRedirects();
         $timeout = $this->_dataHelper->getConsumerPostTimeout();
         $this->_httpClient->setConfig(array('maxredirects' => $maxredirects, 'timeout' => $timeout));
         $this->_httpClient->request(\Magento\Framework\HTTP\ZendClient::POST);
         return $verifier->getVerifier();
     } catch (\Magento\Framework\Model\Exception $exception) {
         throw $exception;
     } catch (\Magento\Framework\Oauth\Exception $exception) {
         throw $exception;
     } catch (\Exception $exception) {
         $this->_logger->logException($exception);
         throw new \Magento\Framework\Oauth\Exception('Unable to post data to consumer due to an unexpected error');
     }
 }
예제 #2
0
 /**
  * Load token object given a consumer Id.
  *
  * @param int $consumerId - The Id of the consumer.
  * @return \Magento\Integration\Model\Oauth\Token
  * @throws \Magento\Framework\Oauth\Exception
  */
 public function getTokenByConsumerId($consumerId)
 {
     $token = $this->_tokenFactory->create()->load($consumerId, 'consumer_id');
     if (!$token->getId()) {
         throw new \Magento\Framework\Oauth\Exception('A token with consumer ID %1 does not exist', [$consumerId]);
     }
     return $token;
 }
예제 #3
0
파일: Provider.php 프로젝트: aiesh/magento2
 /**
  * Load token object and validate it.
  *
  * @param string $token
  * @return Token
  * @throws \Magento\Framework\Oauth\Exception
  */
 protected function _getToken($token)
 {
     if (!$this->validateOauthToken($token)) {
         throw new \Magento\Framework\Oauth\Exception('Token is not the correct length');
     }
     $tokenObj = $this->_tokenFactory->create()->load($token, 'token');
     if (!$tokenObj->getId()) {
         throw new \Magento\Framework\Oauth\Exception('Specified token does not exist');
     }
     return $tokenObj;
 }
예제 #4
0
 /**
  * {@inheritdoc}
  */
 public function createAdminAccessToken($username, $password)
 {
     $this->validatorHelper->validateCredentials($username, $password);
     try {
         $this->userModel->login($username, $password);
         if (!$this->userModel->getId()) {
             /*
              * This message is same as one thrown in \Magento\Backend\Model\Auth to keep the behavior consistent.
              * Constant cannot be created in Auth Model since it uses legacy translation that doesn't support it.
              * Need to make sure that this is refactored once exception handling is updated in Auth Model.
              */
             throw new AuthenticationException('Please correct the user name or password.');
         }
     } catch (\Magento\Backend\Model\Auth\Exception $e) {
         throw new AuthenticationException($e->getMessage(), [], $e);
     } catch (\Magento\Framework\Model\Exception $e) {
         throw new LocalizedException($e->getMessage(), [], $e);
     }
     return $this->tokenModelFactory->create()->createAdminToken($this->userModel->getId())->getToken();
 }
예제 #5
0
 /**
  * {@inheritdoc}
  */
 public function createCustomerAccessToken($username, $password)
 {
     $this->validateCredentials($username, $password);
     $customerDataObject = $this->customerAccountService->authenticate($username, $password);
     return $this->tokenModelFactory->create()->createCustomerToken($customerDataObject->getId())->getToken();
 }