BeforeAuthorization
This event will be fired when authorization is done. You may call the
setAuthorized(?bool $flag = null)
method to oversteer the default authorization logic.
true
will succeed the authorizationfalse
will fail the authorizationnull
will use the default implementation to decided (default)
AuthorizationEventSubscriber
<?php
declare(strict_types=1);
namespace Full\Qualified\Namespace\Context\Events;
use OxidEsales\EshopCommunity\Internal\Framework\Event\AbstractShopAwareEventSubscriber;
use OxidEsales\GraphQL\Base\Event\BeforeAuthorization;
use function rand;
class AuthorizationEventSubscriber extends AbstractShopAwareEventSubscriber
{
public function handleAuth(BeforeAuthorization $event): BeforeAuthorization {
// decide
if (rand(0, 1)) {
$event->setAuthorized(true);
}
return $event;
}
public static function getSubscribedEvents()
{
return [
BeforeAuthorization::NAME => 'handleAuth'
];
}
}
Important
The code above is only an example. In case you need to handle the BeforeAuthorization
event,
please adapt to your needs.
services.yaml
services:
Full\Qualified\Namespace\DeveloperAuthorizationEventSubscriber:
class: Full\Qualified\Namespace\DeveloperAuthorizationEventSubscriber
tags: ['kernel.event_subscriber']