src/Controller/SocialLoginController.php line 18

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use KnpU\OAuth2ClientBundle\Client\ClientRegistry;
  4. use League\OAuth2\Client\Provider\Exception\IdentityProviderException;
  5. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  6. use Symfony\Component\HttpFoundation\Request;
  7. use Symfony\Component\Routing\Annotation\Route;
  8. class SocialLoginController extends AbstractController
  9. {
  10.     /**
  11.      * Link to this controller to start the "connect" process
  12.      *
  13.      * @Route("/connect/facebook", name="connect_facebook_start")
  14.      */
  15.     public function connectFacebookAction(ClientRegistry $clientRegistry)
  16.     {
  17.         // will redirect to Facebook!
  18.         return $clientRegistry
  19.             ->getClient('facebook_main'// key used in config/packages/knpu_oauth2_client.yaml
  20.             ->redirect([
  21.                 'public_profile''email' // the scopes you want to access
  22.             ], []);
  23.     }
  24.     /**
  25.      * After going to Facebook, you're redirected back here
  26.      * because this is the "redirect_route" you configured
  27.      * in config/packages/knpu_oauth2_client.yaml
  28.      *
  29.      * @Route("/connect/facebook/check", name="connect_facebook_check")
  30.      */
  31.     public function connectFacebookCheckAction(Request $requestClientRegistry $clientRegistry)
  32.     {
  33.     }
  34.     /**
  35.      * @Route("/connect/google", name="connect_google_start")
  36.      */
  37.     public function connectGoogleAction(ClientRegistry $clientRegistry)
  38.     {
  39.         return $clientRegistry
  40.             ->getClient('google_main'// key used in config/packages/knpu_oauth2_client.yaml
  41.             ->redirect([], []);
  42.     }
  43.     /**
  44.      * @Route("/connect/google/check", name="connect_google_check")
  45.      */
  46.     public function connectGoogleCheckAction(Request $requestClientRegistry $clientRegistry)
  47.     {
  48.     }
  49.     /**
  50.      * @Route("/connect/instagram", name="connect_instagram_start")
  51.      */
  52.     public function connectInstagramAction(ClientRegistry $clientRegistry)
  53.     {
  54.         // will redirect to Facebook!
  55.         return $clientRegistry
  56.             ->getClient('instagram_main'// key used in config/packages/knpu_oauth2_client.yaml
  57.             ->redirect([
  58.                 'user_profile' // the scopes you want to access
  59.             ], []);
  60.     }
  61.     /**
  62.      * @Route("/connect/instagram/check", name="connect_instagram_check")
  63.      */
  64.     public function connectInstagramCheckAction(Request $requestClientRegistry $clientRegistry)
  65.     {
  66.     }
  67. }