PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, December 28, 2021

[FIXED] Required param state missing from persistent data

 December 28, 2021     facebook-php-sdk     No comments   

Issue

I've an issue with php-graph-sdk, I've those functions

 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;
        }
        ....
  }

And I do

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

And in the callback file

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

When I click on the link, the callback file is executed and $helper->getAccessToken(); causes this error: Uncaught Facebook\Exceptions\FacebookSDKException: Cross-site request forgery validation failed. Required param "state" missing from persistent data.

I've seen posts about that and no fix works for me

EDIT: What I've found currently is that: 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 and https://github.com/facebookarchive/php-graph-sdk/issues/1123 https://github.com/facebookarchive/php-graph-sdk/issues/1134


Solution

Finally I've solved my issue by switching samesite to Lax by adding that in config.php ini_set('session.cookie_samesite','Lax');



Answered By - Camille Gallet
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing