Skip to content
This repository has been archived by the owner on Jan 13, 2022. It is now read-only.

Getting error "Required param state missing from persistent data" #1245

Open
cgkronos opened this issue Jul 7, 2021 · 1 comment
Open

Getting error "Required param state missing from persistent data" #1245

cgkronos opened this issue Jul 7, 2021 · 1 comment

Comments

@cgkronos
Copy link

cgkronos commented Jul 7, 2021

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);
then I make an <A></A> with this 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, what am I doing wrong?

Thanks in advance

@cgkronos
Copy link
Author

cgkronos commented Jul 8, 2021

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant