Skip to content

Commit

Permalink
disable customer webapi
Browse files Browse the repository at this point in the history
  • Loading branch information
ronangr1 committed Sep 22, 2024
1 parent 20252ea commit 0a653ae
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
32 changes: 32 additions & 0 deletions Plugin/Webapi/Controller/Rest/DisableApi.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
/**
* Copyright © OpenGento, All rights reserved.
* See LICENSE bundled with this library for license details.
*/
declare(strict_types=1);

namespace Opengento\Hoodoor\Plugin\Webapi\Controller\Rest;

use Magento\Framework\App\RequestInterface;
use Magento\Framework\Exception\AuthorizationException;
use Magento\Webapi\Controller\Rest;

class DisableApi
{
public function beforeDispatch(Rest $subject, RequestInterface $request)
{
$blockedRoutes = [
'rest/V1/customers',
'rest/all/V1/customers',
'rest/default/V1/customers'
];

$currentPath = $request->getPathInfo();

foreach ($blockedRoutes as $route) {
if (str_contains($currentPath, $route)) {
throw new AuthorizationException(__('Access to this API is disabled.'));
}
}
}
}
2 changes: 1 addition & 1 deletion Service/JwtManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace Opengento\Hoodoor\Service;

use \Firebase\JWT\JWT;
use Firebase\JWT\JWT;
use Firebase\JWT\Key;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Opengento\Hoodoor\Enum\Config;
Expand Down
3 changes: 3 additions & 0 deletions etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,7 @@
type="Opengento\Hoodoor\Controller\Account\ForgotPasswordPost" />
<preference for="Magento\Customer\Controller\Account\Edit"
type="Opengento\Hoodoor\Controller\Account\Edit" />
<type name="Magento\Webapi\Controller\Rest">
<plugin name="hoodoor_disable_customer_webapi" type="Opengento\Hoodoor\Plugin\Webapi\Controller\Rest\DisableApi" />
</type>
</config>

0 comments on commit 0a653ae

Please sign in to comment.