loyal_warden 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. data/Gemfile +11 -0
  2. data/History.rdoc +150 -0
  3. data/LICENSE +20 -0
  4. data/README.textile +9 -0
  5. data/Rakefile +12 -0
  6. data/lib/loyal_warden.rb +2 -0
  7. data/lib/warden.rb +45 -0
  8. data/lib/warden/config.rb +112 -0
  9. data/lib/warden/errors.rb +66 -0
  10. data/lib/warden/hooks.rb +211 -0
  11. data/lib/warden/manager.rb +136 -0
  12. data/lib/warden/mixins/common.rb +44 -0
  13. data/lib/warden/proxy.rb +371 -0
  14. data/lib/warden/session_serializer.rb +52 -0
  15. data/lib/warden/strategies.rb +47 -0
  16. data/lib/warden/strategies/base.rb +175 -0
  17. data/lib/warden/test/helpers.rb +36 -0
  18. data/lib/warden/test/warden_helpers.rb +43 -0
  19. data/lib/warden/version.rb +4 -0
  20. data/loyal_warden.gemspec +26 -0
  21. data/spec/helpers/request_helper.rb +51 -0
  22. data/spec/helpers/strategies/failz.rb +8 -0
  23. data/spec/helpers/strategies/invalid.rb +8 -0
  24. data/spec/helpers/strategies/pass.rb +8 -0
  25. data/spec/helpers/strategies/pass_with_message.rb +8 -0
  26. data/spec/helpers/strategies/password.rb +13 -0
  27. data/spec/helpers/strategies/single.rb +12 -0
  28. data/spec/spec_helper.rb +24 -0
  29. data/spec/warden/authenticated_data_store_spec.rb +114 -0
  30. data/spec/warden/config_spec.rb +48 -0
  31. data/spec/warden/errors_spec.rb +47 -0
  32. data/spec/warden/hooks_spec.rb +373 -0
  33. data/spec/warden/manager_spec.rb +316 -0
  34. data/spec/warden/proxy_spec.rb +1041 -0
  35. data/spec/warden/scoped_session_serializer.rb +123 -0
  36. data/spec/warden/session_serializer_spec.rb +53 -0
  37. data/spec/warden/strategies/base_spec.rb +313 -0
  38. data/spec/warden/strategies_spec.rb +93 -0
  39. data/spec/warden/test/helpers_spec.rb +93 -0
  40. data/spec/warden/test/test_mode_spec.rb +76 -0
  41. data/warden.gemspec +24 -0
  42. metadata +105 -0
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ gem 'rake'
6
+ gem 'rack', '1.3'
7
+
8
+ group :test do
9
+ gem 'rspec', '~>2'
10
+ gem 'rack-test'
11
+ end
@@ -0,0 +1,150 @@
1
+ == Version 1.2.3 / 2013-07-14
2
+ * Fix an issue with lazy loaded sessions
3
+
4
+ == Version 1.2.2 / 2013-07-12
5
+ * Support nil session stores on logout
6
+ * Fix strategies blowing up with undefined method base
7
+
8
+ == Version 1.2.1 / 2012-06-16
9
+ * Minor caching and speed improvements
10
+ * Add support to #lock in the proxy
11
+ * Add support to after_failed_fetch callback
12
+
13
+ == Version 1.2.0 / 2012-05-08
14
+ * Deprecate warden_cookies since it was never functional
15
+ * Add support to serialize_from_session and serialize_into_session per scope
16
+
17
+ == Version 1.1.1 / 2012-02-16
18
+ * Allow run_callbacks as an option to set_user and user
19
+
20
+ == Version 1.1.0 / 2011-11-02
21
+ * Use the default scopes action when using a bare throw(:warden)
22
+
23
+ == Version 1.0.6
24
+ * Remove gem files from the packaged gem
25
+
26
+ == Version 1.0.3
27
+ * Do not renew session on user fetch
28
+
29
+ == Version 1.0.2
30
+ * Added :intercept_401 to Warden::Config
31
+
32
+ == Version 1.0.1
33
+ * Bug fix on strategies errors handler
34
+
35
+ == Version 1.0.0
36
+ * Bump!
37
+ * Allow strategies to configure if user should be stored or not
38
+ * Force session id renewal when user is set
39
+
40
+ == Version 0.10.7
41
+ * Performance boost. config object to use raw accessors
42
+ * Add per strategy storage option
43
+
44
+ == Version 0.10.6 / 0.10.7 / 2010-05-22
45
+ * Bugfix set_user was not respecting logouts in hooks
46
+
47
+ == Version 0.10.4 / 0.10.5 / 2010-05-20
48
+ * Add action specifying in scope_defaults
49
+
50
+ == Version 0.10.3 / 2010-03-01
51
+ * Bugfix prevent halted winning strategy from being skipped in subsequent runs
52
+
53
+ == Version 0.10.2 / 2010-03-26
54
+ * Halt on fail!. Add fail to allow cascading
55
+ * cache the winning strategy
56
+ * Make the config object Dupable
57
+
58
+ == Version 0.10.1 / 2010-03-23
59
+ * Merge previous from master
60
+ * tag
61
+
62
+ == Version 0.10.0 / 2010-03-22
63
+ * Allow default strategies to be set on the proxy
64
+ * Provide each scope with it's own default strategies
65
+ * Provide each scope with default set_user opts
66
+ * depricate the Proxy#default_strategies= method
67
+
68
+ == Version 0.9.5 / 2010-02-28
69
+
70
+ * Add Warden.test_mode!
71
+ * Add Warden.on_next_request
72
+ * Add test helpers in Warden::Test::Helpers
73
+ ** login_as
74
+ ** logout
75
+
76
+ == Version 0.9.4 / 2010-02-23
77
+
78
+ * Fix an issue where winning_strategy was not cleaned, allowing multiple scopes to sign in, even when the second one should not
79
+
80
+ == Version 0.9.3 / 2010-02-17
81
+
82
+ * Add prepend_ to all hooks (josevalim)
83
+
84
+ == Version 0.9.2 / 2010-02-10
85
+
86
+ * Ruby 1.9 compatibility changes (grimen)
87
+
88
+ == Version 0.9.1 / 2010-02-09
89
+
90
+ * Support for passing a custom message with Warden::Strategy::Base#success! as second optional (grimen)
91
+
92
+ == Version 0.9.0 / 2010-01-21
93
+
94
+ * Remove serializers and make strategies more powerful, including cache behavior (josevalim)
95
+
96
+ == Version 0.8.1 / 2010-01-06
97
+
98
+ * Fix a bug when silence missing serializers is set (josevalim)
99
+
100
+ == Version 0.8.0 / 2010-01-06
101
+
102
+ * enhancements
103
+ * Add conditionals to callbacks (josevalim)
104
+ * Extract Warden::Config from Warden::Manager (josevalim)
105
+
106
+ == Version 0.7.0 / 2010-01-04
107
+
108
+ * enhancements
109
+ * Expose config in warden proxy (hassox)
110
+
111
+ == Version 0.6.0 / 2009-11-16
112
+
113
+ * enhancements
114
+ * added serializers, including session serializer (set by default) and a cookie serializer (josevalim)
115
+
116
+ * deprecation
117
+ * serializer_into_session and serializer_from_session are deprecated, overwrite serialize and deserializer in Warden::Serializers::Session instead (josevalim)
118
+
119
+ == Version 0.5.3 / 2009-11-10
120
+ * bug fixes
121
+ * authenticated? and unauthenticated? should return true or false, not the user or false. (hassox)
122
+
123
+ == Version 0.5.2 / 2009-11-09
124
+ * enhancements
125
+ * authenticated? always try to serialize the user from session (josevalim)
126
+ * stored_in_session? checks if user information is stored in session, without serializing (josevalim)
127
+ * 401 behaves exactly like throw :warden (staugaard)
128
+
129
+ === Version 0.5.1 / 2009-10-25
130
+ * enhancements
131
+ * Adds yeilding to authenticated? and unauthenticated? methods (hassox)
132
+ * Adds an option to silence missing strategies (josevalim)
133
+ * Add an option to authenticate(!) to prevent storage of a user into the session (hassox)
134
+ * allow custom :action to be thrown (josevalim)
135
+
136
+ === Version 0.4.0 / 2009-10-12
137
+
138
+ * enhancements
139
+ * add Content-Type header to redirects (staugaard)
140
+ * Make scope available to strategies (josevalim)
141
+
142
+ * bug fixes
143
+ * Do not consume opts twice, otherwise just the first will parse the scope (josevalim)
144
+
145
+ === Version 0.3.2 / 2009-09-15
146
+
147
+ * enhancements
148
+ * add a hook for plugins to specify how they can clear the whole section
149
+
150
+
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Daniel Neighman
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,9 @@
1
+ Please see the "Warden Wiki":http://wiki.github.com/hassox/warden for overview documentation.
2
+
3
+ h2. Maintainers
4
+
5
+ * Daniel Neighman (hassox)
6
+ * José Valim (josevalim)
7
+ * Justin Smestad (jsmestad)
8
+
9
+ "A list of all contributors is available on Github.":https://github.com/hassox/warden/contributors
@@ -0,0 +1,12 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require 'rubygems'
3
+ require 'rake'
4
+ $:.unshift File.join(File.dirname(__FILE__), "lib")
5
+
6
+ require 'rspec/core'
7
+ require 'rspec/core/rake_task'
8
+
9
+ task :default => :spec
10
+
11
+ desc "Run all specs in spec directory"
12
+ RSpec::Core::RakeTask.new(:spec)
@@ -0,0 +1,2 @@
1
+ require 'warden'
2
+
@@ -0,0 +1,45 @@
1
+ # encoding: utf-8
2
+ require 'forwardable'
3
+
4
+ require 'warden/mixins/common'
5
+ require 'warden/proxy'
6
+ require 'warden/manager'
7
+ require 'warden/errors'
8
+ require 'warden/session_serializer'
9
+ require 'warden/strategies'
10
+ require 'warden/strategies/base'
11
+
12
+ module Warden
13
+ class NotAuthenticated < StandardError; end
14
+
15
+ module Test
16
+ autoload :WardenHelpers, 'warden/test/warden_helpers'
17
+ autoload :Helpers, 'warden/test/helpers'
18
+ end
19
+
20
+ # Provides helper methods to warden for testing.
21
+ #
22
+ # To setup warden in test mode call the +test_mode!+ method on warden
23
+ #
24
+ # @example
25
+ # Warden.test_mode!
26
+ #
27
+ # This will provide a number of methods.
28
+ # Warden.on_next_request(&blk) - captures a block which is yielded the warden proxy on the next request
29
+ # Warden.test_reset! - removes any captured blocks that would have been executed on the next request
30
+ #
31
+ # Warden.test_reset! should be called in after blocks for rspec, or teardown methods for Test::Unit
32
+ def self.test_mode!
33
+ unless Warden::Test::WardenHelpers === Warden
34
+ Warden.extend Warden::Test::WardenHelpers
35
+ Warden::Manager.on_request do |proxy|
36
+ unless proxy.asset_request?
37
+ while blk = Warden._on_next_request.shift
38
+ blk.call(proxy)
39
+ end
40
+ end
41
+ end
42
+ end
43
+ true
44
+ end
45
+ end
@@ -0,0 +1,112 @@
1
+ # encoding: utf-8
2
+
3
+ module Warden
4
+ # This is a class which is yielded on use Warden::Manager. If you have a plugin
5
+ # and wants to add more configuration to warden, you just need to extend this
6
+ # class.
7
+ class Config < Hash
8
+ # Creates an accessor that simply sets and reads a key in the hash:
9
+ #
10
+ # class Config < Hash
11
+ # hash_accessor :failure_app
12
+ # end
13
+ #
14
+ # config = Config.new
15
+ # config.failure_app = Foo
16
+ # config[:failure_app] #=> Foo
17
+ #
18
+ # config[:failure_app] = Bar
19
+ # config.failure_app #=> Bar
20
+ #
21
+ def self.hash_accessor(*names) #:nodoc:
22
+ names.each do |name|
23
+ class_eval <<-METHOD, __FILE__, __LINE__ + 1
24
+ def #{name}
25
+ self[:#{name}]
26
+ end
27
+
28
+ def #{name}=(value)
29
+ self[:#{name}] = value
30
+ end
31
+ METHOD
32
+ end
33
+ end
34
+
35
+ hash_accessor :failure_app, :default_scope, :intercept_401
36
+
37
+ def initialize(other={})
38
+ merge!(other)
39
+ self[:default_scope] ||= :default
40
+ self[:scope_defaults] ||= {}
41
+ self[:default_strategies] ||= {}
42
+ self[:intercept_401] = true unless key?(:intercept_401)
43
+ end
44
+
45
+ def initialize_copy(other)
46
+ super
47
+ deep_dup(:scope_defaults, other)
48
+ deep_dup(:default_strategies, other)
49
+ end
50
+
51
+ # Do not raise an error if a missing strategy is given.
52
+ # :api: plugin
53
+ def silence_missing_strategies!
54
+ self[:silence_missing_strategies] = true
55
+ end
56
+
57
+ def silence_missing_strategies? #:nodoc:
58
+ !!self[:silence_missing_strategies]
59
+ end
60
+
61
+ # Set the default strategies to use.
62
+ # :api: public
63
+ def default_strategies(*strategies)
64
+ opts = Hash === strategies.last ? strategies.pop : {}
65
+ hash = self[:default_strategies]
66
+ scope = opts[:scope] || :_all
67
+
68
+ hash[scope] = strategies.flatten unless strategies.empty?
69
+ hash[scope] || hash[:_all] || []
70
+ end
71
+
72
+ # A short hand way to set up a particular scope
73
+ # :api: public
74
+ def scope_defaults(scope, opts = {})
75
+ if strategies = opts.delete(:strategies)
76
+ default_strategies(strategies, :scope => scope)
77
+ end
78
+
79
+ if opts.empty?
80
+ self[:scope_defaults][scope] || {}
81
+ else
82
+ self[:scope_defaults][scope] ||= {}
83
+ self[:scope_defaults][scope].merge!(opts)
84
+ end
85
+ end
86
+
87
+ # Quick accessor to strategies from manager
88
+ # :api: public
89
+ def strategies
90
+ Warden::Strategies
91
+ end
92
+
93
+ # Hook from configuration to serialize_into_session.
94
+ # :api: public
95
+ def serialize_into_session(*args, &block)
96
+ Warden::Manager.serialize_into_session(*args, &block)
97
+ end
98
+
99
+ # Hook from configuration to serialize_from_session.
100
+ # :api: public
101
+ def serialize_from_session(*args, &block)
102
+ Warden::Manager.serialize_from_session(*args, &block)
103
+ end
104
+
105
+ protected
106
+
107
+ def deep_dup(key, other)
108
+ self[key] = hash = other[key].dup
109
+ hash.each { |k, v| hash[k] = v.dup }
110
+ end
111
+ end
112
+ end
@@ -0,0 +1,66 @@
1
+ # encoding: utf-8
2
+ module Warden
3
+ class Proxy
4
+ # Lifted from DataMapper's dm-validations plugin :)
5
+ # @author Guy van den Berg
6
+ # @since DM 0.9
7
+ class Errors
8
+
9
+ include Enumerable
10
+
11
+ # Clear existing authentication errors.
12
+ def clear!
13
+ errors.clear
14
+ end
15
+
16
+ # Add a authentication error. Use the field_name :general if the errors does
17
+ # not apply to a specific field of the Resource.
18
+ #
19
+ # @param <Symbol> field_name the name of the field that caused the error
20
+ # @param <String> message the message to add
21
+ def add(field_name, message)
22
+ (errors[field_name] ||= []) << message
23
+ end
24
+
25
+ # Collect all errors into a single list.
26
+ def full_messages
27
+ errors.inject([]) do |list,pair|
28
+ list += pair.last
29
+ end
30
+ end
31
+
32
+ # Return authentication errors for a particular field_name.
33
+ #
34
+ # @param <Symbol> field_name the name of the field you want an error for
35
+ def on(field_name)
36
+ errors_for_field = errors[field_name]
37
+ blank?(errors_for_field) ? nil : errors_for_field
38
+ end
39
+
40
+ def each
41
+ errors.map.each do |k,v|
42
+ next if blank?(v)
43
+ yield(v)
44
+ end
45
+ end
46
+
47
+ def empty?
48
+ entries.empty?
49
+ end
50
+
51
+ def method_missing(meth, *args, &block)
52
+ errors.send(meth, *args, &block)
53
+ end
54
+
55
+ private
56
+ def errors
57
+ @errors ||= {}
58
+ end
59
+
60
+ def blank?(thing)
61
+ thing.nil? || thing == "" || (thing.respond_to?(:empty?) && thing.empty?)
62
+ end
63
+
64
+ end # class Errors
65
+ end # Proxy
66
+ end # Warden
@@ -0,0 +1,211 @@
1
+ # encoding: utf-8
2
+ module Warden
3
+ module Hooks
4
+
5
+ # Hook to _run_callbacks asserting for conditions.
6
+ def _run_callbacks(kind, *args) #:nodoc:
7
+ options = args.last # Last callback arg MUST be a Hash
8
+
9
+ send("_#{kind}").each do |callback, conditions|
10
+ invalid = conditions.find do |key, value|
11
+ value.is_a?(Array) ? !value.include?(options[key]) : (value != options[key])
12
+ end
13
+
14
+ callback.call(*args) unless invalid
15
+ end
16
+ end
17
+
18
+ # A callback hook set to run every time after a user is set.
19
+ # This callback is triggered the first time one of those three events happens
20
+ # during a request: :authentication, :fetch (from session) and :set_user (when manually set).
21
+ # You can supply as many hooks as you like, and they will be run in order of decleration.
22
+ #
23
+ # If you want to run the callbacks for a given scope and/or event, you can specify them as options.
24
+ # See parameters and example below.
25
+ #
26
+ # Parameters:
27
+ # <options> Some options which specify when the callback should be executed
28
+ # scope - Executes the callback only if it maches the scope(s) given
29
+ # only - Executes the callback only if it matches the event(s) given
30
+ # except - Executes the callback except if it matches the event(s) given
31
+ # <block> A block where you can set arbitrary logic to run every time a user is set
32
+ # Block Parameters: |user, auth, opts|
33
+ # user - The user object that is being set
34
+ # auth - The raw authentication proxy object.
35
+ # opts - any options passed into the set_user call includeing :scope
36
+ #
37
+ # Example:
38
+ # Warden::Manager.after_set_user do |user,auth,opts|
39
+ # scope = opts[:scope]
40
+ # if auth.session["#{scope}.last_access"].to_i > (Time.now - 5.minutes)
41
+ # auth.logout(scope)
42
+ # throw(:warden, :scope => scope, :reason => "Times Up")
43
+ # end
44
+ # auth.session["#{scope}.last_access"] = Time.now
45
+ # end
46
+ #
47
+ # Warden::Manager.after_set_user :except => :fetch do |user,auth,opts|
48
+ # user.login_count += 1
49
+ # end
50
+ #
51
+ # :api: public
52
+ def after_set_user(options = {}, method = :push, &block)
53
+ raise BlockNotGiven unless block_given?
54
+
55
+ if options.key?(:only)
56
+ options[:event] = options.delete(:only)
57
+ elsif options.key?(:except)
58
+ options[:event] = [:set_user, :authentication, :fetch] - Array(options.delete(:except))
59
+ end
60
+
61
+ _after_set_user.send(method, [block, options])
62
+ end
63
+
64
+ # Provides access to the array of after_set_user blocks to run
65
+ # :api: private
66
+ def _after_set_user # :nodoc:
67
+ @_after_set_user ||= []
68
+ end
69
+
70
+ # after_authentication is just a wrapper to after_set_user, which is only invoked
71
+ # when the user is set through the authentication path. The options and yielded arguments
72
+ # are the same as in after_set_user.
73
+ #
74
+ # :api: public
75
+ def after_authentication(options = {}, method = :push, &block)
76
+ after_set_user(options.merge(:event => :authentication), method, &block)
77
+ end
78
+
79
+ # after_fetch is just a wrapper to after_set_user, which is only invoked
80
+ # when the user is fetched from sesion. The options and yielded arguments
81
+ # are the same as in after_set_user.
82
+ #
83
+ # :api: public
84
+ def after_fetch(options = {}, method = :push, &block)
85
+ after_set_user(options.merge(:event => :fetch), method, &block)
86
+ end
87
+
88
+ # A callback that runs just prior to the failur application being called.
89
+ # This callback occurs after PATH_INFO has been modified for the failure (default /unauthenticated)
90
+ # In this callback you can mutate the environment as required by the failure application
91
+ # If a Rails controller were used for the failure_app for example, you would need to set request[:params][:action] = :unauthenticated
92
+ #
93
+ # Parameters:
94
+ # <options> Some options which specify when the callback should be executed
95
+ # scope - Executes the callback only if it maches the scope(s) given
96
+ # <block> A block to contain logic for the callback
97
+ # Block Parameters: |env, opts|
98
+ # env - The rack env hash
99
+ # opts - any options passed into the authenticate call includeing :scope
100
+ #
101
+ # Example:
102
+ # Warden::Manager.before_failure do |env, opts|
103
+ # params = Rack::Request.new(env).params
104
+ # params[:action] = :unauthenticated
105
+ # params[:warden_failure] = opts
106
+ # end
107
+ #
108
+ # :api: public
109
+ def before_failure(options = {}, method = :push, &block)
110
+ raise BlockNotGiven unless block_given?
111
+ _before_failure.send(method, [block, options])
112
+ end
113
+
114
+ # Provides access to the callback array for before_failure
115
+ # :api: private
116
+ def _before_failure
117
+ @_before_failure ||= []
118
+ end
119
+
120
+ # A callback that runs if no user could be fetched, meaning there is now no user logged in.
121
+ #
122
+ # Parameters:
123
+ # <options> Some options which specify when the callback should be executed
124
+ # scope - Executes the callback only if it maches the scope(s) given
125
+ # <block> A block to contain logic for the callback
126
+ # Block Parameters: |user, auth, scope|
127
+ # user - The authenticated user for the current scope
128
+ # auth - The warden proxy object
129
+ # opts - any options passed into the authenticate call including :scope
130
+ #
131
+ # Example:
132
+ # Warden::Manager.after_failed_fetch do |user, auth, opts|
133
+ # I18n.locale = :en
134
+ # end
135
+ #
136
+ # :api: public
137
+ def after_failed_fetch(options = {}, method = :push, &block)
138
+ raise BlockNotGiven unless block_given?
139
+ _after_failed_fetch.send(method, [block, options])
140
+ end
141
+
142
+ # Provides access to the callback array for after_failed_fetch
143
+ # :api: private
144
+ def _after_failed_fetch
145
+ @_after_failed_fetch ||= []
146
+ end
147
+
148
+ # A callback that runs just prior to the logout of each scope.
149
+ #
150
+ # Parameters:
151
+ # <options> Some options which specify when the callback should be executed
152
+ # scope - Executes the callback only if it maches the scope(s) given
153
+ # <block> A block to contain logic for the callback
154
+ # Block Parameters: |user, auth, scope|
155
+ # user - The authenticated user for the current scope
156
+ # auth - The warden proxy object
157
+ # opts - any options passed into the authenticate call including :scope
158
+ #
159
+ # Example:
160
+ # Warden::Manager.before_logout do |user, auth, opts|
161
+ # user.forget_me!
162
+ # end
163
+ #
164
+ # :api: public
165
+ def before_logout(options = {}, method = :push, &block)
166
+ raise BlockNotGiven unless block_given?
167
+ _before_logout.send(method, [block, options])
168
+ end
169
+
170
+ # Provides access to the callback array for before_logout
171
+ # :api: private
172
+ def _before_logout
173
+ @_before_logout ||= []
174
+ end
175
+
176
+ # A callback that runs on each request, just after the proxy is initialized
177
+ #
178
+ # Parameters:
179
+ # <block> A block to contain logic for the callback
180
+ # Block Parameters: |proxy|
181
+ # proxy - The warden proxy object for the request
182
+ #
183
+ # Example:
184
+ # user = "A User"
185
+ # Warden::Manager.on_request do |proxy|
186
+ # proxy.set_user = user
187
+ # end
188
+ #
189
+ # :api: public
190
+ def on_request(options = {}, method = :push, &block)
191
+ raise BlockNotGiven unless block_given?
192
+ _on_request.send(method, [block, options])
193
+ end
194
+
195
+ # Provides access to the callback array for before_logout
196
+ # :api: private
197
+ def _on_request
198
+ @_on_request ||= []
199
+ end
200
+
201
+ # Add prepend filters version
202
+ %w(after_set_user after_authentication after_fetch on_request
203
+ before_failure before_logout).each do |filter|
204
+ class_eval <<-METHOD, __FILE__, __LINE__ + 1
205
+ def prepend_#{filter}(options={}, &block)
206
+ #{filter}(options, :unshift, &block)
207
+ end
208
+ METHOD
209
+ end
210
+ end # Hooks
211
+ end # Warden