Esempio n. 1
0
 /**
  * {@inheritdoc}
  */
 public function revokeCustomerAccessToken($customerId)
 {
     $tokenCollection = $this->tokenModelCollectionFactory->create()->addFilterByCustomerId($customerId);
     if ($tokenCollection->getSize() == 0) {
         throw new LocalizedException("This customer has no tokens.");
     }
     try {
         foreach ($tokenCollection as $token) {
             $token->setRevoked(1)->save();
         }
     } catch (\Exception $e) {
         throw new LocalizedException("The tokens could not be revoked.");
     }
     return true;
 }
 /**
  * @magentoApiDataFixture Magento/Customer/_files/customer.php
  */
 public function testCreateCustomerAccessToken()
 {
     $customerUserName = '******';
     $password = '******';
     $isTokenCorrect = false;
     $serviceInfo = ['rest' => ['resourcePath' => self::RESOURCE_PATH_CUSTOMER_TOKEN, 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_POST]];
     $requestData = ['username' => $customerUserName, 'password' => $password];
     $accessToken = $this->_webApiCall($serviceInfo, $requestData);
     $customerData = $this->customerAccountManagement->authenticate($customerUserName, $password);
     /** @var $this->tokenCollection \Magento\Integration\Model\Resource\Oauth\Token\Collection */
     $this->tokenCollection->addFilterByCustomerId($customerData->getId());
     foreach ($this->tokenCollection->getItems() as $item) {
         /** @var $item TokenModel */
         if ($item->getToken() == $accessToken) {
             $isTokenCorrect = true;
         }
     }
     $this->assertTrue($isTokenCorrect);
 }