My server logs show a "CSRF state token does not match one provided" error which seems to happen for almost every user. However, the users are created and/or authenticated and I am able to retrieve the user info. I am using a Linux server with Apache. I am also using the latest Facebook PHP SDK v.3.1.1 Can anyone tell me why this is happening and how to fix it?
相关问题
- facebook error invalid key hash for some devices
- LoginActivty with Firebase & Facebook authenticati
- Multiple Django sites on the same domain - CSRF fa
- Obtaining Refresh Token from lepture/Authlib throu
- YouTube API refresh token revoked with 400 code “i
相关文章
- Facebook login for group members
- The method FB.api will stop working when called fr
- Why is redirect_uri required on Access Token reque
- React native deep linking vs Facebook SDK conflct
- Django REST Framework - OAuth2 Consumer API from e
- UIActivity with no settings for Facebook
- Google OAuth 2.0 User id datatype for MYSQL
- Google OAuth 2: response_type error on token reque
I had the same problem in my local machine and the problem turned out to be that my hosts file was blocking communication with Verisign, so the URL Facebook tries to communicate with (http://crl.verisign.com/pca3.crl) never worked (state: 404).
Commenting out the various Verisign IP addresses from my hosts file did the trick!
CSRF state and code are checked using local sessions, I bet you need to check your session.save_handler in your php.ini, and if it was working properly.
if you use .htaccess mod rewrite redirects on your page, use the [QSA] (Query String Append) at the end of the lines to preserve the GET variables, or else you lost the $code variable, which is required to the facebook login
I had a similar issue last week, and tracked it down to the
state
field being overwritten by multiple calls togetLoginUrl()
. Each time you callgetLoginUrl()
, a newstate
token is generated in the SDK and stored in the$_SESSION
(it's just a random value), so if you call it twice and the user uses the first link to log in, the second call will have reset the SDK's internalstate
token, and you will get this error in your logs.The SDK looks for the same
state
token in the URL coming back after Facebook authorizes the user and redirects them back to your site, and if it doesn't match it will log this error (here's a link to the source).Facebook SDK code has a bug when checking against tokens twice in the same handler.
I edited the getCode function of
facebook.php
like this:to be more clear and does not state invalid token if called twice.
To be clear the function can be called twice on the same url handler if eg:
$facebook->getUser();
and then in the same handler$facebook->getLogoutUrl()
then thegetCode()
is called twice thus resulting into and invalid error messageI had the same issue. It´s easy. Don´t call
before
otherwise you will get "CSRF state token does not match one provided" error.