奇怪的Facebook API行为。 CSRF状态令牌与提供的令牌不匹配

时间:2012-10-14 08:16:02

标签: php facebook facebook-php-sdk

  

可能重复:
  CSRF state token does not match one provided FB PHP SDK 3.1.1 Oauth 2.0
  CSRF state token does not match one provided

我一遍又一遍地检查Devs面临与Facebook API类似的问题。 PHP-SDK会在每次运行

时记录错误
CSRF state token does not match one provided.

奇怪的是,预期的应用程序似乎工作正常(这是批量发布脚本,一旦我重置批处理,它就会生成此错误。)

所以我在PHP-SDK提供的here中跟踪了base_facebook.php。并更改了此代码(在here中):

protected function getCode() {
    if (isset($_REQUEST['code'])) {
      if ($this->state !== null &&
          isset($_REQUEST['state']) &&
          $this->state === $_REQUEST['state']) {

        // CSRF state has done its job, so clear it
        $this->state = null;
        $this->clearPersistentData('state');
        return $_REQUEST['code'];
      } else {
        self::errorLog('CSRF state token does not match one provided.');
        return false;
      }
    }

到这个(只是为了跟踪错误日志中的错误):

protected function getCode() {
    if (isset($_REQUEST['code'])) {
      if ($this->state !== null && isset($_REQUEST['state']) && $this->state == $_REQUEST['state']) {
        // CSRF state has done its job, so clear it
        $this->state = null;
        $this->clearPersistentData('state');
        return $_REQUEST['code'];
      } else {
        $add = '';
        if($this->state == null){
            $add .= ' state is null.';
        }
        if(!isset($_REQUEST['state'])){
            $add .= ' state is not set.';
        }
        if($this->state !== $_REQUEST['state']){
            $add .= ' states do not match.';
        }
        self::errorLog('CSRF state token does not match one provided.'. $add);
        return false;
      }
    }

    return false;
  }

再次运行应用程序时,我收到更新错误:

CSRF state token does not match one provided. state is null. states do not match.

现在,$ this-> state()为NULL,我没想到这是facebook sdk中最少的错误。我确定我的应用只会生成一个登录网址请求,只有当用户没有与我的应用会话时才会生成。

帮助将不胜感激。

0 个答案:

没有答案