tfa = $tfa; $this->session = $session; $this->jsonFactory = $jsonFactory; $this->google = $google; $this->tfaSession = $tfaSession; $this->trustedManager = $trustedManager; $this->dataObjectFactory = $dataObjectFactory; $this->alert = $alert; } /** * Get current user * @return \Magento\User\Model\User|null */ private function getUser() { return $this->session->getUser(); } /** * @inheritdoc * @return \Magento\Framework\App\ResponseInterface|\Magento\Framework\Controller\ResultInterface * @throws \Magento\Framework\Exception\NoSuchEntityException */ public function execute() { $response = $this->jsonFactory->create(); $user = $this->getUser(); if ($this->google->verify($user, $this->dataObjectFactory->create([ 'data' => $this->getRequest()->getParams(), ]))) { $this->trustedManager->handleTrustDeviceRequest(Google::CODE, $this->getRequest()); $this->tfaSession->grantAccess(); $response->setData(['success' => true]); } else { $this->alert->event( 'MSP_TwoFactorAuth', 'Google auth invalid token', AlertInterface::LEVEL_WARNING, $user->getUserName() ); $response->setData(['success' => false, 'message' => 'Invalid code']); } return $response; } /** * Check if admin has permissions to visit related pages * * @return bool */ protected function _isAllowed() { $user = $this->getUser(); return $user && $this->tfa->getProviderIsAllowed($user->getId(), Google::CODE) && $this->tfa->getProvider(Google::CODE)->isActive($user->getId()); } }