Skip to content

Commit 32724ef

Browse files
Rizwan KhanRizwan Khan
authored andcommitted
AC-9797: 2FA functionality enhancement
1 parent d7ab701 commit 32724ef

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed

TwoFactorAuth/Block/Provider/Google/Auth.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,35 @@
88
namespace Magento\TwoFactorAuth\Block\Provider\Google;
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+
public const XML_PATH_2FA_RETRY_ATTEMPTS = 'twofactorauth/general/twofactorauth_retry';
22+
23+
/**
24+
* @var ScopeConfigInterface
25+
*/
26+
private $scopeConfig;
27+
28+
/**
29+
* @param ScopeConfigInterface|null $scopeConfig
30+
*/
31+
public function __construct(
32+
\Magento\Backend\Block\Template\Context $context,
33+
ScopeConfigInterface $scopeConfig,
34+
array $data = []
35+
) {
36+
parent::__construct($context, $data);
37+
$this->scopeConfig = $scopeConfig;
38+
}
39+
1740
/**
1841
* @inheritdoc
1942
*/
@@ -25,6 +48,9 @@ public function getJsLayout()
2548
$this->jsLayout['components']['tfa-auth']['successUrl'] =
2649
$this->getUrl($this->_urlBuilder->getStartupPageUrl());
2750

51+
$this->jsLayout['components']['tfa-auth']['attempts'] =
52+
$this->scopeConfig->getValue(self::XML_PATH_2FA_RETRY_ATTEMPTS);
53+
2854
return parent::getJsLayout();
2955
}
3056
}

TwoFactorAuth/etc/adminhtml/system.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@
3535
<label>Configuration Email URL for Web API</label>
3636
<comment>This can be used to override the default email configuration link that is sent when using the Magento Web API's to authenticate. Use the placeholder :tfat to indicate where the token should be injected</comment>
3737
</field>
38+
<field canRestore="1" id="twofactorauth_retry" translate="label" type="text" sortOrder="40"
39+
showInDefault="1" showInWebsite="0" showInStore="0">
40+
<label>Configuration for 2FA retry attempts</label>
41+
<comment>Security configurations for TowFatcorAuth page. To avoid the bruteforce of twofactorauth API</comment>
42+
</field>
3843
</group>
3944
<group id="google" translate="label" type="text" sortOrder="30" showInDefault="1" showInWebsite="0"
4045
showInStore="0">

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

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

14+
let attempts = 0;
15+
1416
return Component.extend({
1517
currentStep: ko.observable('register'),
1618
waitText: ko.observable(''),
@@ -40,6 +42,14 @@ define([
4042
return this.postUrl;
4143
},
4244

45+
/**
46+
* Get Retry Attempts
47+
* @returns {int}
48+
*/
49+
getRetryAttempts: function () {
50+
return this.attempts;
51+
},
52+
4353
/**
4454
* Get plain Secret Code
4555
* @returns {String}
@@ -62,6 +72,13 @@ define([
6272
doVerify: function () {
6373
var me = this;
6474

75+
attempts++;
76+
if (attempts > this.getRetryAttempts()){
77+
alert("Maximum otp retries are done.");
78+
location.href = $(".tfa-logout-link").attr("href");
79+
return;
80+
}
81+
6582
this.waitText('Please wait...');
6683
$.post(this.getPostUrl(), {
6784
'tfa_code': this.verifyCode()

0 commit comments

Comments
 (0)