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 authorization

  • false will fail the authorization

  • null will use the default implementation to decided (default)

AuthorizationEventSubscriber

<?php

declare(strict_types=1);

namespace Full\Qualified\Namespace\Context\Events;

use OxidEsales\GraphQL\Base\Event\BeforeAuthorization;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use function rand;

class AuthorizationEventSubscriber implements EventSubscriberInterface
{
    public function handleAuth(BeforeAuthorization $event): BeforeAuthorization {
        // decide
        if (rand(0, 1)) {
            $event->setAuthorized(true);
        }
        return $event;
    }

    public static function getSubscribedEvents()
    {
        return [
            BeforeAuthorization::class => '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']