Skip to content

Instantly share code, notes, and snippets.

@ngw
Created November 2, 2010 06:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ngw/659296 to your computer and use it in GitHub Desktop.
Save ngw/659296 to your computer and use it in GitHub Desktop.
Rails.configuration.middleware.use Warden::Manager do |manager|
manager.failure_app = SessionsController
manager.serialize_into_session do |user|
user.id.to_s
end
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? ? throw( :warden ) : success!( u )
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment