FriendsOfSymfony / FOSFacebookBundle

NOT MAINTAINED - see https://github.com/hwi/HWIOAuthBundle
322 stars 140 forks source link

Facebook Logout not working properly #292

Closed ajeetvarma closed 10 years ago

ajeetvarma commented 10 years ago

I have implemented the FOSFacebookBundle in SonataUserBundle with FOSUserBundle according to its documentation .

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: {{ 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 .It was working very fine but now after update with the new version , It is login succesfully 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 i.e. it is not destroying my site authentication session . Candulive I do't know what i m doing wrong . If any have idea please help me .

Thanks in advanced !

ajeetvarma commented 10 years ago

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

private function onFailure(GetResponseEvent $event, Request $request, AuthenticationException $failed)

  "$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 .

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 .