Why are cookies for the JavaScript JavaScript SDK not set?

I had a problem when the JavaScript SDK on Facebook does not set cookies on some machines, so my backend authentication does not work when I try to verify the cookie using the secret value of my application.

I have a demo application ; important files are:

The client uses the Facebook JavaScript API to log in to the system and retrieve information, and then posts it on my server. The server sends back fbs_APPID , which the client then displays. On some Windows machines (in all browsers), the server does not receive the expected cookie. What makes Facebook set a cookie and how can I fix it?

The demo application is in Sinatra, but our production application, in which we found an error, is Rails, if that matters.

+6
javascript cookies facebook
source share
3 answers

take a look at the initialization code for JS:

 <script> FB.init({ appId : 'YOUR APP ID', status : true, // check login status cookie : true, // enable cookies to allow the server to access the session xfbml : true // parse XFBML }); </script> 

Have you enabled cookies to receive cookie support? Also make sure cookies are disabled in your browser.

+1
source share

The cookie option, unfortunately, is not so reliable ... personally, I prefer to receive a signed javascript sdk request, send it to the backend as a var message, and then decode this signed request there to verify the call ..

This way it will also work in safari :)

Hooray!

+1
source share

I don’t know exactly what is going on, but I think this is a Facebook problem, not a problem with your application. The same thing happened to me, and then it "magically" began to work.

See Why Facebook JavaScript authentication doesn’t work on a specific computer?

I guess this has something to do with Facebook caching on CDN.

0
source share

All Articles