src/Flexy/FrontBundle/Themes/IlaveU/Controller/OAuth/FacebookController.php line 20

  1. <?php
  2. namespace App\Flexy\FrontBundle\Themes\IlaveU\Controller\OAuth;
  3. namespace App\Flexy\FrontBundle\Themes\IlaveU\Controller\OAuth;
  4. use KnpU\OAuth2ClientBundle\Client\ClientRegistry;
  5. use League\OAuth2\Client\Provider\Exception\IdentityProviderException;
  6. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  7. use Symfony\Component\HttpFoundation\Request;
  8. use Symfony\Component\Routing\Annotation\Route;
  9. class FacebookController extends AbstractController
  10. {
  11.     /**
  12.      * Link to this controller to start the "connect" process
  13.      *
  14.      * @Route("/{_locale}/connect/facebook", name="connect_facebook_start")
  15.      */
  16.     public function connectAction(ClientRegistry $clientRegistry)
  17.     {
  18.         // on Symfony 3.3 or lower, $clientRegistry = $this->get('knpu.oauth2.registry');
  19.         // will redirect to Facebook!
  20.         return $clientRegistry
  21.             ->getClient('facebook_main'// key used in config/packages/knpu_oauth2_client.yaml
  22.             ->redirect([
  23.                 'public_profile' // the scopes you want to access
  24.             ],[]);
  25.     }
  26.     /**
  27.      * After going to Facebook, you're redirected back here
  28.      * because this is the "redirect_route" you configured
  29.      * in config/packages/knpu_oauth2_client.yaml
  30.      *
  31.      * @Route("/{_locale}/connect/facebook/check", name="connect_facebook_check")
  32.      */
  33.     public function connectCheckAction(Request $requestClientRegistry $clientRegistry)
  34.     {
  35.         // ** if you want to *authenticate* the user, then
  36.         // leave this method blank and create a Guard authenticator
  37.         // (read below)
  38.         // /** @var \KnpU\OAuth2ClientBundle\Client\Provider\FacebookClient $client */
  39.         // $client = $clientRegistry->getClient('facebook_main');
  40.         // try {
  41.         //     // the exact class depends on which provider you're using
  42.         //     /** @var \League\OAuth2\Client\Provider\FacebookUser $user */
  43.         //     $user = $client->fetchUser();
  44.         //     // do something with all this new power!
  45.         //     // e.g. $name = $user->getFirstName();
  46.         //     var_dump($user); die;
  47.         //     // ...
  48.         // } catch (IdentityProviderException $e) {
  49.         //     // something went wrong!
  50.         //     // probably you should return the reason to the user
  51.         //     var_dump($e->getMessage()); die;
  52.         // }
  53.     }
  54.     #[Route('/{_locale}/connect/facebook/afterconnexion'name'connect_facebook_after_connexion')]
  55.     public function afterConnectionAction(Request $request)
  56.     {
  57.         return $this->render("@Flexy/FrontBundle/Themes/".$this->container->get('twig')->getGlobals()["settings"]->get()->getAssetFolderName()."/templates/myaccount/oauth/facebook.html.twig");
  58.     }
  59. }