/** * @expectedException \Magento\Framework\Oauth\Exception * @expectedExceptionMessage Cannot get access token because consumer token is not a request token */ public function testGetAccessTokenIsNotRequestToken() { $consumerId = 1; $tokenId = 1; $this->consumerMock->expects($this->once())->method('getId')->willReturn($consumerId); $this->requestTokenMock->expects($this->once())->method('loadByConsumerIdAndUserType')->with($consumerId, UserContextInterface::USER_TYPE_INTEGRATION); $this->tokenFactoryMock->expects($this->once())->method('create')->willReturn($this->requestTokenMock); $this->requestTokenMock->expects($this->once())->method('getId')->willReturn($tokenId); $this->requestTokenMock->expects($this->once())->method('getType')->willReturn('isNotRequestToken'); $this->tokenProvider->getAccessToken($this->consumerMock); }
/** * {@inheritdoc} */ public function createAccessToken($consumerId, $clearExistingToken = false) { try { $consumer = $this->_consumerFactory->create()->load($consumerId); $existingToken = $this->_tokenProvider->getIntegrationTokenByConsumerId($consumer->getId()); if ($existingToken && $clearExistingToken) { $existingToken->delete(); unset($existingToken); } } catch (\Exception $e) { } if (!isset($existingToken)) { $consumer = $this->_consumerFactory->create()->load($consumerId); $this->_tokenFactory->create()->createVerifierToken($consumerId); $this->_tokenProvider->createRequestToken($consumer); $this->_tokenProvider->getAccessToken($consumer); return true; } return false; }