src/Controller/LoginController.php line 45

  1. <?php
  2. namespace App\Controller;
  3. use Exception;
  4. use KnpU\OAuth2ClientBundle\Client\ClientRegistry;
  5. use Symfony\Bridge\Twig\Attribute\Template;
  6. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  7. use Symfony\Component\HttpFoundation\RedirectResponse;
  8. use Symfony\Component\HttpFoundation\Request;
  9. use Symfony\Component\Routing\Annotation\Route;
  10. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  11. class LoginController extends AbstractController
  12. {
  13.     #[Route('/login'name'app_login')]
  14.     #[Template('login/login.html.twig')]
  15.     public function index(AuthenticationUtils $authenticationUtils): array
  16.     {
  17.         // get the login error if there is one
  18.         $error $authenticationUtils->getLastAuthenticationError();
  19.         // last username entered by the user
  20.         $lastUsername $authenticationUtils->getLastUsername();
  21.         return [
  22.             'last_username' => $lastUsername,
  23.             'error'         => $error,
  24.         ];
  25.     }
  26.     /**
  27.      * @throws Exception
  28.      */
  29.     #[Route('/logout'name'app_logout'methods: [Request::METHOD_GET])]
  30.     public function logout()
  31.     {
  32.     }
  33.     /**
  34.      * Link to this controller to start the "connect" process
  35.      */
  36.     #[Route('/connect/google'name'connect_google')]
  37.     public function connectAction(ClientRegistry $clientRegistry): RedirectResponse
  38.     {
  39.         return $clientRegistry
  40.             ->getClient('google'// key used in config/packages/knpu_oauth2_client.yaml
  41.             ->redirect([
  42.                 'profile''email'
  43.             ]);
  44.     }
  45.     /**
  46.      * This should remain blank because we have a guard authenticator
  47.      */
  48.     #[Route('/connect/google/check'name'connect_google_check')]
  49.     public function connectCheckAction()
  50.     {
  51.     }
  52. }