Skip to content

Commit bcf44ac

Browse files
Rizwan KhanRizwan Khan
authored andcommitted
AC-9797: 2FA functionality enhancement
1 parent 9ff0e50 commit bcf44ac

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed

TwoFactorAuth/Block/Provider/Authy/Auth.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,37 @@
88
namespace Magento\TwoFactorAuth\Block\Provider\Authy;
99

1010
use Magento\Backend\Block\Template;
11+
use Magento\Framework\App\Config\ScopeConfigInterface;
1112

1213
/**
1314
* @api
1415
*/
1516
class Auth extends Template
1617
{
18+
/**
19+
* Config path for the 2FA Attempts
20+
*/
21+
private const XML_PATH_2FA_RETRY_ATTEMPTS = 'twofactorauth/general/twofactorauth_retry';
22+
23+
/**
24+
* @var ScopeConfigInterface
25+
*/
26+
private $scopeConfig;
27+
28+
/**
29+
* @param \Magento\Backend\Block\Template\Context $context
30+
* @param ScopeConfigInterface $scopeConfig
31+
* @param array $data
32+
*/
33+
public function __construct(
34+
\Magento\Backend\Block\Template\Context $context,
35+
ScopeConfigInterface $scopeConfig,
36+
array $data = []
37+
) {
38+
parent::__construct($context, $data);
39+
$this->scopeConfig = $scopeConfig;
40+
}
41+
1742
/**
1843
* @inheritdoc
1944
*/
@@ -34,6 +59,9 @@ public function getJsLayout()
3459
$this->jsLayout['components']['tfa-auth']['successUrl'] =
3560
$this->getUrl($this->_urlBuilder->getStartupPageUrl());
3661

62+
$this->jsLayout['components']['tfa-auth']['attempts'] =
63+
$this->scopeConfig->getValue(self::XML_PATH_2FA_RETRY_ATTEMPTS);
64+
3765
return parent::getJsLayout();
3866
}
3967
}

TwoFactorAuth/etc/config.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<twofactorauth>
1212
<general>
1313
<force_providers></force_providers>
14+
<twofactorauth_retry>10</twofactorauth_retry>
1415
</general>
1516
<authy>
1617
<onetouch_message>Login request to your Magento Admin</onetouch_message>

TwoFactorAuth/view/adminhtml/web/js/authy/auth.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ define([
1212
], function ($, ko, Component, error) {
1313
'use strict';
1414

15+
let attempts = 0;
1516
return Component.extend({
1617
selectedMethod: ko.observable(''),
1718
waitingText: ko.observable(''),
@@ -190,12 +191,27 @@ define([
190191
this.success(false);
191192
},
192193

194+
/**
195+
* Get Retry Attempts
196+
* @returns {int}
197+
*/
198+
getRetryAttempts: function () {
199+
return this.attempts;
200+
},
201+
193202
/**
194203
* Verify authy code
195204
*/
196205
verifyCode: function () {
197206
var me = this;
198207

208+
attempts++;
209+
if (attempts > this.getRetryAttempts()) {
210+
console.log('Maximum otp retries are done.');
211+
location.href = $('.tfa-logout-link').attr('href');
212+
return;
213+
}
214+
199215
this.waitingText('Please wait...');
200216

201217
$.post(this.getPostUrl(), {

0 commit comments

Comments
 (0)