Skip to content

Instantly share code, notes, and snippets.

@hassox
Forked from ngw/gist:659296
Created November 2, 2010 06:08
Show Gist options
  • Save hassox/659298 to your computer and use it in GitHub Desktop.
Save hassox/659298 to your computer and use it in GitHub Desktop.
Rails.configuration.middleware.use Warden::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