Implement authorization checking for external api user using api key

This commit is contained in:
Dillon Ngo
2023-12-03 00:56:42 +08:00
parent fcbb71de7e
commit 77bd84f61b
4 changed files with 88 additions and 1 deletions
@@ -5,6 +5,8 @@ namespace App\Classes\Modules\WePost\ControllersLogic;
use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\Modules\WePost\Services\CreatesWePostNotification;
use App\Classes\Modules\WePost\DataTransferObjects\WePostNotificationObject;
use App\Classes\Modules\WePost\DataTransferObjects\WePostProcessNotificationObject;
use App\Classes\Modules\WePost\Standards\Rules\CanProcessWePostNotification;
use App\Http\Resources\WePostNotificationResource;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
@@ -24,14 +26,19 @@ class ProcessWePostNotificationLogic extends AbstractControllerLogic
/** @var CreatesWePostNotification */
private $createsWePostNotification;
/** @var CanProcessWePostNotification */
private $canProcessWePostNotification;
/**
* ProcessWePostNotificationLogic constructor.
* @param CreatesWePostNotification $createsWePostNotification
* @param CanProcessWePostNotification $canProcessWePostNotification
*/
public function __construct(
CreatesWePostNotification $createsWePostNotification)
CreatesWePostNotification $createsWePostNotification, CanProcessWePostNotification $canProcessWePostNotification)
{
$this->createsWePostNotification = $createsWePostNotification;
$this->canProcessWePostNotification = $canProcessWePostNotification;
}
/**
@@ -43,6 +50,9 @@ class ProcessWePostNotificationLogic extends AbstractControllerLogic
*/
public function logic(Request $request) : JsonResponse
{
$object = new WePostProcessNotificationObject($request->query('api-key'));
$this->canProcessWePostNotification->passes($object);
$request->merge([
'isApiPub' => true,
]);