Search code examples
ruby-on-railsfacebookcookiesoauthkoala

Can't get Oauth facebook cookies using Koala for connecting to Facebook (with Rails)


I'm using Rails 3.0.9. Trying to login to my (localhost) site through Facebook.

My init params on the login page:

FB.init({
      appId : '<%= FB_APP_ID %>',
      status : true,
      cookie : true,
      xfbml : true
});

The login button works, I get the Facebook login popup and I can successfully log in to Facebook. Then the following event is reached:

FB.Event.subscribe('auth.sessionChange', function(response) {
    if (response.session) {location.href= ...}

And I'm being redirected to the wanted location. But - can't get any cookies of "fbs_" or "fbsr_" like the Oauth is looking for at: get_user_info_from_cookie(cookies)

My cookies = {}, nothing there. In a few occasions, I recall I did have some facebook cookies there, I can't reconstruct such case, but anyway, it didn't include the "fbs_" ones, only others.

Also, after logging in, when I go back to Facebook tab on the browser and refresh, it does show me my Facebook page, but after a second, it shows a popup says "you need to log in". In my app though, it still knows to keep directing me to the wanted href, like needed when a user is logged in.

I would really love to hear if you have anything that can help me... :-)

Thanks, Moozly.

  • Just got the scenario with some Facebook cookies again (still not by the wanted names). Got the following names: "datr", "locale", "locale", "reg_fb_gate", "lu". But even to these I can't get to with the Rails cookies param - cookies["dart"] returns null. cookies param only shows the cookies with the host of localhost (which contains data when I'm logging in (with Clearance) - the regular login procedure to site.

Solution

  • Just wanted to update to say that I had solved my problem:

    1. I had added to the init the param: oauth : true:

      FB.init({
          appId : '<%= FB_APP_ID %>',
          status : true,
          cookie : true,
          xfbml : true,
          oauth : true
      });
      
    2. Apparently, there is a bug with adding the parameters added in js.src, so I removed them(!) and problem was solved:

      (function(d, s, id) {
          var js, fjs = d.getElementsByTagName(s)[0];
          if (d.getElementById(id)) {return;}
          js = d.createElement(s); js.id = id;
          js.src = "//connect.facebook.net/en_US/all.js" //removed: #xfbml=1&appId=<%= FB_APP_ID %>";
          fjs.parentNode.insertBefore(js, fjs);
      }
      (document, 'script', 'facebook-jssdk')); 
      

    That solved the cookies problem for me!