0
Warden
General Rack Authentication
Many Web Apps Need
1. A User
2. A way to associate it
     with a request
Many Solutions Exist
•                            •
    Restful Authentication       Basic Auth

•                        ...
Why Another One?
Rack
Rack Router
class SimpleRack
  include Rack::Router::Routable

  def initialize
    prepare do |r|
      r.map quot;/quot;, :to => rou...
Mountable Apps
How Will Your
Authentication Cope?
Apps Usually Need a
      “User”
Current Breed Will
Conflict Between Apps
Warden
• Injects a very lazy proxy into the request
• Proxy follows around in the request
• Does nothing until you ask it
...
Authenticating
              (Logging In)

env['warden'].authenticate     :password

env['warden'].authenticate!    :passw...
Accessing The User

   env['warden'].user
Logging Out

env['warden'].logout
Authentication Logic

• Strategy Based
• Packagable
• Sharable between discrete Apps
• Simple
Strategy
Warden::Strategies.add(:password) do

  def valid?
    params[:username] || params[:password]
  end

  def authen...
Strategies

    • Multiple Strategies
    • Strategies Cascade

env['warden'].authenticate!   :password, :basic, :open_id
Failure

 throw(:warden)

 throw(:warden, :some => :option)




Drops out to a “Failure Application”
Rack Setup
Rack::Builder.new do
  use Rack::Session::Cookie

  use Warden::Manager do |manager|
    manager.default_strate...
Session Integration


Warden::Manager.serialize_into_session{ |user| user.id }



Warden::Manager.serialize_from_session{ ...
Other Features

• Callbacks
• User Scopes - Multiple Users / session
• Authenticated Session Data
 • Locks Session per user
Rails Integration
                  config/initializers/warden.rb
Rails.configuration.middleware.use Warden::Manager do |ma...
More Information

• http://github.com/hassox/warden

• http://wiki.github.com/hassox/warden
Warden Introduction
Warden Introduction
Upcoming SlideShare
Loading in...5
×

Warden Introduction

20,058

Published on

A introductory talk about Warden, a Ruby Rack authentication framework, to the Melbourne Ruby Users Group

Published in: Technology
1 Comment
25 Likes
Statistics
Notes
  • on slide25, must be User.get(key)
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Views
Total Views
20,058
On Slideshare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
152
Comments
1
Likes
25
Embeds 0
No embeds

No notes for slide
























































  • Transcript of "Warden Introduction"

    1. 1. Warden General Rack Authentication
    2. 2. Many Web Apps Need
    3. 3. 1. A User
    4. 4. 2. A way to associate it with a request
    5. 5. Many Solutions Exist • • Restful Authentication Basic Auth • • AuthLogic Digest • • Merbful Authentication LAPD • • Merb-Auth CAS • Home Grown • OpenID
    6. 6. Why Another One?
    7. 7. Rack
    8. 8. Rack Router
    9. 9. class SimpleRack include Rack::Router::Routable def initialize prepare do |r| r.map quot;/quot;, :to => router { |c| c.map quot;/helloquot;, :to => ChildApp } r.map quot;/helloquot;, :to => ParentApp r.map quot;/onequot;, :to => lambda { |env| do_one(env) } r.map quot;/twoquot;, :to => lambda { |env| do_two(env) } end end def do_one(env) # Stuff end def do_two(env) # Stuff end end
    10. 10. Mountable Apps
    11. 11. How Will Your Authentication Cope?
    12. 12. Apps Usually Need a “User”
    13. 13. Current Breed Will Conflict Between Apps
    14. 14. Warden • Injects a very lazy proxy into the request • Proxy follows around in the request • Does nothing until you ask it • Authenticates Requests for any kind of “User” • Provides a mechanism for Authentication • Available in all downstream Rack parts
    15. 15. Authenticating (Logging In) env['warden'].authenticate :password env['warden'].authenticate! :password, :basic, :open_id env['warden'].authenticated? :password
    16. 16. Accessing The User env['warden'].user
    17. 17. Logging Out env['warden'].logout
    18. 18. Authentication Logic • Strategy Based • Packagable • Sharable between discrete Apps • Simple
    19. 19. Strategy Warden::Strategies.add(:password) do def valid? params[:username] || params[:password] end def authenticate! u = User.authenticate(params[:username], params[:password]) u.nil? ? fail!(quot;Could not log inquot;) : success!(u) end end
    20. 20. Strategies • Multiple Strategies • Strategies Cascade env['warden'].authenticate! :password, :basic, :open_id
    21. 21. Failure throw(:warden) throw(:warden, :some => :option) Drops out to a “Failure Application”
    22. 22. Rack Setup Rack::Builder.new do use Rack::Session::Cookie use Warden::Manager do |manager| manager.default_strategies :password, :basic manager.failure_app = BadAuthenticationEndsUpHere end run SomeApp end
    23. 23. Session Integration Warden::Manager.serialize_into_session{ |user| user.id } Warden::Manager.serialize_from_session{ |key| User.get(id)}
    24. 24. Other Features • Callbacks • User Scopes - Multiple Users / session • Authenticated Session Data • Locks Session per user
    25. 25. Rails Integration config/initializers/warden.rb Rails.configuration.middleware.use Warden::Manager do |manager| manager.default_strategies :password manager.failure_app = LoginController end # Rails needs the action to be passed in with the params Warden::Manager.before_failure do |env, opts| request = env[quot;action_controller.rescue.requestquot;] request.params[quot;actionquot;] = quot;unauthenticatedquot; end # Session Serialization & Strategies
    26. 26. More Information • http://github.com/hassox/warden • http://wiki.github.com/hassox/warden
    1. A particular slide catching your eye?

      Clipping is a handy way to collect important slides you want to go back to later.

    ×