【问题标题】:Required param state missing from persistent data持久数据中缺少必需的参数状态
【发布时间】:2021-09-18 02:39:19
【问题描述】:

我的 php-graph-sdk 有问题,我有这些功能

 protected function getFacebook()
    {
        static $facebook = null;
        if($facebook == null){
            $facebook =  new Facebook\Facebook([
                'app_id' => $this->getAppId(),
                'app_secret' => $this->getAppSecret(),
                'default_graph_version' => 'v2.10'
            ]);
        }
        return $facebook;
    }
public function getLoginUrl($url)
    {
        $fb = $this->getFacebook();
        
        $helper = $fb->getRedirectLoginHelper();
        
        $autorisations = ['email']; 
        return $helper->getLoginUrl($url , $autorisations);
    }
 public function callback(&$error = null)
    {
        $fb = $this->getFacebook();
        
        $helper = $fb->getRedirectLoginHelper();
        
        try {
            $accessToken = $helper->getAccessToken();
        } catch(Facebook\Exception\ResponseException $e) {
            // When Graph returns an error
            $error = 'Graph returned an error: ' . $e->getMessage();
            return false;
        } catch(Facebook\Exception\SDKException $e) {
            // When validation fails or other local issues
            $error = 'Facebook SDK returned an error: ' . $e->getMessage();
            return false;
        }
        ....
  }

我愿意

 $url = $Facebook->getLoginUrl(URL);

在回调文件中

$token = $Facebook->callback($error);

当我点击链接时,回调文件被执行并且 $helper->getAccessToken();导致此错误: 未捕获的 Facebook\Exceptions\FacebookSDKException:跨站点请求伪造验证失败。持久数据中缺少必需的参数“状态”。

我已经看到了有关此的帖子,但没有任何解决方法适合我

编辑: 我目前发现的是:Facebook SDK error: Cross-site request forgery validation failed. Required param "state" missing from persistent data Cross-site request forgery validation failed required param state missing from persistent data 和 https://github.com/facebookarchive/php-graph-sdk/issues/1123 https://github.com/facebookarchive/php-graph-sdk/issues/1134

【问题讨论】:

  • 您提到您已看到有关此的帖子,但没有适合您的修复程序。为了帮助社区避免建议您已经尝试过的修复,您可以编辑您的帖子以包含您已经尝试过的内容吗?
  • 您能否检查在将用户发送到登录对话框之前和重定向回来之后,PHP 会话 ID 是否保持不变?可能是会话 cookie 的 SameSite 属性有问题。
  • session_id()前后总是5a128v17bor5divgr3tiire56
  • session_get_cookie_params()["samesite"]: 是 ""

标签: facebook-php-sdk


【解决方案1】:

最后,我通过在 config.php 中添加将 samesite 切换到 Lax 解决了我的问题 ini_set('session.cookie_samesite','Lax');

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-05
    • 2012-08-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多