# Simplest Warden Implementation

**URL:** <https://www.ruby-forum.com/t/simplest-warden-implementation/188746>\
**Category:** Rails\
**Created:** [May 17, 2010, 7:00pm UTC](https://www.ruby-forum.com/t/simplest-warden-implementation/188746 "2010-05-17T19:00:52Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![tkimble](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/46a35a/32.png) [@tkimble](https://www.ruby-forum.com/u/tkimble)\
**Post date:** [May 17, 2010, 7:00pm UTC](https://www.ruby-forum.com/t/simplest-warden-implementation/188746/1 "2010-05-17T19:00:52Z")

</div>

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.  
([GitHub - wardencommunity/rails\_warden: A thin rails plugin on top of Warden for Authentication](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
