/** * Retrieves the Session object for the currently logged in user. * * @param bool $useMasterKey If the Master Key should be used to override security. * * @return ParseSession */ public static function getCurrentSession($useMasterKey = false) { $token = ParseUser::getCurrentUser()->getSessionToken(); $response = ParseClient::_request('GET', 'sessions/me', $token, null, $useMasterKey); $session = new self(); $session->_mergeAfterFetch($response); $session->handleSaveResult(); return $session; }
/** * Link the user with Facebook details. * * @param string $id the Facebook user identifier * @param string $access_token the access token for this session * @param \DateTime $expiration_date defaults to 60 days * @param bool $useMasterKey whether to override security * * @throws ParseException * * @return ParseUser */ public function linkWithFacebook($id, $access_token, $expiration_date = null, $useMasterKey = false) { if (!$this->getObjectId()) { throw new ParseException('Cannot link an unsaved user, use ParseUser::logInWithFacebook'); } if (!$id) { throw new ParseException('Cannot link Facebook user without an id.'); } if (!$access_token) { throw new ParseException('Cannot link Facebook user without an access token.'); } if (!$expiration_date) { $expiration_date = new \DateTime(); $expiration_date->setTimestamp(time() + 86400 * 60); } $data = ['authData' => ['facebook' => ['id' => $id, 'access_token' => $access_token, 'expiration_date' => ParseClient::getProperDateFormat($expiration_date)]]]; $result = ParseClient::_request('PUT', 'users/' . $this->getObjectId(), $this->getSessionToken(), json_encode($data), $useMasterKey); $user = new self(); $user->_mergeAfterFetch($result); $user->handleSaveResult(true); return $user; }