Skip to content

Commit 54efe6d

Browse files
committed
ACP2E-2755: Issue with rest api after enable 2FA Duo
1 parent 541d7be commit 54efe6d

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

TwoFactorAuth/Model/Provider/Engine/DuoSecurity.php

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,21 @@ class DuoSecurity implements EngineInterface
7777
*/
7878
private $scopeConfig;
7979

80+
/**
81+
* @var bool
82+
*/
83+
private $forceUseDuoAuth;
84+
8085
/**
8186
* @param ScopeConfigInterface $scopeConfig
87+
* @param bool $forceUseDuoAuth
8288
*/
8389
public function __construct(
84-
ScopeConfigInterface $scopeConfig
90+
ScopeConfigInterface $scopeConfig,
91+
bool $forceUseDuoAuth = false
8592
) {
8693
$this->scopeConfig = $scopeConfig;
94+
$this->forceUseDuoAuth = $forceUseDuoAuth;
8795
}
8896

8997
/**
@@ -208,7 +216,7 @@ public function getRequestSignature(UserInterface $user): string
208216
$duoSignature = $this->signValues(
209217
$this->getSecretKey(),
210218
$values,
211-
static::DUO_PREFIX,
219+
$this->getPrefix(),
212220
static::DUO_EXPIRE,
213221
$time
214222
);
@@ -223,6 +231,16 @@ public function getRequestSignature(UserInterface $user): string
223231
return $duoSignature . ':' . $appSignature;
224232
}
225233

234+
/**
235+
* Return prefix to use in the signature
236+
*
237+
* @return string
238+
*/
239+
private function getPrefix() : string
240+
{
241+
return ($this->forceUseDuoAuth) ? static::DUO_PREFIX : static::AUTH_PREFIX;
242+
}
243+
226244
/**
227245
* @inheritDoc
228246
*/
@@ -236,8 +254,8 @@ public function verify(UserInterface $user, DataObject $request): bool
236254
}
237255
[$authSig, $appSig] = $signatures;
238256

257+
$authUser = $this->parseValues($this->getSecretKey(), $authSig, static::AUTH_PREFIX, $time);
239258
$appUser = $this->parseValues($this->getApplicationKey(), $appSig, static::APP_PREFIX, $time);
240-
$authUser = $this->parseValues($this->getSecretKey(), $authSig, static::DUO_PREFIX, $time);
241259

242260
return (($authUser === $appUser) && ($appUser === $user->getUserName()));
243261
}

TwoFactorAuth/etc/adminhtml/di.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,9 @@
2121
<type name="Magento\Backend\Model\Auth">
2222
<plugin name="delete_tfat_cookie" type="Magento\TwoFactorAuth\Plugin\DeleteCookieOnLogout"/>
2323
</type>
24+
<type name="Magento\TwoFactorAuth\Model\Provider\Engine\DuoSecurity">
25+
<arguments>
26+
<argument name="forceUseDuoAuth" xsi:type="boolean">true</argument>
27+
</arguments>
28+
</type>
2429
</config>

0 commit comments

Comments
 (0)