FB.login Javascript需要在十月份做出更改?

3
所以,我们在新版Javascript SDK和OpenGraph推出时从Facebook Connect切换过来了。
五月份,我们的一些客户收到了一封电子邮件,告诉他们可能存在安全漏洞,需要升级到Oauth 2.0。我查看了我们的新代码和当时的FB.login文档后得出结论,使用我们新产品的客户将没有问题,因此那些使用旧版Facebook Connect的客户需要升级到最新版本。
今天我注意到Javascript SDK已更改,因此为了使用OAuth 2.0,仍需要进行代码更改(例如this blog post,该文章是在上述电子邮件发布一个月后发布的),并且我需要在10月1日之前升级。
今天我尝试将我的应用程序的“Oauth 2.0迁移”标志设置为true,并使用相同的代码运行它。出乎意料地,它成功了。所以我的问题是,我是否需要按照链接博客文章中概述的进行代码更改?如果应用程序在“Oauth 2.0迁移”复选框被选中的情况下今天可以正常工作,那么这是一个有效的前提假设,认为它在10月1日后仍将继续工作吗?
以下是我的代码:
// call to FBinit does not include oauth: true
FB.init({appId: opts.ApiKey, status: true, cookie: true, xfbml: true});

// call to login expects response.session on response. not response.authResponse. 
// Shame on Facebook for arbitrarily renaming that so I can't do a clean swap.
FB.login(function(response){
    if(response.session){
        var access_token = response.session.access_token;
        // blah blah blah
    }
});
3个回答

1

是的,您需要对JS SDK(http://developers.facebook.com/docs/oauth2-https-migration/)进行代码更改,以在FB.init函数中包含oauth:true和博客文章中提到的其他更改。

Dev App中的迁移设置仅表示您将收到加密的访问令牌(请参见工具提示)。


0

我会将所有代码进行更改,同时启用O-2.0并使用旧的认证方法可能会破坏会话,导致用户无法通过应用程序退出登录,或在用户从Facebook注销时保留应用程序中的会话。


启用新的O-2.0并禁用旧的身份验证,我使用下面的示例,与php-sdk 3.1.1集成,没有任何错误或问题。

      <div id="FBauth"></div>
      <div id="fb-root"></div>
<script>
      window.fbAsyncInit = function() {
        FB.init({
    appId  : '112104298812138',
    status : true, // check login status
    cookie : true, // enable cookies to allow the server to access the session
    xfbml  : true, // parse XFBML
    //channelUrl : 'http://WWW.MYDOMAIN.COM/channel.html', // channel.html file
    oauth  : true // enable OAuth 2.0
        });
FB.Canvas.EarlyFlush.addResource("http://shawnsspace.com/index.php");
FB.Canvas.setAutoResize();
            FB.getLoginStatus(function(response) {
              if (response.authResponse) {
                // logged in and connected user, someone you know
                var authbox = document.getElementById('FBauth');
                //authbox.innerHTML="Hey" +authResponse.name+ "";
                authbox.innerHTML="<fb:login-button autologoutlink='true'></fb:login-button><fb:login-button show-faces='true' width='250' max-rows='1'></fb:login-button>";
                FB.XFBML.parse(authbox);
                //var a = document.createElement('a');
                //alert();
              } else {
                // no user session available, someone you dont know
                var authbox = document.getElementById('FBauth');
                authbox.innerHTML="";
                var a = document.createElement('a');
                a.setAttribute("href","javascript:void();");
                a.setAttribute("onclick","FBlogin();");
                a.innerHTML="Please Login";
                authbox.appendChild(a);
                //alert('not logged in'+response+'');
//
        window.FBlogin = function(){
                FB.login(function(response) {
               if (response.authResponse) {
                 FB.api('/me', function(response) {
                 });

               } else {
               top.location.href = "http://apps.facebook.com/shawnsspace/";
                 // user cancealed login.
               }
             }, {scope: 'manage_pages'});
        };
//          
              }
            }); 

        FB.Event.subscribe('auth.login', function(response) {
        top.location.href = 'http://apps.facebook.com/shawnsspace/';
        });
        FB.Event.subscribe('auth.logout', function(response) {
        //top.location.href = "http://facebook.com/designbyshawn";
        });
      };
      (function() {
        var e = document.createElement('script'); e.async = true;
        e.src = document.location.protocol +
          '//connect.facebook.net/en_US/all.js';
        document.getElementById('fb-root').appendChild(e);
      }());
</script>

这是一个很好的建议,Mike。我会研究一下我们是否可以启用它。 - Cat Lee

0

上面的代码没有使用Oauth2。在他们决定强制使用Oauth2之前,它仍然可以正常工作。

要切换到Oauth2,您需要在FB.init调用中添加oauth:true,如您所引用的博客文章中所述。主要变化是response.session变为response.authResponse

还有很多其他变化,因此我建议现在进行测试。我们花了几个小时来过渡我们的网站,但其中大部分是让cookie工作,因为使用Oauth2时它们完全不同,我们想从cookie生成access_token。

您可以查看我更新的Oauth2 Rails插件-https://github.com/imme5150/fgraph 这里是cookie代码:https://github.com/imme5150/fgraph/blob/master/lib/fgraph/rails/fgraph_helper.rb 在底部。另一个技巧是从存储在cookie中的“code”参数获取访问令牌,您需要调用FB图形,但必须包括“redirect_uri”参数,但您希望它为空。

祝你好运!


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接