src/EventSubscriber/OAuthSubscriber.php line 32

Open in your IDE?
  1. <?php
  2. /*
  3. * This file is part of the nellapp-core package.
  4. *
  5. * (c) Benjamin Georgeault
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace App\EventSubscriber;
  11. use App\Entity\OAuth\Client;
  12. use FOS\OAuthServerBundle\Event\PreAuthorizationEvent;
  13. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  14. /**
  15. * Class OAuthSubscriber
  16. *
  17. * @author Benjamin Georgeault
  18. */
  19. class OAuthSubscriber implements EventSubscriberInterface
  20. {
  21. public static function getSubscribedEvents(): array
  22. {
  23. return [
  24. PreAuthorizationEvent::class => 'onPreAuthorization',
  25. ];
  26. }
  27. public function onPreAuthorization(PreAuthorizationEvent $event): void
  28. {
  29. $client = $event->getClient();
  30. if (!$client instanceof Client) {
  31. return;
  32. }
  33. if ($client->isAutoAccept()) {
  34. $event->setAuthorizedClient(true);
  35. }
  36. }
  37. }