39 \Psr\Log\LoggerInterface
$logger 41 $this->_consumerFactory = $consumerFactory;
42 $this->_tokenFactory = $tokenFactory;
52 if (!$consumer->isValidForTokenExchange()) {
53 throw new \Magento\Framework\Oauth\Exception(
54 __(
'Consumer key has expired')
65 $token = $this->getIntegrationTokenByConsumerId($consumer->getId());
67 throw new \Magento\Framework\Oauth\Exception(
68 __(
'Cannot create request token because consumer token is not a verifier token')
71 $requestToken =
$token->createRequestToken(
$token->getId(), $consumer->getCallbackUrl());
72 return [
'oauth_token' => $requestToken->getToken(),
'oauth_token_secret' => $requestToken->getSecret()];
83 throw new \Magento\Framework\Oauth\Exception(
84 __(
'Request token is not associated with the specified consumer')
91 throw new \Magento\Framework\Oauth\Exception(
92 __(
'Token is already being used')
98 return $token->getSecret();
106 $consumerId = $consumer->getId();
107 $token = $this->getIntegrationTokenByConsumerId($consumerId);
109 throw new \Magento\Framework\Oauth\Exception(
110 __(
'Cannot get access token because consumer token is not a request token')
113 $accessToken =
$token->convertToAccess();
115 'Request token ' .
$token->getToken() .
' was exchanged to obtain access token for consumer ' . $consumerId
117 return [
'oauth_token' => $accessToken->getToken(),
'oauth_token_secret' => $accessToken->getSecret()];
128 throw new \Magento\Framework\Oauth\Exception(
129 __(
'Token is not associated with the specified consumer')
133 throw new \Magento\Framework\Oauth\Exception(
134 __(
'Token is not an access token')
137 if (
$token->getRevoked()) {
138 throw new \Magento\Framework\Oauth\Exception(
139 __(
'Access token has been revoked')
143 return $token->getSecret();
156 throw new \Magento\Framework\Oauth\Exception(
157 __(
'Token is not an access token')
161 if (
$token->getRevoked()) {
162 throw new \Magento\Framework\Oauth\Exception(
163 __(
'Access token has been revoked')
167 return $token->getConsumerId();
183 if (strlen($consumerKey) != \
Magento\Framework\Oauth\Helper\Oauth::LENGTH_CONSUMER_KEY) {
184 throw new \Magento\Framework\Oauth\Exception(
185 __(
'Consumer key is not the correct length')
189 $consumer = $this->_consumerFactory->create()->loadByKey($consumerKey);
191 if (!$consumer->getId()) {
192 throw new \Magento\Framework\Oauth\Exception(
193 __(
'A consumer having the specified key does not exist')
210 if (!is_string($oauthVerifier)) {
211 throw new \Magento\Framework\Oauth\Exception(
212 __(
'Verifier is invalid')
216 throw new \Magento\Framework\Oauth\Exception(
217 __(
'Verifier is not the correct length')
220 if (!Security::compareStrings($tokenVerifier, $oauthVerifier)) {
221 throw new \Magento\Framework\Oauth\Exception(
222 __(
'Token verifier and verifier token do not match')
236 $consumer = $this->_consumerFactory->create()->load($consumerId);
238 if (!$consumer->getId()) {
239 throw new \Magento\Framework\Oauth\Exception(
241 'A consumer with the ID %1 does not exist',
260 throw new \Magento\Framework\Oauth\Exception(
261 __(
'The token length is invalid. Check the length and try again.')
265 $tokenObj = $this->_tokenFactory->create()->load(
$token,
'token');
267 if (!$tokenObj->getId()) {
268 throw new \Magento\Framework\Oauth\Exception(
269 __(
'Specified token does not exist')
283 public function getIntegrationTokenByConsumerId($consumerId)
286 $token = $this->_tokenFactory->create();
290 throw new \Magento\Framework\Oauth\Exception(
292 'A token with consumer ID %1 does not exist',
310 return $token->getConsumerId() == $consumer->getId();
getAccessToken($consumer)
validateConsumer($consumer)
_validateVerifierParam($oauthVerifier, $tokenVerifier)
__construct(\Magento\Integration\Model\Oauth\ConsumerFactory $consumerFactory, \Magento\Integration\Model\Oauth\TokenFactory $tokenFactory, \Psr\Log\LoggerInterface $logger)
createRequestToken($consumer)
validateAccessTokenRequest($accessToken, $consumer)
_isTokenAssociatedToConsumer($token, $consumer)
validateRequestToken($requestToken, $consumer, $oauthVerifier)
validateAccessToken($accessToken)
getConsumerByKey($consumerKey)
const USER_TYPE_INTEGRATION
validateOauthToken($oauthToken)
_getConsumer($consumerId)