Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The "state" param from the URL and session do not match

In facebook documantion

require('include/facebook/autoload.php'); //SDK directory
$fb = new Facebook\Facebook([
'app_id' => '***********',
'app_secret' => '***********************'
]);

$helper = $fb->getRedirectLoginHelper();
$permissions = ['email', 'public_profile']; // optional
$loginUrl = $helper->getLoginUrl('http://www.meusite.com.br/login-callback.php', $permissions);

When direct it to the url $loginUrl, the return is: Facebook SDK returned an error: Cross-site request forgery validation failed. The "state" param from the URL and session do not match

like image 864
Pedro Henrique Avatar asked Jul 10 '15 17:07

Pedro Henrique


People also ask

What happens if the redirect URL does not match the application?

the redirect URL does not match one of the registered redirect URLs for the application In these cases, the authorization server should display an error to the user informing them of the problem. The server must not redirect the user back to the application. This avoids what is known as an “ open redirector attack .”

What is the ‘state’ parameter for?

Also mentioned in our documentation, the ‘state’ parameter is used for both preventing cross-site request forgery attacks and to maintain user’s state before authentication request occurs:

What to do if the redirect URL parameter is missing?

the redirect URL parameter is missing the redirect URL parameter was invalid, such as if it was a string that does not parse as a URL the redirect URL does not match one of the registered redirect URLs for the application In these cases, the authorization server should display an error to the user informing them of the problem.

Is it safe to pass a URL in plaintext?

Passing URLs in plaintext or in any predictable way is unsafe. Ensure that the state parameter value is: Unique and opaque to ensure that it can be used for defense against CSRF and phishing attacks. If stored in a cookie, it should be signed to prevent forgery.


1 Answers

I had the same error.

The problem occurred because I did getLoginUrl(...) before getAccessToken()

So rid of getLoginUrl(...) in redirected URL and code should works.

like image 170
tasmaniski Avatar answered Sep 19 '22 18:09

tasmaniski