Osclass Support Forums

Osclass plugin support => Free Osclass Plugins => Facebook Login Plugin => Topic started by: Olegs on May 23, 2019, 11:46:06 PM

Title: Facebook SDK returned an error
Post by: Olegs 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.
Title: Re: Facebook SDK returned an error
Post by: MB Themes on May 24, 2019, 08:45:56 AM
I got this error once as well, then never again.
Title: Re: Facebook SDK returned an error
Post by: Olegs 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
Title: Re: Facebook SDK returned an error
Post by: Olegs 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
Title: Re: Facebook SDK returned an error
Post by: MB Themes on May 26, 2019, 05:27:23 PM
That is strange, plugin should disable cache when fb login request is coming
Title: Re: Facebook SDK returned an error
Post by: Mostapha R. on August 05, 2019, 11:45:12 AM
I'm facing the same problem, And i dont have cache plugin! any advice?
Title: Re: Facebook SDK returned an error
Post by: Mostapha R. 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