/** * Connect facebook user * Uses Facebook api to determine login state. * Retrieve and set user data and permissions. * * @return boolean */ public function connect() { $uid = $this->FacebookApi->getUser(); $accessToken = $this->FacebookApi->getAccessToken(); // check if accessToken has changed (e.g. after requesting/revoking permissions) if ($this->_accessToken !== $accessToken) { // reset without destroying the facebook session $this->disconnect(false); } if ($uid && $this->user) { // connected and active session // we are all set. just return the cached user data. // Check UserIds if ($uid === $this->user['id']) { return true; } // UserIds do not match // reset without destroying the facebook session // and update user info $this->disconnect(false); $this->log(__d('facebook', 'UserIds do not match. Expected: %s / Actual: %s. Disconnect.', $this->user['id'], $uid), 'warning'); } elseif (!$uid && $this->user) { // not connected but active session // reset the session $this->log(__d('facebook', 'User with ID %s is not connected but has active session. Disconnect.', $uid), 'info'); $this->disconnect(true); return false; } elseif (!$uid) { // not connected return false; } //@todo confirm identity/verify access token //@see https://developers.facebook.com/docs/facebook-login/manually-build-a-login-flow/#confirm // connected but not in session // retrieve data from facebook $this->updateUserInfo(); $this->log(__d('facebook', 'Connected user with ID %s', $uid), 'info'); //@todo dispatch event facebook.connect return true; }