accountManagement = $accountManagement; $this->validatorHelper = $validatorHelper; $this->eventManager = $eventManager ?: ObjectManager::getInstance()->get(ManagerInterface::class); $this->tokenParametersFactory = $tokenParamsFactory ?? ObjectManager::getInstance()->get(UserTokenParametersFactory::class); $this->tokenIssuer = $tokenIssuer ?? ObjectManager::getInstance()->get(UserTokenIssuerInterface::class); $this->tokenRevoker = $tokenRevoker ?? ObjectManager::getInstance()->get(UserTokenRevokerInterface::class); } /** * @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( __( 'The account sign-in was incorrect or your account is disabled temporarily. ' . 'Please wait and try again later.' ) ); } $this->eventManager->dispatch('customer_login', ['customer' => $customerDataObject]); $this->getRequestThrottler()->resetAuthenticationFailuresCount($username, RequestThrottler::USER_TYPE_CUSTOMER); $context = new CustomUserContext( (int)$customerDataObject->getId(), CustomUserContext::USER_TYPE_CUSTOMER ); $params = $this->tokenParametersFactory->create(); return $this->tokenIssuer->create($context, $params); } /** * Revoke token by customer id. * * @param int $customerId * @return bool * @throws \Magento\Framework\Exception\LocalizedException */ public function revokeCustomerAccessToken($customerId) { try { $this->tokenRevoker->revokeFor(new CustomUserContext((int)$customerId, CustomUserContext::USER_TYPE_CUSTOMER)); } catch (UserTokenException $exception) { throw new LocalizedException(__('Failed to revoke customer\'s access tokens'), $exception); } return true; } /** * Get request throttler instance * * @return RequestThrottler * @deprecated 100.0.4 */ private function getRequestThrottler() { if (!$this->requestThrottler instanceof RequestThrottler) { return ObjectManager::getInstance()->get(RequestThrottler::class); } return $this->requestThrottler; } }