开发者

Why wouldn't the Facebook JavaScript authentication work on a specific computer?

开发者 https://www.devze.com 2023-02-13 21:33 出处:网络
I have a site that uses the Facebook JavaScript API to allow users to log in to a Ruby on Rails application through Facebook. When a user clicks to log in or log out, Facebook code does the authentica

I have a site that uses the Facebook JavaScript API to allow users to log in to a Ruby on Rails application through Facebook. When a user clicks to log in or log out, Facebook code does the authentication and then raises an event and supplies a cookie with authentication parameters. The cookie is sent to my server, and I use it to authenticate. This has been working for some time.

  // Connnect with Facebook.
  $('.fbLogout').click(function() {
      FB.logout();
  });
  $('.fbLogin').click(function () {
      FB.login();
  });
  FB.init({appId: '163691796982300', status: true, cookie: true, xfbml: true});
  FB.Event.subscribe('auth.sessionChange', function() {
      location.reload();
  });

I recently got a new computer, and my site doesn't work from this computer. The Facebook login UI seems to work, the auth.sessionChange event is raised, but it looks like the cookie is never supplied and so the page goes into an endless loop of receiving an authentication event, refreshing the page with no cookie and repeating. The problem seems be on this single computer and happens regardless of which browser I use, and which OS I use.

It works on:

  • Friend's PC using Internet Explorer
  • Friend's PC using Firefox Friend's PC
  • Friends PC using Firefox in Ubuntu 10.10 in VirtualBox
  • Another PC in the same subnet as new computer
  • New computer booting from Ubuntu 10.10 live CD 64-bit

Doesn't work on:

  • New computer using Internet Explorer
  • New computer using Chrome
  • New computer using Firefox
  • New computer using Firefox in Ubuntu 10.10 in VirtualBox

Could this somehow be caused by my network card or network configuration?

Update: It started working just as mysterio开发者_高级运维usly as it was failing.


This could be the same thing I had to deal with. In your code I can't see the asynchronous initialization:

window.fbAsyncInit = function() {
    FB.init({
          appId  : fb_appId,
          status : true, // check login status
          cookie : true, // enable cookies to allow the server to access the session
          xfbml  : true,  // parse XFBML
          oauth : true //enables OAuth 2.0
    });
};

This is very important to guarantee that the Facebook JavaScript SDK is fully loaded before you call the init method. Therefore it may suddenly have started working, because the browser already cached the JavaScript file.


Try top.location.reload();

It looks like you might be using some sort of jQuery. If so, what version are you using?

Also it might be worth migrating to the new JavaScript SDK with OAuth 2.0. The migration has put a lot of my applications' bugs to rest.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号