Skip to content

Instantly share code, notes, and snippets.

@madtrick
Created October 19, 2012 09:06
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save madtrick/3917079 to your computer and use it in GitHub Desktop.
Save madtrick/3917079 to your computer and use it in GitHub Desktop.
Warden strategy for Devise
module Devise
module Strategies
class RemoteAuthenticatable < Authenticatable
#
# For an example check : https://github.com/plataformatec/devise/blob/master/lib/devise/strategies/database_authenticatable.rb
#
# Method called by warden to authenticate a resource.
#
def authenticate!
#
# authentication_hash doesn't include the password
#
auth_params = authentication_hash
auth_params[:password] = password
#
# mapping.to is a wrapper over the resource model
#
resource = mapping.to.new
return fail! unless resource
# remote_authentication method is defined in Devise::Models::RemoteAuthenticatable
#
# validate is a method defined in Devise::Strategies::Authenticatable. It takes
#a block which must return a boolean value.
#
# If the block returns true the resource will be loged in
# If the block returns false the authentication will fail!
#
if validate(resource){ resource.remote_authentication(auth_params) }
success!(resource)
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment