简体   繁体   English

Facebook注销无法正常工作

[英]Facebook Logout not working properly

I have implemented the FOSFacebookBundle in SonataUserBundle with FOSUserBundle according to its documentation . 我已经根据它的文档在SonataUserBundle和FOSUserBundle中实现了FOSFacebookBundle。

config.yml : 
    fos_facebook:
           alias:  facebook
           app_id: xxxxxxxx597242
           secret: xxxxxxxxxxxxxxxxxxxx2a6e7
           cookie: true
           permissions: [email, user_birthday, user_location]
    services:
        fos_facebook.user.login:
            class: Webmuch\UserBundle\Security\User\Provider\FacebookProvider
            arguments:
                facebook: "@fos_facebook.api"
                userManager: "@fos_user.user_manager"
                validator: "@validator"

security.yml:
   providers:
         chain_provider:
            chain:
                providers: [fos_userbundle,fos_facebook_provider]
         fos_userbundle:
            id:  fos_user.user_provider.username_email
         fos_facebook_provider:
            id: fos_facebook.user.login
    firewalls:
         main:
             pattern: ^/
             fos_facebook:
                  app_url: "https://developers.facebook.com/apps/xxxxxxxx597242"
                  server_url: "http://localhost/Mysite/web/app_dev.php/"
                  login_path: /login
                  check_path: /login_check
                  provider: fos_facebook_provider
                  default_target_path: /
             form_login:
                  provider: fos_userbundle
                  login_path:     /login
                  use_forward:    false
                  check_path:     /login_check
                  failure_path:   null 
             logout:
                path:   /logout
                target: /
             anonymous: true

base.html.twig: base.html.twig:

{{ facebook_initialize({'xfbml': true, 'fbAsyncInit': 'onFbInit();'}) }}
  {{ facebook_login_button({'autologoutlink': true}) }}

  {% block javascripts %}
      <script>
             function goLogIn(){
                 window.location.href = "{{ path('fos_facebook_security_check') }}";
             }

             function onFbInit() {
                  if (typeof(FB) != 'undefined' && FB != null ) {              
                  FB.Event.subscribe('auth.statusChange', function(response) {
                     if (response.session || response.authResponse) {
                    setTimeout(goLogIn, 500);
                   } else {
                     window.location.href = "{{ path('fos_user_security_logout') }}";
                         }
                    });
               }
             }
       </script>
  {% endblock %}

My Facebook Provider and User Entity is set as per documentation . 我的Facebook提供者和用户实体是根据文档设置的。

It was working very fine but now after update with the new version , It is login successfully after authentication in my site , but when I click on Facebook logout button it is now only Facebook logout while in my site I'm still in login condition ie it is not destroying my site authentication session . 它运行良好,但是现在更新为新版本后,可以在我的站点中通过身份验证成功登录,但是当我单击Facebook注销按钮时,现在只有Facebook注销,而我仍处于登录状态,即这并没有破坏我的站点身份验证会话。

I do't know what I'm doing wrong. 我不知道我在做什么错。

Finally after a lot of scratching my mind i found the root cause of the error ; 终于,经过我的努力,我发现了错误的根本原因; it is the Security component of Symfony Package in the vendor in which in Firewall folder located in HTTP folder, a file "AbstractAuthenticationListener.php" has problem on line 190 它是供应商中Symfony软件包的安全组件,其中在HTTP文件夹中的“防火墙”文件夹中,文件“ AbstractAuthenticationListener.php”在第190行有问题

$token = $this->securityContext->getToken();
if ($token instanceof UsernamePasswordToken && $this->providerKey === $token->getProviderKey()) {
$this->securityContext->setToken(null);
} 

Since Facebook api uses "FacebookAccessToken" instead of the "UsernamePasswordToken" so facebook logout is simply destroy its own(facebook) session but unable to destroy the site authentication session . 由于Facebook api使用“ FacebookAccessToken”而不是“ UsernamePasswordToken”,因此Facebook注销仅破坏了其自己的(facebook)会话,但无法破坏站点身份验证会话。

So if we just set 所以,如果我们只是设置

$this->securityContext->setToken(null)  

on the place of above four lines , the problem is resolved and everything is working very fine . 在以上四行的地方,问题已解决,并且一切工作正常。 I know it is not a good idea to change in vendor but it is working very fine and i will welcome any more idea please . 我知道更换供应商不是一个好主意,但是工作得很好,我欢迎任何更多的主意。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM