src/Flexy/FrontBundle/Themes/IlaveU/Controller/OAuth/FacebookController.php line 20
<?php
namespace App\Flexy\FrontBundle\Themes\IlaveU\Controller\OAuth;
namespace App\Flexy\FrontBundle\Themes\IlaveU\Controller\OAuth;
use KnpU\OAuth2ClientBundle\Client\ClientRegistry;
use League\OAuth2\Client\Provider\Exception\IdentityProviderException;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
class FacebookController extends AbstractController
{
/**
* Link to this controller to start the "connect" process
*
* @Route("/{_locale}/connect/facebook", name="connect_facebook_start")
*/
public function connectAction(ClientRegistry $clientRegistry)
{
// on Symfony 3.3 or lower, $clientRegistry = $this->get('knpu.oauth2.registry');
// will redirect to Facebook!
return $clientRegistry
->getClient('facebook_main') // key used in config/packages/knpu_oauth2_client.yaml
->redirect([
'public_profile' // the scopes you want to access
],[]);
}
/**
* After going to Facebook, you're redirected back here
* because this is the "redirect_route" you configured
* in config/packages/knpu_oauth2_client.yaml
*
* @Route("/{_locale}/connect/facebook/check", name="connect_facebook_check")
*/
public function connectCheckAction(Request $request, ClientRegistry $clientRegistry)
{
// ** if you want to *authenticate* the user, then
// leave this method blank and create a Guard authenticator
// (read below)
// /** @var \KnpU\OAuth2ClientBundle\Client\Provider\FacebookClient $client */
// $client = $clientRegistry->getClient('facebook_main');
// try {
// // the exact class depends on which provider you're using
// /** @var \League\OAuth2\Client\Provider\FacebookUser $user */
// $user = $client->fetchUser();
// // do something with all this new power!
// // e.g. $name = $user->getFirstName();
// var_dump($user); die;
// // ...
// } catch (IdentityProviderException $e) {
// // something went wrong!
// // probably you should return the reason to the user
// var_dump($e->getMessage()); die;
// }
}
#[Route('/{_locale}/connect/facebook/afterconnexion', name: 'connect_facebook_after_connexion')]
public function afterConnectionAction(Request $request)
{
return $this->render("@Flexy/FrontBundle/Themes/".$this->container->get('twig')->getGlobals()["settings"]->get()->getAssetFolderName()."/templates/myaccount/oauth/facebook.html.twig");
}
}