src/Controller/Security/SecurityController.php line 23

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Security;
  3. use KnpU\OAuth2ClientBundle\Client\ClientRegistry;
  4. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  5. use Symfony\Component\HttpFoundation\RedirectResponse;
  6. use Symfony\Component\HttpFoundation\Response;
  7. use Symfony\Component\Routing\Annotation\Route;
  8. class SecurityController extends AbstractController
  9. {
  10.     public const SCOPES=[
  11.         'google'=>[],
  12.     ];
  13.     #[Route(path'/logout'name'app_logout')]
  14.     public function logout(): void
  15.     {
  16.         throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');
  17.     }
  18.     #[Route("/oauth/connect/{service}"name'auth_oauth_connect'methods: ['GET'])]
  19.     public function connect(string $service,ClientRegistry $clientRegistry): RedirectResponse
  20.     {
  21.         if(! in_array($service,array_keys(self::SCOPES),true)){
  22.             throw $this->createNotFoundException();
  23.         }
  24.         return $clientRegistry
  25.             ->getClient($service)
  26.             ->redirect(self::SCOPES[$service]);
  27.     }
  28.     #[Route("/oauth/check/{service}"name'auth_oauth_check'methods: ['GET''POST'])]
  29.     public function check():Response
  30.     {
  31.         return new Response(status200);
  32.     }
  33. }