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