/**
  * {@inheritdoc}
  */
 public function createCustomerAccessToken($username, $password)
 {
     $this->validatorHelper->validate($username, $password);
     $this->getRequestThrottler()->throttle($username, RequestThrottler::USER_TYPE_CUSTOMER);
     try {
         $customerDataObject = $this->accountManagement->authenticate($username, $password);
     } catch (\Exception $e) {
         $this->getRequestThrottler()->logAuthenticationFailure($username, RequestThrottler::USER_TYPE_CUSTOMER);
         throw new AuthenticationException(__('You did not sign in correctly or your account is temporarily disabled.'));
     }
     $this->getRequestThrottler()->resetAuthenticationFailuresCount($username, RequestThrottler::USER_TYPE_CUSTOMER);
     return $this->tokenModelFactory->create()->createCustomerToken($customerDataObject->getId())->getToken();
 }
Exemple #2
0
 /**
  * {@inheritdoc}
  */
 public function createAdminAccessToken($username, $password)
 {
     $this->validatorHelper->validate($username, $password);
     $this->userModel->login($username, $password);
     if (!$this->userModel->getId()) {
         /*
          * This message is same as one thrown in \Magento\Backend\Model\Auth to keep the behavior consistent.
          * Constant cannot be created in Auth Model since it uses legacy translation that doesn't support it.
          * Need to make sure that this is refactored once exception handling is updated in Auth Model.
          */
         throw new AuthenticationException(__('You did not sign in correctly or your account is temporarily disabled.'));
     }
     return $this->tokenModelFactory->create()->createAdminToken($this->userModel->getId())->getToken();
 }
 public function testValidateValidCredentials()
 {
     $username = '******';
     $password = '******';
     $this->credentialsValidator->validate($username, $password);
 }
 /**
  * {@inheritdoc}
  */
 public function createCustomerAccessToken($username, $password)
 {
     $this->validatorHelper->validate($username, $password);
     $customerDataObject = $this->accountManagement->authenticate($username, $password);
     return $this->tokenModelFactory->create()->createCustomerToken($customerDataObject->getId())->getToken();
 }