This topic contains a post which is marked as Best Answer. Press here if you would like to see it.
*

Olegs

  • ****
  • 123 posts
Facebook SDK returned an error
« on: May 23, 2019, 11:46:06 PM »
such an error periodically comes out, we cannot understand what it is the reason.
but after 2-3 minutes it disappears, and the login is done successfully, but after leaving the profile, you can’t go back, this error appears again

Facebook SDK returned an error: Cross-site request forgery validation failed. The "state" param from the URL and session do not match.

*

MB Themes

Re: Facebook SDK returned an error
« Reply #1 on: May 24, 2019, 08:45:56 AM »
I got this error once as well, then never again.
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots

*

Olegs

  • ****
  • 123 posts
Re: Facebook SDK returned an error
« Reply #2 on: May 24, 2019, 09:06:49 AM »
Its looks like the problem is in the code,

Found this in one forum,


Quote
There could be 2 reason for this error:

you didn't call session_start(); before getLoginUrl call
You executed getLoginUrl again in login-callback.php, so state value regenerated and mismatched with the redirected value

and

Quote
I had the same problem.

The reason for this error is because --->

When "$helper->getLoginUrl" calls, it create a session variable "FB_State", and this is something to FB uses to match the token. Every-time getLoginUrl calls, it create new state. Then after user authorized and redirect back, if you codes cannot detect this event and re-run "$helper->getLoginUrl", then this error will occur.

The solution ->

refine your coding, stop run "$helper->getLoginUrl" again if authorized.

if you already rerun, then set the session variable for the token to NULL if you have, then User can re-authorize again.

when user tries re-authorize, they can remove the authorized APP once or you need to generate new link with "$helper->getReRequestUrl"

Yet, token has be called by "getAccessToken()" before the "$helper->getLoginUrl" or "$helper->getReRequestUrl" runs.

Good Luck!!!!!



@MbThemes, maybe you can help with that

*

Olegs

  • ****
  • 123 posts
Re: Facebook SDK returned an error
« Reply #3 on: May 26, 2019, 03:36:09 PM »
@MbThemes,

the reason of this issue is cache plug-in, When I turn off the cache on the home page, fb login plugin working properly and without errors. As soon as I turn ON cache on Home page, this message appears.

I hope that you look at the possibility of correcting this error.

Thanks

*

MB Themes

Re: Facebook SDK returned an error
« Reply #4 on: May 26, 2019, 05:27:23 PM »
That is strange, plugin should disable cache when fb login request is coming
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots

*

Mostapha R.

  • ***
  • 20 posts
Re: Facebook SDK returned an error
« Reply #5 on: August 05, 2019, 11:45:12 AM »
I'm facing the same problem, And i dont have cache plugin! any advice?

Marked as best answer by frosticek on August 05, 2019, 02:17:04 PM
*

Mostapha R.

  • ***
  • 20 posts
Re: Facebook SDK returned an error
« Reply #6 on: August 05, 2019, 12:05:57 PM »
I found this solution to fix it guys we need to insert below code after $helper = $fb->getRedirectLoginHelper();

if (isset($_GET['state'])) {
    $helper->getPersistentDataHandler()->set('state', $_GET['state']);
}

Read more at:

https://stackoverflow.com/questions/32029116/facebook-sdk-returned-an-error-cross-site-request-forgery-validation-failed-th
« Last Edit: August 05, 2019, 12:11:09 PM by Mostapha R. »