I’m trying to create the most simple Rails wrapper for Warden I can for
my own learning experience. Warden’s maintainer also has rails_warden,
but I’d like to simplify that even further.
(http://github.com/hassox/rails_warden)
I currently have a warden.rb initializer with the following:
Rails.configuration.middleware.use Warden::Manager do |manager|
manager.default_strategies :password
manager.failure_app = UserSessionsController
end
Warden::Manager.before_failure do |env, opts|
env['action_dispatch.request.path_parameters'][:action] = "new"
end
Warden::Manager.serialize_into_session do |user|
user.id
end
Warden::Manager.serialize_from_session do |id|
User.find(id)
end
Warden::Strategies.add(:password) do
def valid?
params[:email] || params[:password]
end
def authenticate!
u = User.authenticate(params[:email], params[:password])
u.nil? ? fail!("authentication error from warden") : success!(u)
end
end
This code only works fine if I include the rails_warden gem. If I don’t,
every Rails’ request will fail with an:
“Internal Server Error: uninitialized constant ActionMailer::Base”
Even if I include all of the rails_warden code as a library locally
before the initializer it will fail. I can only get it to work with the
gem included, but I’m failing to see what the gem is doing to Warden or
Rails that the above code is not.
Also, if I choose to use my own Rails Metal application as the Warden
failure app, all is well, even without the gem. The error only arrise
when I choose a Rails controller as the failure app.
Again, I’m just trying to find the simplest possible Warden
implementation. My searches have given me nothing, and I’m not
interested in Devise, or any other authentication engine, this is only
for my own learning experience.
Best,
Ted