예제 #1
0
 /**
  * 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 boolean $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", "/1/users/" . $this->getObjectId(), $this->getSessionToken(), json_encode($data), $useMasterKey);
     $user = new ParseUser();
     $user->_mergeAfterFetch($result);
     $user->handleSaveResult(true);
     return $user;
 }
예제 #2
0
 /**
  * Logs in a user with a session token.  Calls the /users/me route and if
  *   valid, creates and returns the current user.
  *
  * @param string $sessionToken
  *
  * @return ParseUser
  */
 public static function become($sessionToken)
 {
     $result = ParseClient::_request('GET', '/1/users/me', $sessionToken);
     $user = new ParseUser();
     $user->_mergeAfterFetch($result);
     $user->handleSaveResult(true);
     ParseClient::getStorage()->set("user", $user);
     return $user;
 }