Example #1
0
 /**
  * Validate data
  *
  * @return bool
  * @throws OauthException Throw exception on fail validation
  */
 public function validate()
 {
     if (OauthHelper::CALLBACK_ESTABLISHED != $this->getCallbackUrl() && !$this->_urlValidator->isValid($this->getCallbackUrl())) {
         $messages = $this->_urlValidator->getMessages();
         throw new OauthException(__(array_shift($messages)));
     }
     /** @var $validatorLength \Magento\Integration\Model\Oauth\Consumer\Validator\KeyLength */
     $validatorLength = $this->_keyLengthFactory->create();
     $validatorLength->setLength(OauthHelper::LENGTH_TOKEN_SECRET);
     $validatorLength->setName('Token Secret Key');
     if (!$validatorLength->isValid($this->getSecret())) {
         $messages = $validatorLength->getMessages();
         throw new OauthException(__(array_shift($messages)));
     }
     $validatorLength->setLength(OauthHelper::LENGTH_TOKEN);
     $validatorLength->setName('Token Key');
     if (!$validatorLength->isValid($this->getToken())) {
         $messages = $validatorLength->getMessages();
         throw new OauthException(__(array_shift($messages)));
     }
     if (null !== ($verifier = $this->getVerifier())) {
         $validatorLength->setLength(OauthHelper::LENGTH_TOKEN_VERIFIER);
         $validatorLength->setName('Verifier Key');
         if (!$validatorLength->isValid($verifier)) {
             $messages = $validatorLength->getMessages();
             throw new OauthException(__(array_shift($messages)));
         }
     }
     return true;
 }
Example #2
0
 /**
  * {@inheritdoc}
  */
 public function validate()
 {
     if ($this->getCallbackUrl() || $this->getRejectedCallbackUrl()) {
         $this->setCallbackUrl(trim($this->getCallbackUrl()));
         $this->setRejectedCallbackUrl(trim($this->getRejectedCallbackUrl()));
         if ($this->getCallbackUrl() && !$this->_urlValidator->isValid($this->getCallbackUrl())) {
             throw new \Magento\Framework\Exception\LocalizedException(__('Invalid Callback URL'));
         }
         if ($this->getRejectedCallbackUrl() && !$this->_urlValidator->isValid($this->getRejectedCallbackUrl())) {
             throw new \Magento\Framework\Exception\LocalizedException(__('Invalid Rejected Callback URL'));
         }
     }
     /** @var $validatorLength \Magento\Integration\Model\Oauth\Consumer\Validator\KeyLength */
     $validatorLength = $this->_keyLengthFactory->create(['options' => ['length' => \Magento\Framework\Oauth\Helper\Oauth::LENGTH_CONSUMER_KEY]]);
     $validatorLength->setName('Consumer Key');
     if (!$validatorLength->isValid($this->getKey())) {
         $messages = $validatorLength->getMessages();
         throw new \Magento\Framework\Exception\LocalizedException(__(array_shift($messages)));
     }
     $validatorLength->setLength(\Magento\Framework\Oauth\Helper\Oauth::LENGTH_CONSUMER_SECRET);
     $validatorLength->setName('Consumer Secret');
     if (!$validatorLength->isValid($this->getSecret())) {
         $messages = $validatorLength->getMessages();
         throw new \Magento\Framework\Exception\LocalizedException(__(array_shift($messages)));
     }
     return true;
 }