-
-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from Jitheesh/master
Does not patch rest api #1
- Loading branch information
Showing
8 changed files
with
129 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace MarkShust\DisableTwoFactorAuth\Plugin; | ||
|
||
use Closure; | ||
use Magento\Framework\App\Config\ScopeConfigInterface; | ||
use Magento\Framework\Exception\AuthenticationException; | ||
use Magento\Framework\Exception\InputException; | ||
use Magento\Framework\Exception\LocalizedException; | ||
use Magento\Integration\Api\AdminTokenServiceInterface; | ||
use Magento\TwoFactorAuth\Model\AdminAccessTokenService; | ||
|
||
/** | ||
* Class BypassWebApiTwoFactorAuth | ||
* @package MarkShust\DisableTwoFactorAuth\Plugin | ||
*/ | ||
class BypassTwoFactorAuthForApiTokenGeneration | ||
{ | ||
const XML_PATH_CONFIG_ENABLE_FOR_API_TOKEN_GENERATION = 'twofactorauth/general/enable_for_api_token_generation'; | ||
|
||
/** @var ScopeConfigInterface */ | ||
private ScopeConfigInterface $scopeConfig; | ||
|
||
/** @var AdminTokenServiceInterface */ | ||
private AdminTokenServiceInterface $adminTokenService; | ||
|
||
/** | ||
* BypassTwoFactorAuthForApiTokenGeneration constructor. | ||
* @param AdminTokenServiceInterface $adminTokenService | ||
* @param ScopeConfigInterface $scopeConfig | ||
*/ | ||
public function __construct( | ||
AdminTokenServiceInterface $adminTokenService, | ||
ScopeConfigInterface $scopeConfig | ||
) { | ||
$this->scopeConfig = $scopeConfig; | ||
$this->adminTokenService = $adminTokenService; | ||
} | ||
|
||
/** | ||
* Enables the bypass of 2FA for API token generation. | ||
* This can be useful for third-party vendors during module development. | ||
* | ||
* NOTE: Always keep 2FA enabled within production environments for security purposes. | ||
* | ||
* @param AdminAccessTokenService $subject | ||
* @param Closure $proceed | ||
* @param $username | ||
* @param $password | ||
* @return string | ||
* @throws AuthenticationException | ||
* @throws InputException | ||
* @throws LocalizedException | ||
*/ | ||
public function aroundCreateAdminAccessToken( | ||
AdminAccessTokenService $subject, | ||
Closure $proceed, | ||
$username, | ||
$password | ||
): string { | ||
return $this->scopeConfig->isSetFlag(self::XML_PATH_CONFIG_ENABLE_FOR_API_TOKEN_GENERATION) | ||
? $proceed($username, $password) | ||
: $this->adminTokenService->createAdminAccessToken($username, $password); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters