small medium large xlarge

Generic-user-small
11 Apr 2009, 18:23
Theodore Kimble (6 posts)

Hello all, for the most part I’ve successfully implemented Facebook Connect into my restful_authentication setup using Facebooker and madebymany’s tutorial. The only problem I have is when I manually log out of Facebook through facebook.com.

To log out of my site I am using a conditional statement to check whether a user is using Connect or not( facebook_session ). If not, the logout link simply destroys the restful_authentication session. If they are, the logout link is:

<a href="#" onclick='FB.Connect.logoutAndRedirect("/logout")>Logout</a>

</code>

This works fine unless I manually log out of facebook. Now, facebook_session still registers as true and the logoutAndRedirect link never redirects to “/logout” and the user remains logged in.

Is there a better way to check if a user is logged in to Facebook? facebook_session appears to only be destroyed when called from within the application. Or am I missing something here?

Thanks a Bunch!

Ted

Head_pragsmall
13 Apr 2009, 13:03
Mike Mangino (543 posts)

I don’t store login information in the rails session when logging a user in via facebook connect. Instead, I modify the @current_user@ method to add a login_from_facebook

`

    def current_user
      @current_user ||= (login_from_session || 
                                   login_from_basic_auth || 
                                   login_from_cookie || 
                                   login_from_facebook) unless @current_user == false
    end

`

where the login_from_facebook looks like:

`

    def login_from_facebook
      if facebook_session
        # dont set current_user since we don't want to store the user in a cookie
        User.find_by_facebook_id(facebook_session.user.id)
      end
    end

`

That way, the when the facebook session cookie is destroyed, the user is logged out.

Generic-user-small
13 Apr 2009, 15:15
Theodore Kimble (6 posts)

Hmmmm… Even with those changes to my login_from_facebook method (I was indeed setting current_user), I’m still having problems:

I did change my logout method to:

<a href="/logout" onclick='FB.Connect.logoutAndRedirect("/logout")>Logout</a>

</code>

So I always have a way to log out, but still no way to detect when someone logs out from facebook in another window. I guess this isn’t a big deal, but it would be nice to be able to log out from facebook and not worry about the other 10 facebook connect sites I’m also logged in to.

Generic-user-small
13 Apr 2009, 17:39
Theodore Kimble (6 posts)

Well I changed a before_filter in my application controller from:

before_filter :set_facebook_session

</code>

as I’ve seen in other tutorials, to

before_filter :create_facebook_session

</code>

as in your fb_connect example. I didn’t think it was working, but it actually is, there just seems to be about a 30 second delay. Looking through the facebooker code I see this line:

Line 196 in facebooker/lib/facebooker/rails/controller.rb

          'expires' => lambda{|value| blank?(value) ? nil : Time.at(value.to_f)},

</code>

I’m not quite sure I follow exactly, but it seems like it’s responsible for setting the time when facebook’s session will expire. Is this delay that I’m experiencing typical? Thanks,

Ted

Generic-user-small
13 Apr 2009, 20:50
Theodore Kimble (6 posts)

OK Nevermind, it seems like my server was just being slow, it only takes about two or three refreshes for the changes to update. Thanks for all of your help.

You must be logged in to comment