tfa = $tfa; $this->session = $session; $this->u2fKey = $u2fKey; $this->jsonFactory = $jsonFactory; $this->tfaSession = $tfaSession; $this->trustedManager = $trustedManager; $this->dataObjectFactory = $dataObjectFactory; $this->alert = $alert; } /** * Dispatch request * * @return \Magento\Framework\Controller\ResultInterface|ResponseInterface */ public function execute() { $result = $this->jsonFactory->create(); try { $this->u2fKey->verify($this->getUser(), $this->dataObjectFactory->create([ 'data' => $this->getRequest()->getParams(), ])); $this->tfaSession->grantAccess(); $this->trustedManager->handleTrustDeviceRequest(U2fKey::CODE, $this->getRequest()); $res = ['success' => true]; } catch (\Exception $e) { $this->alert->event( 'MSP_TwoFactorAuth', 'U2F error', AlertInterface::LEVEL_ERROR, $this->getUser()->getUserName(), AlertInterface::ACTION_LOG, $e->getMessage() ); $res = ['success' => false, 'message' => $e->getMessage()]; } $result->setData($res); return $result; } /** * @return \Magento\User\Model\User|null */ private function getUser() { return $this->session->getUser(); } /** * Check if admin has permissions to visit related pages * * @return bool */ protected function _isAllowed() { $user = $this->getUser(); return $user && $this->tfa->getProviderIsAllowed($user->getId(), U2fKey::CODE) && $this->tfa->getProvider(U2fKey::CODE)->isActive($user->getId()); } }