Esempio n. 1
0
 /**
  * @param $code
  * @return null
  * @throws \Facebook\FacebookRequestException
  * @throws \Facebook\FacebookSDKException
  */
 protected function getAccessToken($code)
 {
     $response = (new FacebookRequest(FacebookSession::newAppSession(), 'GET', '/oauth/access_token', ['client_id' => FacebookSession::_getTargetAppId(), 'client_secret' => FacebookSession::_getTargetAppSecret(), 'redirect_uri' => Config::get('auth.providers.facebook.redirect_uri'), 'code' => $code]))->execute()->getResponse();
     // Graph v2.3 and greater return objects on the /oauth/access_token endpoint
     $accessToken = null;
     if (is_object($response) && isset($response->access_token)) {
         $accessToken = $response->access_token;
     } elseif (is_array($response) && isset($response['access_token'])) {
         $accessToken = $response['access_token'];
     }
     return $accessToken;
 }
 /**
  * Initialize the helper and process available signed request data.
  *
  * @param string|null $appId
  * @param string|null $appSecret
  */
 public function __construct($appId = null, $appSecret = null)
 {
     $this->appId = FacebookSession::_getTargetAppId($appId);
     $this->appSecret = FacebookSession::_getTargetAppSecret($appSecret);
     $this->instantiateSignedRequest();
 }
 /**
  * Send a request to Graph with an app access token.
  *
  * @param string $endpoint
  * @param array $params
  * @param string|null $appId
  * @param string|null $appSecret
  *
  * @return \Facebook\FacebookResponse
  *
  * @throws FacebookRequestException
  */
 protected static function request($endpoint, array $params, $appId = null, $appSecret = null)
 {
     $targetAppId = FacebookSession::_getTargetAppId($appId);
     $targetAppSecret = FacebookSession::_getTargetAppSecret($appSecret);
     if (!isset($params['client_id'])) {
         $params['client_id'] = $targetAppId;
     }
     if (!isset($params['client_secret'])) {
         $params['client_secret'] = $targetAppSecret;
     }
     // The response for this endpoint is not JSON, so it must be handled
     //   differently, not as a GraphObject.
     $request = new FacebookRequest(FacebookSession::newAppSession($targetAppId, $targetAppSecret), 'GET', $endpoint, $params);
     return $request->execute();
 }
Esempio n. 4
0
 /**
  * @param $name
  * @param array $permissions
  *
  * @return array
  */
 public function createTestUser($name, array $permissions)
 {
     $response = $this->executeFacebookRequest($this->appSession, 'POST', '/' . FacebookSession::_getTargetAppId() . '/accounts/test-users', ['name' => $name, 'installed' => true, 'permissions' => $permissions])->getRawResponse();
     return json_decode($response, true);
 }
 /**
  * Constructs a RedirectLoginHelper for a given appId.
  *
  * @param string $appId The application id
  * @param string $appSecret The application secret
  */
 public function __construct($appId = null, $appSecret = null)
 {
     $this->appId = FacebookSession::_getTargetAppId($appId);
     $this->appSecret = FacebookSession::_getTargetAppSecret($appSecret);
 }
Esempio n. 6
0
 public function fbAuthAction()
 {
     $this->view->disable();
     $params = array('client_id' => FacebookSession::_getTargetAppId($this->config->facebook->appId), 'redirect_uri' => $this->config->facebook->redirect, 'client_secret' => FacebookSession::_getTargetAppSecret($this->config->facebook->secret), 'code' => isset($_GET['code']) ? $_GET['code'] : null);
     $response = (new FacebookRequest(FacebookSession::newAppSession($this->config->facebook->appId, $this->config->facebook->secret), 'GET', '/oauth/access_token', $params))->execute()->getResponse();
     if (isset($response['access_token'])) {
         $session = new FacebookSession($response['access_token']);
     }
     if (isset($session)) {
         $userSession['access_token'] = $response['access_token'];
         $request = new FacebookRequest($session, 'GET', '/me');
         $response = $request->execute();
         // get response
         $graphObject = $response->getGraphObject();
         $email = $graphObject->getProperty('email');
         $fbId = $graphObject->getProperty('id');
         $verified = $graphObject->getProperty('verified');
         $firstName = $graphObject->getProperty('first_name');
         $lastName = $graphObject->getProperty('last_name');
         $fullName = $graphObject->getProperty('name');
         $gender = $graphObject->getProperty('gender');
         $profileLink = $graphObject->getProperty('link');
         $bday = $graphObject->getProperty('birthday');
         $email = $graphObject->getProperty('email');
         $city = $graphObject->getProperty('location')->getProperty('name');
         if (!isset($email)) {
             $email = $fbId . '@facebook.com';
         }
         if (isset($bday)) {
             $bday = date('Y-m-d', strtotime($bday));
         }
         $socialData = array('social_network' => 'Facebook', 'social_id' => $fbId, 'first_name' => $firstName, 'last_name' => $lastName, 'full_name' => $fullName, 'gender' => $gender, 'profile_link' => $profileLink, 'birthday' => $bday, 'email' => $email, 'city' => $city, 'access_token' => $userSession['access_token']);
         if ($member = Members::findFirstByEmail($email)) {
             $userSession = get_object_vars($member);
             if (!($socialProfile = SocialProfiles::findFirstByEmail($email))) {
                 $socialData['member_id'] = $member->id;
                 $this->newSocialProfile($socialData);
             }
         } else {
             $memberId = $this->newMember($socialData);
             $socialData['id'] = $memberId;
             $userSession = $socialData;
             $socialData['member_id'] = $memberId;
             $this->newSocialProfile($socialData);
         }
         //print_r($graphObject);
         $this->session->set('userSession', $userSession);
     }
     return $this->response->redirect();
 }