Skip to content

Commit 11816ae

Browse files
committed
AC-10982::[2FA] Integrate with Duo Web SDK to support Universal Prompt-WEB API tests fixes
1 parent 3f08d7e commit 11816ae

File tree

4 files changed

+54
-16
lines changed

4 files changed

+54
-16
lines changed

TwoFactorAuth/Block/Adminhtml/System/Config/Providers.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,16 @@ protected function _getElementHtml(AbstractElement $element)
4646
'#twofactorauth_general_force_providers' => [
4747
'Magento_TwoFactorAuth/js/system/config/providers' => [
4848
'modalTitleText' => $this->getModalTitleText(),
49-
'modalContentBody' => $this->getModalContentBody()
49+
'modalContentBody' => $this->getModalContentBody(),
50+
'duoProviderValue' => 'duo_security',
51+
'duoFields' => [
52+
'twofactorauth_duo_client_id',
53+
'twofactorauth_duo_client_secret',
54+
'twofactorauth_duo_api_hostname',
55+
'twofactorauth_duo_failmode',
56+
'twofactorauth_duo_integration_key',
57+
'twofactorauth_duo_secret_key',
58+
]
5059
]
5160
]
5261
];

TwoFactorAuth/Model/Provider/Engine/DuoSecurity.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,6 @@ public function getApiHostname(): string
161161
*/
162162
private function getClientSecret(): string
163163
{
164-
// return default value if client secret is not set as per Duo Library
165164
return $this->encryptor->decrypt(
166165
$this->scopeConfig->getValue(static::XML_PATH_CLIENT_SECRET)
167166
);
@@ -174,7 +173,6 @@ private function getClientSecret(): string
174173
*/
175174
private function getClientId(): string
176175
{
177-
// return default value if client id is not set as per Duo Library
178176
return $this->scopeConfig->getValue(static::XML_PATH_CLIENT_ID);
179177
}
180178

TwoFactorAuth/etc/config.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
<api_key backend_model="Magento\Config\Model\Config\Backend\Encrypted"/>
2020
</authy>
2121
<duo>
22-
<client_secret backend_model="Magento\Config\Model\Config\Backend\Encrypted"/>
2322
<secret_key backend_model="Magento\Config\Model\Config\Backend\Encrypted"/>
2423
</duo>
2524
<google>

TwoFactorAuth/view/adminhtml/web/js/system/config/providers.js

Lines changed: 44 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,50 @@ define([
1212
'use strict';
1313

1414
return function (config, element) {
15-
1615
var $element = $(element),
17-
initialValue = $element.val();
16+
initialValue = $element.val(),
17+
duoProviderValue = config.duoProviderValue,
18+
duoFields = config.duoFields;
19+
20+
$element.on('change', function () {
21+
var selectedValues = $element.val() || [];
22+
23+
if (selectedValues.includes(duoProviderValue)) {
24+
addRequiredAttributes(duoFields);
25+
} else {
26+
removeRequiredAttributes(duoFields);
27+
}
28+
});
29+
30+
/**
31+
* Adds the "required" attribute to each Duo field
32+
*
33+
* @param {Array} fields - List of field IDs to mark as required
34+
*/
35+
function addRequiredAttributes(fields) {
36+
fields.forEach(function (fieldId) {
37+
var $field = $('#' + fieldId);
38+
if ($field.length) {
39+
$field.attr('required', 'required');
40+
$field.addClass('required-entry');
41+
}
42+
});
43+
}
44+
45+
/**
46+
* Removes the "required" attribute from each Duo field
47+
*
48+
* @param {Array} fields - List of field IDs to unmark as required
49+
*/
50+
function removeRequiredAttributes(fields) {
51+
fields.forEach(function (fieldId) {
52+
var $field = $('#' + fieldId);
53+
if ($field.length) {
54+
$field.removeAttr('required');
55+
$field.removeClass('required-entry');
56+
}
57+
});
58+
}
1859

1960
element.on('blur', function () {
2061
var currentValue = $element.val();
@@ -32,28 +73,18 @@ define([
3273
text: $t('Cancel'),
3374
class: 'action-secondary action-dismiss',
3475

35-
/**
36-
* Close modal and trigger 'cancel' action on click
37-
*/
3876
click: function (event) {
3977
this.closeModal(event);
4078
}
4179
}, {
4280
text: $t('Confirm'),
4381
class: 'action-primary action-accept',
4482

45-
/**
46-
* Close modal and trigger 'confirm' action on click
47-
*/
4883
click: function (event) {
4984
this.closeModal(event, true);
5085
}
5186
}],
5287
actions: {
53-
54-
/**
55-
* Revert back to original Enabled setting
56-
*/
5788
cancel: function () {
5889
$element.val(initialValue);
5990
}
@@ -62,3 +93,4 @@ define([
6293
});
6394
};
6495
});
96+

0 commit comments

Comments
 (0)