Warden
Warden is a Rack-based middleware, designed to provide a mechanism for authentication in Ruby web applications. It is a common mechanism that fits into the Rack Machinery to offer powerful options for authentication.
»
Warden
Strategies?!
General Rack Authentication Framework
Rack
Ruby on Rails and Sinatra are both built on top of Rack
Provides a minimal interface between webservers supporting Ruby and Ruby frameworks.
The Russian Doll Pattern
class HelloAthega
def call(env)
[200, {"Content-Type" => "text/plain"}, ["Hello Athega!"]]
end
end
Or, turtles all the way down.
The promise of multiple applications running in the same process, sub-applications and sub-sub-applications can be realized.
What?
Warden is a Rack-based middleware, designed to provide a mechanism for authentication in Ruby web applications.
require 'rack/flash'
require 'blog.rb'
require 'app.rb'
use Rack::Flash
use Blog
run App
Why?
How?
Warden sits in the Rack stack, after the session middleware.
Warden injects a lazy object into the Rack environment at env[‘warden’]
use Warden::Manager do |manager|
manager.default_strategies :password
manager.failure_app = App
end
Conceptually a strategy is where you put the logic for authenticating a request.
Warden::Strategies.add(:password) do
def valid?
params[:username] || params[:password]
end
def authenticate!
u = User.authenticate(params[:username], params[:password])
u.nil? ? fail!("Could not log in") : success!(u)
end
end
Sharing is caring!
For example, you may want to throw up a quick test application in Sinatra or straight Rack.
Using Warden you can share the same strategies from your main application and provide consistent, company wide authentication requirements.
config.ruPopular presentations
Faith: the Final Frontier
Celebration Christian Church on
http://www.celebrationchristianchurch.com/, celebration christian church is a local part of the body of Christ (The Church) in Northwest Portland Oregon. We are full of the Holy ...
More popular prezis in Explore>