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.
I currently have a warden.rb initializer with the following:
Rails.configuration.middleware.use Warden::Manager do |manager|
manager.failure_app = UserSessionsController
Warden::Manager.before_failure do |env, opts|
env['action_dispatch.request.path_parameters'][:action] = "new"
Warden::Manager.serialize_into_session do |user|
Warden::Manager.serialize_from_session do |id|
params[:email] || params[:password]
u = User.authenticate(params[:email], params[:password])
u.nil? ? fail!("authentication error from warden") : success!(u)
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.