I'm currently building a web application in Rails. I'm using Authlogic
to handle normal authentication. I'm using facebooker to handle
facebook connect on the external site and to authenticate users within
the facebook canvas application.
I'm having trouble building simple, coherent current_user
functionality. Currently I have a whole mess of different methods
getting/setting the current user, and I'd like to simplify this as
much as possible.
I'm using active_record_store for my sessions (defined in
environment.rb)
Here is my application Controller:
class ApplicationController < ActionController::Base
helper :all # include all helpers, all the time
protect_from_forgery # See
ActionController::RequestForgeryProtection for details
filter_parameter_logging :fb_sig_friends, :password, :password_confirmation
helper_method :facebook_session, :current_user_session, :current_user
before_filter :fb_setup
attr_accessor :current_user
helper_attr :current_user
#Before filter to decide if we should use facebook sessions to
set current user
def fb_setup
if request_comes_from_facebook?
ensure_authenticated_to_facebook
set_current_fb_user
end
end
############
# AuthLogic
############
def current_user_session
return @current_user_session if defined?
(@current_user_session)
@current_user_session = UserSession.find
end
def current_user
return @current_user if defined?(@current_user)
@current_user = current_user_session &&
current_user_session.user
end
##########
# Facebook
##########
def create_user
self.current_user = User.for(facebook_session.user.to_i,
facebook_session)
end
def set_current_fb_user
self.current_user = User.for(facebook_session.user.to_i,
facebook_session)
end
end
And in my User model, I have these methods to help finding/creating a
user from a facebook id:
def self.for(facebook_id,facebook_session=nil)
returning find_or_create_by_facebook_id(facebook_id) do |user|
unless facebook_session.nil?
user.store_session(facebook_session.session_key)
end
end
end
def store_session(session_key)
if self.session_key != session_key
update_attribute(:session_key,session_key)
end
end
def facebook_session
@facebook_session ||=
returning Facebooker::Session.create do |session|
session.secure_with!(session_key,facebook_id,1.day.from_now)
end
end
I need either self.current_user or @current_user set in
application_controller in a coherent way regardless of which session
is responsible for setting the current_user. I'm having trouble doing
this and the rest of my code base is suffering because of this. If
anyone has any advice, it would be much appreciated.
If you need any additional info, I'll be happy to provide it.
Thanks
Dave
> --
> You received this message because you are subscribed to the Google Groups "facebooker" group.
> To post to this group, send email to faceb...@googlegroups.com.
> To unsubscribe from this group, send email to facebooker+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/facebooker?hl=en.
>
--
David L. Sifry
415 846-0232 (Mobile)
Blog: http://www.sifry.com/alerts
Photos: http://flickr.com/photos/dsifry
Charlie
> > For more options, visit this group athttp://groups.google.com/group/facebooker?hl=en.
I got a skeleton application up and running.
The web application is hosted free at http://facebooker-authlogic-bridge.heroku.com/
The Facebook application is located at http://apps.facebook.com/fb-authlogic-bridge/
The code is hosted at Github here, http://github.com/fluidtickets/facebooker-authlogic-bridge
The app handles authentication from 3 sources: authlogic, facebook
connect, and facebook canvas apps.
you can use the current_user method (like normally used in Authlogic)
to get the current_user, no matter how they authenticated.
Let me know if there are any bugs, and hopefully this helps someone.
Dave
> For more options, visit this group at http://groups.google.com/group/facebooker?hl=en.
I was wondering if you could tell me what you're using as application
settings in Facebook - e.g. the callbacks.
For example, what do you have in your Post-Authorize Callback URL and
Post-Remove Callback URL? Canvas Callback URL, Post-Authorize Redirect
URL, and Connect URL?
Many thanks, I'm sure it will help me get things debugged and working
on my site...
Dave
My Post-Authorize Callback URL and Post-Remove Callback URL are
blank.
My canvas callback url is http://facebooker-authlogic-bridge.heroku.com/,
which is the root of my web application.
Post-Authorize Redirect is blank.
Connect URL is also http://facebooker-authlogic-bridge.heroku.com/
Note that in Facebooker.yml neither the canvas page or the
callback_url have trailing slashes.
What errors are you seeing?
To be honest, I haven't tried this over a tunneled connection. If
you have more trouble, maybe try creating a free Heroku account, and
try to get that working first.
On Mar 9, 8:36 pm, David Sifry <dsi...@gmail.com> wrote:
> Hi! Thanks a lot for posting your skeleton app. I've been attempting
> to get it running flawlessly over my tunneled connection.
>
> I was wondering if you could tell me what you're using as application
> settings in Facebook - e.g. the callbacks.
>
> For example, what do you have in your Post-Authorize Callback URL and
> Post-Remove Callback URL? Canvas Callback URL, Post-Authorize Redirect
> URL, and Connect URL?
>
> Many thanks, I'm sure it will help me get things debugged and working
> on my site...
>
> Dave
>
> On Mar 5, 2010, at 12:40 PM, rcwhite wrote:
>
>
>
>
>
> > Hi Everyone,
>
> > I got a skeleton application up and running.
>
> > The web application is hosted free athttp://facebooker-authlogic-bridge.heroku.com/
>
> > The Facebook application is located athttp://apps.facebook.com/fb-authlogic-bridge/
>
> > The code is hosted at Github here,http://github.com/fluidtickets/facebooker-authlogic-bridge
On Mar 9, 8:36 pm, David Sifry <dsi...@gmail.com> wrote:
> Hi! Thanks a lot for posting your skeleton app. I've been attempting
> to get it running flawlessly over my tunneled connection.
>
> I was wondering if you could tell me what you're using as application
> settings in Facebook - e.g. the callbacks.
>
> For example, what do you have in your Post-Authorize Callback URL and
> Post-Remove Callback URL? Canvas Callback URL, Post-Authorize Redirect
> URL, and Connect URL?
>
> Many thanks, I'm sure it will help me get things debugged and working
> on my site...
>
> Dave
>
> On Mar 5, 2010, at 12:40 PM, rcwhite wrote:
>
>
>
>
>
> > Hi Everyone,
>
> > I got a skeleton application up and running.
>
> > The web application is hosted free athttp://facebooker-authlogic-bridge.heroku.com/
>
> > The Facebook application is located athttp://apps.facebook.com/fb-authlogic-bridge/
>
> > The code is hosted at Github here,http://github.com/fluidtickets/facebooker-authlogic-bridge
development:
api_key: XXXXX
secret_key: YYYYYYY
canvas_page_name: your_canvas_page_name
callback_url: http://www.yourdomain.com:3000
pretty_errors: true
set_asset_host_to_callback_url: true
tunnel:
public_host_username: your_username
public_host: the_tunnel_host
public_port: 3000
local_port: 3000
server_alive_interval: 0
Changing the callback_url from:
http://www.yourdomain.com:3000/
to
http://www.yourdomain.com:3000
made all the difference. Thanks!
Dave
> For more options, visit this group at http://groups.google.com/group/facebooker?hl=en
undefined method `find_or_create_by_facebook_id' for #<Class:
0xbf75f58>
Obviously the github version doesn't have that, so any thoughts into
why I'm going about this wrong?
Justin
On Mar 10, 12:59 pm, David Sifry <dsi...@gmail.com> wrote:
> Ah, making sure that there was no final slash in the callback_url in
> the facebooker.yml was the key. If you're going to use a tunnel, this
> is the way to specify it:
>
> development:
> api_key: XXXXX
> secret_key: YYYYYYY
> canvas_page_name: your_canvas_page_name
> callback_url:http://www.yourdomain.com:3000
> pretty_errors: true
> set_asset_host_to_callback_url: true
> tunnel:
> public_host_username: your_username
> public_host: the_tunnel_host
> public_port: 3000
> local_port: 3000
> server_alive_interval: 0
>
> Changing the callback_url from:http://www.yourdomain.com:3000/
> tohttp://www.yourdomain.com:3000
>
> made all the difference. Thanks!
>
> Dave
>
> On Mar 10, 2010, at 5:54 AM, rcwhite wrote:
>
>
>
> > David,
>
> > My Post-Authorize Callback URL and Post-Remove Callback URL are
> > blank.
>
> > My canvas callback url ishttp://facebooker-authlogic-bridge.heroku.com/
> > ,
> > which is the root of my web application.
>
> > Post-Authorize Redirect is blank.
>
> > Connect URL is alsohttp://facebooker-authlogic-bridge.heroku.com/
Mike
--
Mike Mangino
http://www.elevatedrails.com
> ...
>
> read more »
Justin
> ...
>
> read more »
I know there's one inserted by Facebook in the lower-right corner of my page (FBML), but I want it to be more prominent. I wouldn't mind using a link that worked just like that link -- I just want to embed it at the very top of my page.
Anyone know how to do this?
-Jason