public function facebookAction()
 {
     $hasError = $this->params()->fromQuery('error', false);
     if (FALSE !== $hasError) {
         $errorCode = $this->params()->fromQuery('error_code', null);
         $errorReason = $this->params()->fromQuery('error_reason', null);
         $data = $this->facebookConfig->getUrlDataForError();
         return $this->redirect()->toRoute($data['routeName'], $data['params'] + array('error_code' => $errorCode, 'error_reason' => $errorReason), true);
     }
     $facebook = new FacebookService($this->facebookConfig);
     $data = $facebook->getData();
     if ($data) {
         $urlData = $this->facebookConfig->getUrlDataForSuccess();
         return $this->pr($data);
         die;
     }
     return $this->redirect()->toUrl($facebook->getLoginUrl($this->url()->fromRoute('third-party-connect', array('controller' => 'identity', 'action' => 'facebook'), array('force_canonical' => true))));
 }
 /**
  * @param FacebookConfig $config
  */
 public function __construct(FacebookConfig $config, Request $request)
 {
     $error = $request->getQuery('error');
     if (!empty($error)) {
         $this->isValid = false;
         return;
     }
     if (!$config->isEnabled()) {
         throw new \Exception('Facebook is not enabled');
     }
     $this->applicationId = $config->getPublicKey();
     $this->applicationSecret = $config->getSecretKey();
     $this->needsExtendedToken = $config->needsExtendedToken();
     $this->returnUrlData = $config->getReturnUrlData();
     $this->shouldDisplayInPopup = $config->shouldDisplayInPopup() ? 'popup' : 'page';
     foreach ($config->getPermissions() as $perm) {
         if (!in_array($perm, $this->allowedPermissions)) {
             throw new \Exception(sprintf('%s is not a valid Facebook permission', $perm));
         }
         $this->permissions[] = $perm;
     }
 }