-
-
Save hassox/659298 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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