【问题标题】:Oauth2 - Unsafe JavaScript attempt to access frame with URLOauth2 - 不安全的 JavaScript 尝试使用 URL 访问框架
【发布时间】:2012-01-17 16:25:56
【问题描述】:

我正在使用以下代码来呈现 facebook 登录按钮

<div id="facebook-login">
  <script>
    FB.init({ 
      appId:"appid", cookie:true, 
      status:true, xfbml:true
    });
    FB.Event.subscribe("auth.login", function(response) {
      window.location = "http://xxx"; // redirect if user has logged in
    });
  </script>
  <fb:login-button perms="publish_stream"><?php print 'Login with Facebook'; ?></fb:login-button>
</div>

但它今天不再起作用,我认为它与oauth2有关。

所以我尝试按照Facebook's developer docs 中的建议更新代码。

新代码:

<div id="facebook-login">
  <script>
    window.fbAsyncInit = function() {
      FB.init({ 
        appId:"appid", cookie:true, 
        status:true, xfbml:true, oauth:true, xfbml: true, channelUrl: '//mydomain/channel.php'
      });
      FB.Event.subscribe("auth.login", function(response) {
        window.location = "http://xxx"; // redirect if user has logged in
      });
    };
    // Load the SDK Asynchronously
    (function(d){
       var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
       js = d.createElement('script'); js.id = id; js.async = true;
       js.src = "//connect.facebook.net/en_US/all.js";
       d.getElementsByTagName('head')[0].appendChild(js);
     }(document));
  </script>
  <fb:login-button scope="publish_stream"><?php print 'Login with Facebook'; ?></fb:login-button>
</div>

现在,每当我单击 facebook 登录按钮时,chrome 控制台都会不断抛出以下错误 不安全的 JavaScript 尝试使用 URL https://www.facebook.com/login.php?...访问框架。

我认为这是一个 js 跨域问题,但我已经设置了频道 url。关于如何解决这个问题的任何想法?

谢谢。

问候, 套件

【问题讨论】:

    标签: facebook-javascript-sdk oauth-2.0


    【解决方案1】:

    请务必将代码替换为新的 oAuth 2.0

    param => scope
    response.session => response.authResponse
    response.session.access_token => response.authResponse.accessToken
    FB.getSession().uid => FB.getAuthResponse().userID
    

    链接: https://developers.facebook.com/blog/post/525/

    【讨论】:

      【解决方案2】:

      我终于找到了答案。 get_facebook_cookie() 不再适用于 OAuth 2.0。我们需要facebook php-sdk 中提到的Facebook Developers – Facebook for Websites

      你也可以试试Facebook Javascript SDK – A Simple Login Page with OAuth 2.0中的例子

      【讨论】:

        猜你喜欢
        • 2011-11-18
        • 1970-01-01
        • 1970-01-01
        • 2013-02-02
        • 2011-05-18
        • 1970-01-01
        • 2014-12-27
        相关资源
        最近更新 更多