When trying to execute - $helper->getAccessToken() - gives an error - 'Cross-site request forgery validation failed. Required param "state" missing from persistent data'
Used symfony 3.3 and facebook/graph-sdk 5.4
All domains added
'FBRLH_state' exists
Session started
// Create url
$facebookCallbackUrl = 'https://' . $base . '/' . $_locale . '/fb-callback';
$loginfb = $this->get('app.lmfacebook')->getSigninURL($this->getParameter('fbappid'), $this->getParameter('fbsecretkey'), $facebookCallbackUrl);
<?php
namespace AppBundle\Services\Ukraine;
use Facebook\Facebook;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
class LMFacebook extends Controller
{
public static function getSigninURL($fbId, $fbSecret, $callback)
{
$fb = new Facebook([
'app_id' => $fbId,
'app_secret' => $fbSecret,
'default_graph_version' => 'v2.9',
'persistent_data_handler' => 'session'
]);
$permissions = ['email'];
return $fb->getRedirectLoginHelper()->getLoginUrl($callback, $permissions);
}
}
$facebookCallbackUrl = 'https://' . $base . '/' . $_locale . '/fb-callback';
$loginfb = $this->get('app.lmfacebook')->getSigninURL($this->getParameter('fbappid'), $this->getParameter('fbsecretkey'), $facebookCallbackUrl);
)
// Facebook callback
/**
* @Route("/{_locale}/fb-callback", name="fb-callback", defaults={"_locale": "ua"}, requirements={"_locale" : "ua|en|ru"})
* @param Request $request
* @param $_locale
* @return mixed
*/
public function fbCallbackAction(Request $request, $_locale)
{
$session = $request->getSession();
$fb = new Facebook([
'app_id' => ********,
'app_secret' => *******,
'default_graph_version' => 'v2.9',
'persistent_data_handler' => 'session'
]);
$helper = $fb->getRedirectLoginHelper();
try {
$accessToken = $helper->getAccessToken(); // Error
} catch (\Exception $exception) {
$this->logToFile('Facebook returned an error: ' . $exception->getMessage());
exit;
}
Please make sure the state param value in login link is refreshing each time you're re-attempting to login.
same problem here
@abhij89 state value is in fact changing each time
Hello there i have the same problem did anyone got a solution please
What Helps me, was add session_start(); at the begining of file.
I have it in login.php but i dont have it in my callback.php file.
When i add it, the problem was solved.
I hope that can help YoU.
still didn't work
same problem here
@abhij89 state value is in fact changing each time
Interesting, 'cause I have the same trouble, but for me it only works once and then throws the error message, so I'll try and let you know the outcome.
hi, could anyone solve this problem? I do not know what to do
Most helpful comment
What Helps me, was add session_start(); at the begining of file.
I have it in login.php but i dont have it in my callback.php file.
When i add it, the problem was solved.
I hope that can help YoU.