diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index ed4820c..6f7fbe5 100755 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,4 +1,4 @@ -image: "sashas777/magento-php:7.3-cli" +image: "sashas777/magento-php:7.4-cli" stages: - build diff --git a/Controller/Customer/ResetPost.php b/Controller/Customer/ResetPost.php index 9b590ba..f732a1f 100755 --- a/Controller/Customer/ResetPost.php +++ b/Controller/Customer/ResetPost.php @@ -15,7 +15,6 @@ use Magento\Framework\Data\Form\FormKey\Validator; use Magento\Framework\App\ResponseInterface; use Magento\Framework\Controller\ResultInterface; -use MSP\TwoFactorAuth\Model\Provider\Engine\Google as MspGoogle; use Magetarian\CustomerTwoFactorAuth\Controller\Customer; use Magetarian\CustomerTwoFactorAuth\Api\ProviderPoolInterface; diff --git a/Model/Config/ConfigProvider.php b/Model/Config/ConfigProvider.php index ab8f15c..d58e9e7 100755 --- a/Model/Config/ConfigProvider.php +++ b/Model/Config/ConfigProvider.php @@ -17,7 +17,7 @@ */ class ConfigProvider { - const XML_PATH_CUSTOMER_FORCE_TFA = 'msp_securitysuite_twofactorauth/general/customer_force_tfa'; + const XML_PATH_CUSTOMER_FORCE_TFA = 'twofactorauth/general/customer_force_tfa'; /** * @var ScopeConfigInterface diff --git a/Model/Provider/Engine/Authy.php b/Model/Provider/Engine/Authy.php index e09665a..54d7ad9 100755 --- a/Model/Provider/Engine/Authy.php +++ b/Model/Provider/Engine/Authy.php @@ -14,11 +14,11 @@ use Magento\Framework\Exception\LocalizedException; use Magetarian\CustomerTwoFactorAuth\Api\CustomerConfigManagerInterface; use Magetarian\CustomerTwoFactorAuth\Api\EngineInterface; -use MSP\TwoFactorAuth\Model\Provider\Engine\Authy as MspAuthy; -use MSP\TwoFactorAuth\Model\Provider\Engine\Authy\Service as MspAuthyService; +use Magento\TwoFactorAuth\Model\Provider\Engine\Authy as MagentoAuthy; +use Magento\TwoFactorAuth\Model\Provider\Engine\Authy\Service as MagentoAuthyService; use Magento\Framework\HTTP\Client\CurlFactory; use Magento\Framework\Serialize\Serializer\Json; -use MSP\TwoFactorAuth\Model\ResourceModel\Country\CollectionFactory as CountryCollectionFactory; +use Magento\TwoFactorAuth\Model\ResourceModel\Country\CollectionFactory as CountryCollectionFactory; /** * Class Authy @@ -29,7 +29,7 @@ class Authy implements EngineInterface /** * Enabled for customer XML Path */ - const XML_PATH_ENABLED_CUSTOMER = 'msp_securitysuite_twofactorauth/authy/enabled_customer'; + const XML_PATH_ENABLED_CUSTOMER = 'twofactorauth/authy/enabled_customer'; /** * Key for customer id field @@ -135,12 +135,14 @@ private function authenticate(CustomerInterface $customer, array $providerInfo, if (!isset($providerInfo[static::CONFIG_CUSTOMER_KEY])) { throw new LocalizedException(__('Missing customer information')); } + if (isset($providerInfo[static::CONFIG_PENDING_APPROVAL_KEY])) { $this->verifyOneTouch($customer, $providerInfo); } else { $url = $this->getProtectedApiEndpoint('verify/' . $code . '/' . $providerInfo[static::CONFIG_CUSTOMER_KEY]); $this->makeApiRequest($url, [], 'GET'); } + } /** @@ -150,7 +152,6 @@ private function authenticate(CustomerInterface $customer, array $providerInfo, public function isEnabled() { return - !!$this->scopeConfig->getValue(MspAuthy::XML_PATH_ENABLED) && !!$this->scopeConfig->getValue(static::XML_PATH_ENABLED_CUSTOMER) && !!$this->getApiKey(); } @@ -323,9 +324,12 @@ private function verifyOneTouch(CustomerInterface $customer, array $providerInfo { $approvalCode = $providerInfo[static::CONFIG_PENDING_APPROVAL_KEY]; $status = $this->validateOneTouch($customer, $providerInfo, $approvalCode); - if ($status == 'approved') { + + if ($status == 'approved' || $status == 'denied') { unset($providerInfo[static::CONFIG_PENDING_APPROVAL_KEY]); $this->customerConfigManager->setProviderConfig((int) $customer->getId(), $this->getCode(), $providerInfo); + } elseif ($status == 'denied') { + throw new LocalizedException(__('Authentication denied.')); } } @@ -368,7 +372,7 @@ private function makeApiRequest(string $url, $data = [], $type = 'POST') */ private function getApiKey(): ?string { - return $this->scopeConfig->getValue(MspAuthyService::XML_PATH_API_KEY); + return $this->scopeConfig->getValue(MagentoAuthyService::XML_PATH_API_KEY); } /** @@ -378,7 +382,7 @@ private function getApiKey(): ?string */ private function getProtectedApiEndpoint(string $path): string { - return MspAuthyService::AUTHY_BASE_ENDPOINT . 'protected/json/' . $path; + return MagentoAuthyService::AUTHY_BASE_ENDPOINT . 'protected/json/' . $path; } /** @@ -388,7 +392,7 @@ private function getProtectedApiEndpoint(string $path): string */ private function getOneTouchApiEndpoint(string $path): string { - return MspAuthyService::AUTHY_BASE_ENDPOINT . 'onetouch/json/' . $path; + return MagentoAuthyService::AUTHY_BASE_ENDPOINT . 'onetouch/json/' . $path; } /** @@ -399,7 +403,7 @@ private function getCountriesList(): array { $countries = []; $countriesList = $this->countryCollectionFactory->create()->addOrder('name', 'asc')->getItems(); - /** @var \MSP\TwoFactorAuth\Api\Data\CountryInterface $country */ + /** @var \Magento\TwoFactorAuth\Api\Data\CountryInterface $country */ foreach ($countriesList as $country) { $countries[] = [ 'dial_code' => $country->getDialCode(), @@ -414,7 +418,7 @@ private function getCountriesList(): array */ public function getCode(): string { - return MspAuthy::CODE; + return MagentoAuthy::CODE; } /** diff --git a/Model/Provider/Engine/DuoSecurity.php b/Model/Provider/Engine/DuoSecurity.php index 98b3174..2770e3e 100755 --- a/Model/Provider/Engine/DuoSecurity.php +++ b/Model/Provider/Engine/DuoSecurity.php @@ -12,7 +12,7 @@ use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Framework\DataObject; use Magetarian\CustomerTwoFactorAuth\Api\EngineInterface; -use MSP\TwoFactorAuth\Model\Provider\Engine\DuoSecurity as MspDuoSecurity; +use Magento\TwoFactorAuth\Model\Provider\Engine\DuoSecurity as MagentoDuoSecurity; /** * Class DuoSecurity @@ -23,7 +23,7 @@ class DuoSecurity implements EngineInterface /** * Enabled for customer XML Path */ - const XML_PATH_ENABLED_CUSTOMER = 'msp_securitysuite_twofactorauth/duo/enabled_customer'; + const XML_PATH_ENABLED_CUSTOMER = 'twofactorauth/duo/enabled_customer'; /** * @var ScopeConfigInterface @@ -46,7 +46,7 @@ public function __construct( */ public function getApiHostname() { - return $this->scopeConfig->getValue(MspDuoSecurity::XML_PATH_API_HOSTNAME); + return $this->scopeConfig->getValue(MagentoDuoSecurity::XML_PATH_API_HOSTNAME); } /** @@ -55,7 +55,7 @@ public function getApiHostname() */ private function getApplicationKey() { - return $this->scopeConfig->getValue(MspDuoSecurity::XML_PATH_APPLICATION_KEY); + return $this->scopeConfig->getValue(MagentoDuoSecurity::XML_PATH_APPLICATION_KEY); } /** @@ -64,7 +64,7 @@ private function getApplicationKey() */ private function getSecretKey() { - return $this->scopeConfig->getValue(MspDuoSecurity::XML_PATH_SECRET_KEY); + return $this->scopeConfig->getValue(MagentoDuoSecurity::XML_PATH_SECRET_KEY); } /** @@ -73,7 +73,7 @@ private function getSecretKey() */ private function getIntegrationKey() { - return $this->scopeConfig->getValue(MspDuoSecurity::XML_PATH_INTEGRATION_KEY); + return $this->scopeConfig->getValue(MagentoDuoSecurity::XML_PATH_INTEGRATION_KEY); } /** @@ -85,12 +85,12 @@ private function getIntegrationKey() * @param int $time * @return string */ - private function signValues($key, $values, $prefix, $expire, $time) + private function signValues(string $key, string $values, string $prefix, int $expire, int $time): string { $exp = $time + $expire; $cookie = $prefix . '|' . base64_encode($values . '|' . $exp); - $sig = hash_hmac("sha1", $cookie, $key); + $sig = hash_hmac('sha1', $cookie, $key); return $cookie . '|' . $sig; } @@ -102,7 +102,7 @@ private function signValues($key, $values, $prefix, $expire, $time) * @param int $time * @return string|false */ - private function parseValues($key, $val, $prefix, $time) + private function parseValues(string $key, string $val, string $prefix, int $time): ?string { $integrationKey = $this->getIntegrationKey(); @@ -110,17 +110,17 @@ private function parseValues($key, $val, $prefix, $time) $parts = explode('|', $val); if (count($parts) !== 3) { - return false; + return null; } - list($uPrefix, $uB64, $uSig) = $parts; + [$uPrefix, $uB64, $uSig] = $parts; - $sig = hash_hmac("sha1", $uPrefix . '|' . $uB64, $key); - if (hash_hmac("sha1", $sig, $key) !== hash_hmac("sha1", $uSig, $key)) { - return false; + $sig = hash_hmac('sha1', $uPrefix . '|' . $uB64, $key); + if (hash_hmac('sha1', $sig, $key) !== hash_hmac('sha1', $uSig, $key)) { + return null; } if ($uPrefix !== $prefix) { - return false; + return null; } // @codingStandardsIgnoreStart @@ -128,15 +128,15 @@ private function parseValues($key, $val, $prefix, $time) // @codingStandardsIgnoreEnd if (count($cookieParts) !== 3) { - return false; + return null; } - list($user, $uIkey, $exp) = $cookieParts; + [$user, $uIkey, $exp] = $cookieParts; if ($uIkey !== $integrationKey) { - return false; + return null; } if ($timestamp >= (int) $exp) { - return false; + return null; } return $user; @@ -147,7 +147,7 @@ private function parseValues($key, $val, $prefix, $time) * @param CustomerInterface $customer * @return string */ - public function getRequestSignature(CustomerInterface $customer) + public function getRequestSignature(CustomerInterface $customer): string { $time = time(); @@ -155,15 +155,15 @@ public function getRequestSignature(CustomerInterface $customer) $duoSignature = $this->signValues( $this->getSecretKey(), $values, - MspDuoSecurity::DUO_PREFIX, - MspDuoSecurity::DUO_EXPIRE, + MagentoDuoSecurity::DUO_PREFIX, + MagentoDuoSecurity::DUO_EXPIRE, $time ); $appSignature = $this->signValues( $this->getApplicationKey(), $values, - MspDuoSecurity::APP_PREFIX, - MspDuoSecurity::APP_EXPIRE, + MagentoDuoSecurity::APP_PREFIX, + MagentoDuoSecurity::APP_EXPIRE, $time ); @@ -176,14 +176,14 @@ public function getRequestSignature(CustomerInterface $customer) * @param DataObject $request * @return bool */ - public function verify(CustomerInterface $customer, DataObject $request) + public function verify(CustomerInterface $customer, DataObject $request): bool { $time = time(); list($authSig, $appSig) = explode(':', $request->getData('tfa_code')); - $authUser = $this->parseValues($this->getSecretKey(), $authSig, MspDuoSecurity::AUTH_PREFIX, $time); - $appUser = $this->parseValues($this->getApplicationKey(), $appSig, MspDuoSecurity::APP_PREFIX, $time); + $authUser = $this->parseValues($this->getSecretKey(), $authSig, MagentoDuoSecurity::AUTH_PREFIX, $time); + $appUser = $this->parseValues($this->getApplicationKey(), $appSig, MagentoDuoSecurity::APP_PREFIX, $time); return (($authUser === $appUser) && ($appUser === $customer->getEmail().$customer->getId())); } @@ -195,7 +195,6 @@ public function verify(CustomerInterface $customer, DataObject $request) public function isEnabled() { return - !!$this->scopeConfig->getValue(MspDuoSecurity::XML_PATH_ENABLED) && !!$this->scopeConfig->getValue(static::XML_PATH_ENABLED_CUSTOMER) && !!$this->getApiHostname() && !!$this->getIntegrationKey() && @@ -208,7 +207,7 @@ public function isEnabled() */ public function getCode(): string { - return MspDuoSecurity::CODE; + return MagentoDuoSecurity::CODE; } /** diff --git a/Model/Provider/Engine/Google.php b/Model/Provider/Engine/Google.php index e07cd48..f38f2a2 100755 --- a/Model/Provider/Engine/Google.php +++ b/Model/Provider/Engine/Google.php @@ -9,15 +9,18 @@ namespace Magetarian\CustomerTwoFactorAuth\Model\Provider\Engine; use Base32\Base32; +use Endroid\QrCode\ErrorCorrectionLevel; use Endroid\QrCode\QrCode; use Endroid\QrCode\Writer\PngWriter; use Magento\Customer\Api\Data\CustomerInterface; use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Framework\DataObject; use Magento\Store\Model\StoreManagerInterface; +use Magento\TwoFactorAuth\Model\Provider\Engine\Google\TotpFactory; use Magetarian\CustomerTwoFactorAuth\Api\EngineInterface; -use MSP\TwoFactorAuth\Model\Provider\Engine\Google as MspGoogle; +use Magento\TwoFactorAuth\Model\Provider\Engine\Google as MagentoGoogle; use Magetarian\CustomerTwoFactorAuth\Api\CustomerConfigManagerInterface; +use OTPHP\TOTPInterface; /** * Class Google @@ -25,7 +28,10 @@ */ class Google implements EngineInterface { - const XML_PATH_ENABLED_CUSTOMER = 'msp_securitysuite_twofactorauth/google/enabled_customer'; + /** + * + */ + const XML_PATH_ENABLED_CUSTOMER = 'twofactorauth/google/enabled_customer'; /** * @var null @@ -47,21 +53,29 @@ class Google implements EngineInterface */ private $scopeConfig; + /** + * @var TOTPInterfaceFactory + */ + private $totpFactory; + /** * Google constructor. * * @param StoreManagerInterface $storeManager * @param ScopeConfigInterface $scopeConfig * @param CustomerConfigManagerInterface $customerConfigManager + * @param TotpFactory $totpFactory */ public function __construct( StoreManagerInterface $storeManager, ScopeConfigInterface $scopeConfig, - CustomerConfigManagerInterface $customerConfigManager + CustomerConfigManagerInterface $customerConfigManager, + TotpFactory $totpFactory ) { $this->customerConfigManager = $customerConfigManager; $this->storeManager = $storeManager; $this->scopeConfig = $scopeConfig; + $this->totpFactory = $totpFactory; } /** @@ -104,7 +118,8 @@ public function getQrCodeAsPng(CustomerInterface $customer) // @codingStandardsIgnoreStart $qrCode = new QrCode($this->getProvisioningUrl($customer)); $qrCode->setSize(400); - $qrCode->setErrorCorrectionLevel('high'); + $qrCode->setMargin(0); + $qrCode->setErrorCorrectionLevel(ErrorCorrectionLevel::HIGH()); $qrCode->setForegroundColor(['r' => 0, 'g' => 0, 'b' => 0, 'a' => 0]); $qrCode->setBackgroundColor(['r' => 255, 'g' => 255, 'b' => 255, 'a' => 0]); $qrCode->setLabelFontSize(16); @@ -132,6 +147,7 @@ private function getProvisioningUrl(CustomerInterface $customer) // @codingStandardsIgnoreEnd $totp = $this->getTotp($customer); + $totp->setLabel($customer->getEmail()); $totp->setIssuer($issuer); return $totp->getProvisioningUri(); @@ -143,24 +159,16 @@ private function getProvisioningUrl(CustomerInterface $customer) * @return \OTPHP\TOTP * @throws \Magento\Framework\Exception\NoSuchEntityException */ - private function getTotp(CustomerInterface $customer) + private function getTotp(CustomerInterface $customer): TOTPInterface { - if ($this->totp === null) { - $config = $this->customerConfigManager->getProviderConfig((int) $customer->getId(), $this->getCode()); - - if (!isset($config['secret'])) { - $config['secret'] = $this->getSecretCode((int) $customer->getId()); - } - - // @codingStandardsIgnoreStart - $this->totp = new \OTPHP\TOTP( - $customer->getEmail(), - $config['secret'] - ); - // @codingStandardsIgnoreEnd + $config = $this->customerConfigManager->getProviderConfig((int) $customer->getId(), $this->getCode()); + if (!isset($config['secret'])) { + $config['secret'] = $this->getSecretCode((int) $customer->getId()); } - return $this->totp; + $totp = $this->totpFactory->create($config['secret']); + + return $totp; } /** @@ -173,11 +181,17 @@ private function getTotp(CustomerInterface $customer) public function verify(CustomerInterface $customer, DataObject $request) { $token = $request->getData('tfa_code'); - + if (!$token) { + return false; + } $totp = $this->getTotp($customer); $totp->now(); - return $totp->verify($token); + return $totp->verify( + $token, + null, + $config['window'] ?? (int)$this->scopeConfig->getValue(MagentoGoogle::XML_PATH_OTP_WINDOW) ?: null + ); } /** @@ -186,8 +200,7 @@ public function verify(CustomerInterface $customer, DataObject $request) */ public function isEnabled() { - return !!$this->scopeConfig->getValue(MspGoogle::XML_PATH_ENABLED) && - !!$this->scopeConfig->getValue(static::XML_PATH_ENABLED_CUSTOMER); + return !!$this->scopeConfig->getValue(static::XML_PATH_ENABLED_CUSTOMER); } /** @@ -195,7 +208,7 @@ public function isEnabled() */ public function getCode(): string { - return MspGoogle::CODE; + return MagentoGoogle::CODE; } /** diff --git a/Test/Unit/Model/Provider/Engine/AuthyTest.php b/Test/Unit/Model/Provider/Engine/AuthyTest.php index 30c17b7..37020e5 100755 --- a/Test/Unit/Model/Provider/Engine/AuthyTest.php +++ b/Test/Unit/Model/Provider/Engine/AuthyTest.php @@ -18,10 +18,10 @@ use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; use Magento\Framework\HTTP\Client\CurlFactory; use Magento\Framework\HTTP\Client\Curl; -use MSP\TwoFactorAuth\Model\ResourceModel\Country\CollectionFactory as CountryCollectionFactory; -use MSP\TwoFactorAuth\Model\ResourceModel\Country\Collection; +use Magento\TwoFactorAuth\Model\ResourceModel\Country\CollectionFactory as CountryCollectionFactory; +use Magento\TwoFactorAuth\Model\ResourceModel\Country\Collection; use Magetarian\CustomerTwoFactorAuth\Model\Provider\Engine\Authy; -use MSP\TwoFactorAuth\Api\Data\CountryInterface; +use Magento\TwoFactorAuth\Api\Data\CountryInterface; /** * Class AuthyTest diff --git a/Test/Unit/Model/Provider/Engine/DuoSecurityTest.php b/Test/Unit/Model/Provider/Engine/DuoSecurityTest.php index 68b45cd..6efddf6 100755 --- a/Test/Unit/Model/Provider/Engine/DuoSecurityTest.php +++ b/Test/Unit/Model/Provider/Engine/DuoSecurityTest.php @@ -15,7 +15,7 @@ use PHPUnit\Framework\TestCase; use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; use Magetarian\CustomerTwoFactorAuth\Model\Provider\Engine\DuoSecurity; -use MSP\TwoFactorAuth\Model\Provider\Engine\DuoSecurity as MspDuoSecurity; +use Magento\TwoFactorAuth\Model\Provider\Engine\DuoSecurity as MagentoDuoSecurity; /** * Class DuoSecurityTest @@ -51,7 +51,7 @@ public function testGetAdditionalConfig() */ public function testGetCode() { - $this->assertEquals(MspDuoSecurity::CODE, $this->object->getCode()); + $this->assertEquals(MagentoDuoSecurity::CODE, $this->object->getCode()); } /** diff --git a/composer.json b/composer.json index 0eab0f6..1f19e43 100755 --- a/composer.json +++ b/composer.json @@ -10,13 +10,12 @@ } ], "require": { - "php": "~7.2.0||~7.3.0", - "magento/framework": "102.0.*", - "magento/module-customer": "102.0.*", - "magento/module-backend": "101.0.*", - "magento/module-eav": "102.0.*", - "magento/module-store": "101.0.*", - "msp/twofactorauth": "3.1.*" + "magento/framework": "103.0.*", + "magento/module-customer": "103.0.*", + "magento/module-backend": "102.0.*", + "magento/module-eav": "102.1.*", + "magento/module-store": "101.1.*", + "magento/twofactorauth": "1.0.*" }, "license": [ "GPL-3.0-only" diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml index a1836a5..dff7558 100755 --- a/etc/adminhtml/system.xml +++ b/etc/adminhtml/system.xml @@ -7,7 +7,7 @@ -
+
diff --git a/etc/csp_whitelist.xml b/etc/csp_whitelist.xml new file mode 100755 index 0000000..bb0767b --- /dev/null +++ b/etc/csp_whitelist.xml @@ -0,0 +1,46 @@ + + + + + + + *.duosecurity.com + + + + + *.duosecurity.com + + + + + *.duosecurity.com + + + + + *.duosecurity.com + + + + + *.duosecurity.com + + + + + *.duosecurity.com + + + + + *.duosecurity.com + + + + diff --git a/etc/di.xml b/etc/di.xml index a54be44..05078c4 100755 --- a/etc/di.xml +++ b/etc/di.xml @@ -24,21 +24,21 @@ Magetarian\CustomerTwoFactorAuth\Model\Provider\Engine\Google - \MSP\TwoFactorAuth\Model\Provider\Engine\Google::CODE + \Magento\TwoFactorAuth\Model\Provider\Engine\Google::CODE Google Authenticator Magetarian\CustomerTwoFactorAuth\Model\Provider\Engine\DuoSecurity - \MSP\TwoFactorAuth\Model\Provider\Engine\DuoSecurity::CODE + \Magento\TwoFactorAuth\Model\Provider\Engine\DuoSecurity::CODE Duo Security Magetarian\CustomerTwoFactorAuth\Model\Provider\Engine\Authy - \MSP\TwoFactorAuth\Model\Provider\Engine\Authy::CODE + \Magento\TwoFactorAuth\Model\Provider\Engine\Authy::CODE Authy diff --git a/etc/module.xml b/etc/module.xml index 1486a32..721ed03 100755 --- a/etc/module.xml +++ b/etc/module.xml @@ -7,7 +7,7 @@ - + diff --git a/view/frontend/layout/tfa_customer_configuration.xml b/view/frontend/layout/tfa_customer_configuration.xml index 98e71f2..e346f8d 100755 --- a/view/frontend/layout/tfa_customer_configuration.xml +++ b/view/frontend/layout/tfa_customer_configuration.xml @@ -17,13 +17,13 @@ Magetarian\CustomerTwoFactorAuth\ViewModel\Customer\Information - \MSP\TwoFactorAuth\Model\Provider\Engine\Google::CODE + \Magento\TwoFactorAuth\Model\Provider\Engine\Google::CODE Magetarian\CustomerTwoFactorAuth\ViewModel\Customer\Information - \MSP\TwoFactorAuth\Model\Provider\Engine\Authy::CODE + \Magento\TwoFactorAuth\Model\Provider\Engine\Authy::CODE diff --git a/view/frontend/web/js/view/provider/authy.js b/view/frontend/web/js/view/provider/authy.js index a32ed65..228a696 100755 --- a/view/frontend/web/js/view/provider/authy.js +++ b/view/frontend/web/js/view/provider/authy.js @@ -10,6 +10,7 @@ define([ 'ko', 'Magetarian_CustomerTwoFactorAuth/js/action/authy/register', 'Magetarian_CustomerTwoFactorAuth/js/action/authy/verify', + 'Magento_Ui/js/model/messageList', 'Magetarian_CustomerTwoFactorAuth/js/view/provider/default' ], function ( $, @@ -17,6 +18,7 @@ define([ ko, registerAction, verifyAction, + messageList, Component ) { 'use strict'; @@ -69,9 +71,15 @@ define([ * @param {String} status */ validateOneTouch: function (code, status) { - if (status !== 'approved') { + if (status == 'approved') { + $(this.authButton).closest("form").find(this.tfaCodeFieldSelector).val(code); + $(this.authButton).hide(); + $(this.authButton).closest("form").submit(); + } else if (status == 'denied') { + messageList.addErrorMessage({ message: 'The authentication request denied.' }); + $('body').trigger('processStop'); + } else if (status == 'pending') { let verifyData = this.collectFormData(this.authButton); - verifyData['method'] = this.method(); verifyData['code'] = code; $('body').trigger('processStart'); @@ -79,9 +87,8 @@ define([ $('body').trigger('processStop'); }); } else { - $(this.authButton).closest("form").find(this.tfaCodeFieldSelector).val(code); - $(this.authButton).hide(); - $(this.authButton).closest("form").submit(); + messageList.addErrorMessage({ message: 'The authentication status '+status }); + $('body').trigger('processStop'); } }, diff --git a/view/frontend/web/js/view/provider/default.js b/view/frontend/web/js/view/provider/default.js index 61aad56..4d4b91b 100755 --- a/view/frontend/web/js/view/provider/default.js +++ b/view/frontend/web/js/view/provider/default.js @@ -45,6 +45,12 @@ define([ selectedProvider(this.getCode()); }, + /** + * @return {String} + */ + getSelectedProviderCode: function () { + return selectedProvider(); + }, /** * @return {String} */ diff --git a/view/frontend/web/template/provider/authy.html b/view/frontend/web/template/provider/authy.html index c534500..dad1fd7 100755 --- a/view/frontend/web/template/provider/authy.html +++ b/view/frontend/web/template/provider/authy.html @@ -1,8 +1,3 @@ - -
- -
-

-
- -
- + +
+ +
+

+
+ +
+ +
-
-
- -
- +
+ +
+ +
-
-
- -
- +
+ +
+ +
-
-
- -
-
- - -
-

-
- -
-
- -
-

-
- -
-
- -
-
- -
-

-
- -
- +
+
-
-
- -
-
- -
+ + + +
+

+
+ +
+
+ +
+

+
+ +
+
+ +
+
+ +
+

+
+ +
+ +
+
+
+ +
+
+ + + diff --git a/view/frontend/web/template/provider/duo.html b/view/frontend/web/template/provider/duo.html index 2cb7686..40d7885 100755 --- a/view/frontend/web/template/provider/duo.html +++ b/view/frontend/web/template/provider/duo.html @@ -1,8 +1,3 @@ - -
+
- + + +
diff --git a/view/frontend/web/template/provider/google.html b/view/frontend/web/template/provider/google.html index b4e2d2f..f3ab332 100755 --- a/view/frontend/web/template/provider/google.html +++ b/view/frontend/web/template/provider/google.html @@ -1,8 +1,3 @@ - - -
- -

-

-
- -
- -
- - + + +
+ +

+

-
-
- -
+ +
+ +
+ + +
+
+
+ +
+ diff --git a/view/frontend/web/template/tfa-login.html b/view/frontend/web/template/tfa-login.html index 9084533..c820324 100755 --- a/view/frontend/web/template/tfa-login.html +++ b/view/frontend/web/template/tfa-login.html @@ -1,8 +1,3 @@ -