Facebook auth dialog (JS SDK) returns blank screen

坚强是说给别人听的谎言 提交于 2019-12-12 15:04:42

问题


I'm setting up a rails app and trying to implement login via Facebook JS SDK. Missing Omniauth already... :(

Anyway, what happens is that the dialog pops up, the user provides the login info, but then it redirects to https://www.facebook.com/connect/window_comm.php?_id=some-string&_relation=opener&auth_token=some-big-string, a blank screen. The pop-up doesn't close.

If I close it manually, though, and then refresh my page, I can see the login happened.

A curious thing is that on the first login, when permissions are asked for, everything works as expected, with the pop-up closing after permissions are granted or denied.

Tested on Chrome, FF, Safari and Opera. Consistent behaviour.

If I debug the blank redirect page on Chrome, there are two errors:

1) Unsafe JavaScript attempt to access frame with URL http://something from frame with URL https://something. Domains, protocols and ports must match. (note http x https...)

2) window_comm.php:7Uncaught TypeError: Cannot call method '_recv' of undefined

Here's the relevant code:

<script>
  window.fbAsyncInit = function() {
    FB.init({
      appId      : 'my-app-id',
      status     : true,
      channelURL : 'http://localhost:3000/channel.html',
      cookie     : true,
      oauth      : true,
      xfbml      : true
    });

    FB.Event.subscribe('auth.login', function(response) {
      window.location.reload();
    });
  };
  (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/pt_BR/all.js"
    fjs.parentNode.insertBefore(js, fjs); 
    } 
    (document, 'script', 'facebook-jssdk'));
</script>
<div class="fb-login-button" data-show-faces="true" data-width="400" data-max-rows="1" perms="offline_access"></div>

Thanks a lot for any light on this... Driving me nuts! =(

Edit: Can it be a bug on Facebook, since it is redirecting from http to https?


回答1:


This answers Q.1) only. Facebook new requirements:-

  • switching to Oauth2.0 to fetch token_access
  • using SSL (ie: https://) to authenticate (hence the cross domain issues)

Also, I'd generally start with the code below to figure out the possible user state during the login process. That means clicking on anything and everything during testing phase.

FB.Event.subscribe('auth.authResponseChange', function(response) {
    alert('The status of the session is: ' + response.status);
});


来源:https://stackoverflow.com/questions/8103359/facebook-auth-dialog-js-sdk-returns-blank-screen

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!