src/Controller/Bo/GoogleController.php line 15

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Bo;
  3. use KnpU\OAuth2ClientBundle\Client\ClientRegistry;
  4. use KnpU\OAuth2ClientBundle\Client\Provider\GoogleClient;
  5. use League\OAuth2\Client\Provider\Exception\IdentityProviderException;
  6. use League\OAuth2\Client\Provider\GoogleUser;
  7. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  8. use Symfony\Component\HttpFoundation\RedirectResponse;
  9. use Symfony\Component\Routing\Annotation\Route;
  10. class GoogleController extends AbstractController
  11. {
  12.     #[Route('/connect/google'name'connect_google')]
  13.     public function connectAction(ClientRegistry $clientRegistry)
  14.     {
  15.         return $clientRegistry
  16.             ->getClient('google')
  17.             ->redirect();
  18.     }
  19.     #[Route('/connect/google/check'name'connect_google_check')]
  20.     public function connectCheckAction(ClientRegistry $clientRegistry): RedirectResponse
  21.     {
  22.         /** @var GoogleClient $client */
  23.         $client $clientRegistry->getClient('google');
  24.         try {
  25.             /** @var GoogleUser $user */
  26.             $user $client->fetchUser();
  27.             var_dump($user); die;
  28.         } catch (IdentityProviderException $e) {
  29.             var_dump($e->getMessage()); die;
  30.         }
  31.     }
  32. }