MiniFB.parse_cookie_information returns nil

13 views
Skip to first unread message

George Faraj

unread,
Jan 29, 2011, 11:35:31 AM1/29/11
to min...@googlegroups.com
Hello,

I'm having a problem with the facebook cookies right now. I didn't use to have this problem before yesterday, and I haven't been able to get it to work since. 

Here's the situation:

I have a <fb:login_button> in my pages. I'm subscribing to the auth.login facebook API event, that refreshes the page when the user logs in. Currently, if the user logs in using this button, the page is refreshed correctly. My app calls check_facebook_login (below) and cannot parse the cookie correctly. The parse_cookie_information method returns nil. As I said, this worked perfectly before yesterday, so I'm not sure what is going on.

Here's my code:

  def check_facebook_login
    begin
      fb_cookie = MiniFB.parse_cookie_information(Settings.facebook.app_id, cookies)
      Rails.logger.info 'verifying cookie: ' + cookies.inspect + ' fb_cookie: ' + fb_cookie.inspect

      if MiniFB.verify_cookie_signature(Settings.facebook.app_id, Settings.facebook.app_secret, cookies)
        Rails.logger.info 'cookie verified, creating session'
        @_fb_session = MiniFB::Session.new(Settings.facebook.api_key, Settings.facebook.app_secret, fb_cookie['session_key'], fb_cookie['uid'])

        Rails.logger.info 'looking for existing user'
        user = User.find_by_facebook_id(@_fb_session.uid)
        if user.nil?
          Rails.logger.info 'registering new user'
          user = User.new
          user.name = @_fb_session.user['name']
          user.facebook_id = @_fb_session.user['uid']
          user.save
        end

        set_current_user(user)
      elsif is_logged_in?
        Rails.logger.info 'could not verify cookie, logged out'
        set_current_user(nil)
      end
    rescue MiniFB::FaceBookError => error
      Rails.logger.info error.message
      Rails.logger.info error.backtrace.inspect
      set_current_user(nil)
    end
  end

Logger output:

Started GET "/posts" for 127.0.0.1 at 2011-01-29 10:28:22 -0800
  Processing by PostsController#index as HTML
verifying cookie: {"_Foo_session"=>"BAh7B0kiD3Nlc3Npb25faWQGOgZFRiIlMmQ4YTcyZjcxYmM0Y2JhM2FiMjhiMzdhNzRjZjY4NTVJIhBfY3NyZl90b2tlbgY7AEZJIjFDU09hZzlNT3A4emRGQldSUjNLRUNkbzE1VGtGc002dFBKT1BmTUVVTVY0PQY7AEY=--35f4354a204816c44ea9db8f03c399a931e39ec5"} fb_cookie: nil

Any ideas why the cookies dont include the facebook ones? What can I do to fix this?

Thanks!
George Faraj


Travis Reeder

unread,
Feb 7, 2011, 11:55:49 PM2/7/11
to min...@googlegroups.com
U figure this out?

George Faraj

unread,
Feb 11, 2011, 9:10:38 PM2/11/11
to min...@googlegroups.com
Yes, thanks for checking in. Stupid system time had automatically changed to a time in the future, so the cookies were expiring immediately. Thanks!
Reply all
Reply to author
Forward
0 new messages