Example #1
0
 /**
  * Determines the connected user by first examining any signed
  * requests, then considering an authorization code, and then
  * falling back to any persistent store storing the user.
  *
  * @return integer The id of the connected Facebook user, or 0 if no such user exists.
  */
 protected function getUserFromAvailableData()
 {
     // if a signed request is supplied, then it solely determines
     // who the user is.
     if ($signedRequest = $this->getSignedRequest()) {
         if (array_key_exists('user_id', $signedRequest)) {
             if ($signedRequest['user_id'] != $this->session->user_id) {
                 $this->session->clearAll();
             }
             return $this->session->user_id = $signedRequest['user_id'];
         }
         // if the signed request didn't present a user id, then invalidate
         // all entries in any persistent store.
         $this->session->clearAll();
         return 0;
     }
     $user = $this->session->get('user_id', 0);
     // use access_token to fetch user id if we have a user access_token, or if
     // the cached access token has changed.
     if (($accessToken = $this->getAccessToken()) && $accessToken !== $this->config->getApplicationAccessToken() && !($user && $this->session->access_token === $accessToken)) {
         if (!($user = $this->getUserFromAccessToken())) {
             $this->session->clearAll();
         } else {
             $this->session->user_id = $user;
         }
     }
     return $user;
 }
Example #2
0
 /**
  * @param \Nette\Http\Session $session
  * @param Configuration $config
  */
 public function __construct(Nette\Http\Session $session, Configuration $config)
 {
     $this->session = $session->getSection('Facebook/' . $config->getApplicationAccessToken());
 }