-
-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
125 additions
and
91 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 was deleted.
Oops, something went wrong.
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
Typed properties are supported from PHP7.4 and up, in PHP7.3 this will result in a Parse error.
https://www.php.net/manual/en/migration74.new-features.php#migration74.new-features.core.typed-properties