public function testSessionInfo()
 {
     $params = array('input_token' => FacebookTestHelper::$testSession->getToken());
     $response = (new FacebookRequest(new FacebookSession(FacebookTestHelper::getAppToken()), 'GET', '/debug_token', $params))->execute()->getGraphObject(GraphSessionInfo::className());
     $this->assertTrue($response instanceof GraphSessionInfo);
     $this->assertNotNull($response->getAppId());
     $this->assertTrue($response->isValid());
 }
 /**
  * Ensures the provided GraphSessionInfo object is valid,
  *   throwing an exception if not.  Ensures the appId matches,
  *   that the machineId matches if it's being used,
  *   that the token is valid and has not expired.
  *
  * @param GraphSessionInfo $tokenInfo
  * @param FacebookApp $app The FacebookApp entity.
  * @param string|null $machineId
  *
  * @return boolean
  */
 public static function validateAccessToken(GraphSessionInfo $tokenInfo, FacebookApp $app, $machineId = null)
 {
     $appIdIsValid = $tokenInfo->getProperty('app_id') == $app->getId();
     $machineIdIsValid = $tokenInfo->getProperty('machine_id') == $machineId;
     $accessTokenIsValid = $tokenInfo->getIsValid();
     // Not all access tokens return an expiration. E.g. an app access token.
     if ($tokenInfo->getExpiresAt() instanceof \DateTime) {
         $accessTokenIsStillAlive = $tokenInfo->getExpiresAt()->getTimestamp() >= time();
     } else {
         $accessTokenIsStillAlive = true;
     }
     return $appIdIsValid && $machineIdIsValid && $accessTokenIsValid && $accessTokenIsStillAlive;
 }
Ejemplo n.º 3
0
 /**
  * Get more info about an access token.
  *
  * @param string|null $appId
  * @param string|null $appSecret
  *
  * @return GraphSessionInfo
  */
 public function getInfo($appId = null, $appSecret = null)
 {
     $params = array('input_token' => $this->accessToken);
     $request = new FacebookRequest(FacebookSession::newAppSession($appId, $appSecret), 'GET', '/debug_token', $params);
     $response = $request->execute()->getGraphObject(GraphSessionInfo::className());
     // Update the data on this token
     if ($response->getExpiresAt()) {
         $this->expiresAt = $response->getExpiresAt();
     }
     return $response;
 }