_oauthHelper = $oauthHelper; $this->_nonceFactory = $nonceFactory; $this->_date = $date; $this->_nonceLength = $nonceLength; } /** * {@inheritdoc} */ public function generateNonce(ConsumerInterface $consumer = null) { return $this->_oauthHelper->generateRandomString($this->_nonceLength); } /** * {@inheritdoc} */ public function generateTimestamp() { return $this->_date->timestamp(); } /** * {@inheritdoc} */ public function validateNonce(ConsumerInterface $consumer, $nonce, $timestamp) { try { $timestamp = (int)$timestamp; if ($timestamp <= 0 || $timestamp > time() + self::TIME_DEVIATION) { throw new \Magento\Framework\Oauth\OauthInputException( __('Incorrect timestamp value in the oauth_timestamp parameter') ); } /** @var \Magento\Integration\Model\Oauth\Nonce $nonceObj */ $nonceObj = $this->_nonceFactory->create()->loadByCompositeKey($nonce, $consumer->getId()); if ($nonceObj->getNonce()) { throw new \Magento\Framework\Oauth\Exception( __( 'The nonce is already being used by the consumer with ID %1', [$consumer->getId()] ) ); } $nonceObj->setNonce($nonce)->setConsumerId($consumer->getId())->setTimestamp($timestamp)->save(); } catch (\Magento\Framework\Oauth\Exception $exception) { throw $exception; } catch (\Exception $exception) { throw new \Magento\Framework\Oauth\Exception(__('An error occurred validating the nonce')); } } }