/** * Retrieves the Session object for the currently logged in user. * * @param boolean $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', '/1/sessions/me', $token, null, $useMasterKey); $session = new ParseSession(); $session->_mergeAfterFetch($response); $session->handleSaveResult(); return $session; }
/** * Parse\Client::initialize, must be called before using Parse features. * * @param string $app_id Parse Application ID * @param string $rest_key Parse REST API Key * @param string $master_key Parse Master Key * @param boolean $enableCurlExceptions Enable or disable Parse curl exceptions * * @return null */ public static function initialize($app_id, $rest_key, $master_key, $enableCurlExceptions = true) { ParseUser::registerSubclass(); ParseRole::registerSubclass(); ParseInstallation::registerSubclass(); ParseSession::registerSubclass(); self::$applicationId = $app_id; self::$restKey = $rest_key; self::$masterKey = $master_key; self::$enableCurlExceptions = $enableCurlExceptions; if (!static::$storage) { if (session_status() === PHP_SESSION_ACTIVE) { self::setStorage(new ParseSessionStorage()); } else { self::setStorage(new ParseMemoryStorage()); } } }
public function testRevocableSession() { ParseClient::enableRevocableSessions(); $user = new ParseUser(); $user->setUsername("username"); $user->setPassword("password"); $user->signUp(); $session = ParseSession::getCurrentSession(); $this->assertEquals($user->getSessionToken(), $session->getSessionToken()); $this->assertTrue($session->isCurrentSessionRevocable()); ParseUser::logOut(); ParseUser::logIn("username", "password"); $session = ParseSession::getCurrentSession(); $this->assertEquals(ParseUser::getCurrentUser()->getSessionToken(), $session->getSessionToken()); $this->assertTrue($session->isCurrentSessionRevocable()); $sessionToken = $session->getSessionToken(); ParseUser::logOut(); $this->setExpectedException('Parse\\ParseException', 'invalid session token'); ParseUser::become($sessionToken); }
/** * Parse\Client::initialize, must be called before using Parse features. * * @param string $app_id Parse Application ID * @param string $rest_key Parse REST API Key * @param string $master_key Parse Master Key * @param bool $enableCurlExceptions Enable or disable Parse curl exceptions * @param string $account_key An account key from Parse.com can enable creating apps via API. * * @throws Exception */ public static function initialize($app_id, $rest_key, $master_key, $enableCurlExceptions = true, $account_key = null) { if (!ParseObject::hasRegisteredSubclass('_User')) { ParseUser::registerSubclass(); } if (!ParseObject::hasRegisteredSubclass('_Role')) { ParseRole::registerSubclass(); } if (!ParseObject::hasRegisteredSubclass('_Installation')) { ParseInstallation::registerSubclass(); } ParseSession::registerSubclass(); self::$applicationId = $app_id; self::$restKey = $rest_key; self::$masterKey = $master_key; self::$enableCurlExceptions = $enableCurlExceptions; self::$accountKey = $account_key; if (!static::$storage) { if (session_status() === PHP_SESSION_ACTIVE) { self::setStorage(new ParseSessionStorage()); } else { self::setStorage(new ParseMemoryStorage()); } } }
/** * Validating user session token * If the session token matches the api key user, it is a valid token * @param String $session_token user session token * @param String $api_key user api key * @return boolean */ public function isValidSessionToken($session_token, $api_key) { // Using already validated $api_key, obtain corresponding user object $query = ParseUser::query(); $query->equalTo("apiKey", $api_key); $results = $query->find(); if (count($results) > 0) { $userObj = $results[0]; } else { return FALSE; } try { // Become user that has this session token // Only was to query back the user that they are // If no user is found with this token, parse error $thisUser = ParseUser::become($session_token); $query = ParseSession::query(); $query->equalTo("user", $userObj); $results = $query->find(); if (count($results) > 0) { return TRUE; } else { return FALSE; } } catch (Parse\ParseException $error) { return FALSE; } }