session = $session; $this->jsonFactory = $jsonFactory; $this->tfa = $tfa; $this->oneTouch = $oneTouch; } /** * Get current user * @return \Magento\User\Model\User|null */ private function getUser() { return $this->session->getUser(); } /** * @inheritdoc */ public function execute() { $result = $this->jsonFactory->create(); try { $approvalCode = $this->oneTouch->request($this->getUser()); $res = ['success' => true, 'code' => $approvalCode]; } catch (\Exception $e) { $result->setHttpResponseCode(500); $res = ['success' => false, 'message' => $e->getMessage()]; } $result->setData($res); return $result; } /** * @inheritdoc */ protected function _isAllowed() { $user = $this->getUser(); return $user && $this->tfa->getProviderIsAllowed($user->getId(), Authy::CODE) && $this->tfa->getProvider(Authy::CODE)->isActive($user->getId()); } }