<?php
/*
* This file is part of the nellapp-core package.
*
* (c) Benjamin Georgeault
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace App\EventSubscriber;
use App\Entity\OAuth\Client;
use FOS\OAuthServerBundle\Event\PreAuthorizationEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
/**
* Class OAuthSubscriber
*
* @author Benjamin Georgeault
*/
class OAuthSubscriber implements EventSubscriberInterface
{
public static function getSubscribedEvents(): array
{
return [
PreAuthorizationEvent::class => 'onPreAuthorization',
];
}
public function onPreAuthorization(PreAuthorizationEvent $event): void
{
$client = $event->getClient();
if (!$client instanceof Client) {
return;
}
if ($client->isAutoAccept()) {
$event->setAuthorizedClient(true);
}
}
}