src/Controller/Oauth/GoogleController.php line 21

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Oauth;
  3. use KnpU\OAuth2ClientBundle\Client\ClientRegistry;
  4. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  5. use Symfony\Component\HttpFoundation\RedirectResponse;
  6. use Symfony\Component\HttpFoundation\Request;
  7. use Symfony\Component\Routing\Annotation\Route;
  8. class GoogleController extends AbstractController
  9. {
  10.     /**
  11.      * Link to this controller to start the "connect" process
  12.      * @param ClientRegistry $clientRegistry
  13.      *
  14.      * @Route("/connect/google", name="connect_google_start")
  15.      *
  16.      * @return RedirectResponse
  17.      */
  18.     public function connectAction(ClientRegistry $clientRegistry)
  19.     {
  20.         return $clientRegistry
  21.             ->getClient('google')
  22.             ->redirect(
  23.                 [
  24.                     'profile',
  25.                     'email' // the scopes you want to access,
  26.                 ],
  27.                 []
  28.             );
  29.     }
  30.     /**
  31.      * After going to Google, you're redirected back here
  32.      * because this is the "redirect_route" you configured
  33.      * in config/packages/knpu_oauth2_client.yaml
  34.      *
  35.      * @param Request $request
  36.      * @param ClientRegistry $clientRegistry
  37.      *
  38.      * @Route("/connect/google/check", name="connect_google_check")
  39.      * @return RedirectResponse
  40.      */
  41.     public function connectCheckAction(Request $requestClientRegistry $clientRegistry)
  42.     {
  43.         return $this->redirectToRoute('dashboard');
  44.     }
  45. }