agorapulse / grails-facebook-sdk

Facebook SDK Grails Plugin
http://agorapulse.github.com/grails-facebook-sdk/guide
30 stars 13 forks source link

How to manage auto login with client side authentication? #57

Closed confile closed 11 years ago

confile commented 11 years ago

When I use your plugin login button

                <script>
                    function facebookCallback(response) {
                        window.location.href = "${createLink(controller:'facebookAuth', action:'success')}";
                    }
                </script>
                <facebook:loginLink
                    appPermissions="${grailsApplication.config.grails.plugin.facebooksdk.appPermissions}"
                    callback="facebookCallback">
                    Signup with Facebook
                </facebook:loginLink>

it works perfect for login. But what if the user has closed the browser after login (without logout), how can I loggin him based on the facebook cookies with your plugin?

How do you do that?

benorama commented 11 years ago

You could use FB.getLoginStatus() from Facebook Javascript SDK during the initialization.

<facebook:initJS appId="${facebookContext.app.id}">
  // Put here any JS code to be executed after Facebook JS initialization
  <g:if test="${!facebookContext.authenticated}">
    FB.getLoginStatus(function(response) {
      if (response.authResponse) {
        window.location.reload();
      }
    });
  </g:if>
</facebook:initJS>

This will automatically reload the page after autologin if the user is already connected on Facebook.