2012-11-12 22 views
0

我在我的Symfony2.1公司网站上使用javascript sdk实现Facebook连接。Symfony2 Facebook连接 - 使用js sdk登录后重定向

下面的代码,我使用,做工精细:

<script> 
    window.fbAsyncInit = function() { 
     FB.init({ 
      appId : 'my-app-id', // App ID 
      cookie : true, 
      xfbml : true, 
      oauth : true 
     }); 
    }; 

    function after_click() { 
     FB.getLoginStatus(function(response) { 
      if (response.status === 'connected') { 
       window.location = "{{ hwi_oauth_login_url('facebook') }}"; 
      } 
     }); 
    } 

    // Load the SDK Asynchronously 
    (function(d){ 
     var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0]; 
     if (d.getElementById(id)) { window.fbAsyncInit(); return;} 
     js = d.createElement('script'); js.id = id; js.async = true; 
     js.onload = window.fbAsyncInit; 
     js.src = '//connect.facebook.net/fr_FR/all.js'; 
     ref.parentNode.insertBefore(js, ref); 
    }(document)); 
</script> 

<div class="fb-login-button m_y" scope="email,user_birthday" onlogin="after_click()"></div> 

我现在面临的问题是,我desperatly寻找一种方式,他登录后,将用户重定向到当前页面现在。行为是用户总是被重定向到我的网站的主页。

我知道使用php sdk时有一个redirect-uri参数,我正在寻找类似于js sdk的东西,我不得不说我很难找到它。

window.location = "{{ hwi_oauth_login_url('facebook') }}";来自Symfony2 OAuth Bundle,用于管理Facebook连接。也许我需要告诉OAuth Bundle成功登录后重定向到哪里,但是无法真正找到解决方案。

感谢您的任何想法,你可以有。

+0

为什么不使用'location.reload()'? – CBroe

+0

那么我需要使用'window.location =“{{hwi_oauth_login_url('facebook')}}”;'实际验证FB身份验证过程并将用户连接到我的网站 – SebScoFr

+0

您可以将当前网址附加到该地址客户端),然后在处理完登录后从那里重新导向。 – CBroe

回答

0

确定它实际上是相当简单的,只是添加在我security.yml use_referer: true做的工作:

security: 
    ... 
    firewalls: 
     portal_area: 
      ... 
      oauth: 
       resource_owners: 
        facebook:  "/login/check-facebook" 
       login_path:  /connect 
       failure_path:  /connect 
       always_use_default_target_path: false 
       default_target_path:/
       target_path_parameter: _target_path 
       use_referer: true 

解决。