Skip to content

Instantly share code, notes, and snippets.

@ngw
Created November 5, 2010 07:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ngw/663795 to your computer and use it in GitHub Desktop.
Save ngw/663795 to your computer and use it in GitHub Desktop.
Rails.configuration.middleware.use RailsWarden::Manager do |config|
config.failure_app = SessionsController
config.default_strategies :facebook
end
Warden::Manager.serialize_into_session do |user|
user.id.to_s
end
Warden::Manager.serialize_from_session do |id|
User.first( :conditions => { :id => id } )
end
Warden::Manager.before_failure do |env, opts|
request = env[ "action_controller.rescue.request" ] ||= ActionController::Request.new( env )
env[ 'action_dispatch.request.path_parameters' ][ :action ] = "unauthenticated"
end
Warden::Strategies.add :facebook do
def valid?
request.cookies && request.cookies[ "fb_access_token" ]
end
def authenticate!
u = User.first :conditions => { :fb_access_token => request.cookies[ "fb_access_token" ] }
u.nil? ? fail! : success!( u )
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment