warden 0.5.3 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.rdoc +8 -5
- data/README.textile +1 -1
- data/lib/warden.rb +7 -4
- data/lib/warden/declarable.rb +43 -0
- data/lib/warden/hooks.rb +121 -0
- data/lib/warden/manager.rb +52 -21
- data/lib/warden/mixins/common.rb +11 -2
- data/lib/warden/proxy.rb +88 -32
- data/lib/warden/serializers.rb +20 -0
- data/lib/warden/serializers/base.rb +38 -0
- data/lib/warden/serializers/cookie.rb +34 -0
- data/lib/warden/serializers/session.rb +30 -0
- data/lib/warden/strategies.rb +18 -0
- data/lib/warden/{authentication/strategy_base.rb → strategies/base.rb} +27 -2
- data/lib/warden/version.rb +1 -1
- data/spec/helpers/request_helper.rb +14 -12
- data/spec/{warden → helpers}/strategies/failz.rb +0 -0
- data/spec/{warden → helpers}/strategies/invalid.rb +0 -0
- data/spec/{warden → helpers}/strategies/pass.rb +0 -0
- data/spec/{warden → helpers}/strategies/pass_without_user.rb +0 -0
- data/spec/{warden → helpers}/strategies/password.rb +0 -0
- data/spec/spec_helper.rb +1 -1
- data/spec/warden/authenticated_data_store_spec.rb +4 -4
- data/spec/warden/manager_spec.rb +0 -8
- data/spec/warden/proxy_spec.rb +61 -10
- data/spec/warden/serializers/cookie_spec.rb +60 -0
- data/spec/warden/serializers/session_spec.rb +47 -0
- data/spec/warden/serializers_spec.rb +96 -0
- data/spec/warden/{strategy_base_spec.rb → strategies/base_spec.rb} +1 -1
- data/spec/warden/strategies_spec.rb +19 -15
- data/warden.gemspec +28 -18
- metadata +28 -18
- data/VERSION +0 -1
- data/lib/warden/authentication/hooks.rb +0 -124
- data/lib/warden/authentication/strategies.rb +0 -59
data/VERSION
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
0.5.3
|
@@ -1,124 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
module Warden
|
3
|
-
class Manager
|
4
|
-
|
5
|
-
class << self
|
6
|
-
# A callback hook set to run every time after a user is set.
|
7
|
-
# This will happen the first time the user is either authenticated, accessed or manually set
|
8
|
-
# during a request. You can supply as many hooks as you like, and they will be run in order of decleration
|
9
|
-
#
|
10
|
-
# Parameters:
|
11
|
-
# <block> A block where you can set arbitrary logic to run every time a user is set
|
12
|
-
# Block Parameters: |user, auth, opts|
|
13
|
-
# user - The user object that is being set
|
14
|
-
# auth - The raw authentication proxy object.
|
15
|
-
# opts - any options passed into the set_user call includeing :scope
|
16
|
-
#
|
17
|
-
# Example:
|
18
|
-
# Warden::Manager.after_set_user do |user,auth,opts|
|
19
|
-
# scope = opts[:scope]
|
20
|
-
# if auth.session["#{scope}.last_access"].to_i > (Time.now - 5.minutes)
|
21
|
-
# auth.logout(scope)
|
22
|
-
# throw(:warden, :scope => scope, :reason => "Times Up")
|
23
|
-
# end
|
24
|
-
# auth.session["#{scope}.last_access"] = Time.now
|
25
|
-
# end
|
26
|
-
#
|
27
|
-
# :api: public
|
28
|
-
def after_set_user(&block)
|
29
|
-
raise BlockNotGiven unless block_given?
|
30
|
-
_after_set_user << block
|
31
|
-
end
|
32
|
-
|
33
|
-
# Provides access to the array of after_set_user blocks to run
|
34
|
-
# :api: private
|
35
|
-
def _after_set_user # :nodoc:
|
36
|
-
@_after_set_user ||= []
|
37
|
-
end
|
38
|
-
|
39
|
-
# A callback hook set to run after the first authentiation of a session.
|
40
|
-
# This will only happenwhen the session is first authenticated
|
41
|
-
#
|
42
|
-
# Parameters:
|
43
|
-
# <block> A block to contain logic for the callback
|
44
|
-
# Block Parameters: |user, auth, opts|
|
45
|
-
# user - The user object that is being set
|
46
|
-
# auth - The raw authentication proxy object.
|
47
|
-
# opts - any options passed into the authenticate call includeing :scope
|
48
|
-
#
|
49
|
-
# Example:
|
50
|
-
#
|
51
|
-
# Warden::Manager.after_authentication do |user, auth, opts|
|
52
|
-
# throw(:warden, opts) unless user.active?
|
53
|
-
# end
|
54
|
-
#
|
55
|
-
# :api: public
|
56
|
-
def after_authentication(&block)
|
57
|
-
raise BlockNotGiven unless block_given?
|
58
|
-
_after_authentication << block
|
59
|
-
end
|
60
|
-
|
61
|
-
# Provides access to the array of after_authentication blocks
|
62
|
-
# :api: private
|
63
|
-
def _after_authentication
|
64
|
-
@_after_authentication ||= []
|
65
|
-
end
|
66
|
-
|
67
|
-
# A callback that runs just prior to the failur application being called.
|
68
|
-
# This callback occurs after PATH_INFO has been modified for the failure (default /unauthenticated)
|
69
|
-
# In this callback you can mutate the environment as required by the failure application
|
70
|
-
# If a Rails controller were used for the failure_app for example, you would need to set request[:params][:action] = :unauthenticated
|
71
|
-
#
|
72
|
-
# Parameters:
|
73
|
-
# <block> A block to contain logic for the callback
|
74
|
-
# Block Parameters: |user, auth, opts|
|
75
|
-
# env - The rack env hash
|
76
|
-
# opts - any options passed into the authenticate call includeing :scope
|
77
|
-
#
|
78
|
-
# Example:
|
79
|
-
# Warden::Manager.before_failure do |env, opts|
|
80
|
-
# params = Rack::Request.new(env).params
|
81
|
-
# params[:action] = :unauthenticated
|
82
|
-
# params[:warden_failure] = opts
|
83
|
-
# end
|
84
|
-
#
|
85
|
-
# :api: public
|
86
|
-
def before_failure(&block)
|
87
|
-
_before_failure << block
|
88
|
-
end
|
89
|
-
|
90
|
-
# Provides access to the callback array for before_failure
|
91
|
-
# :api: private
|
92
|
-
def _before_failure
|
93
|
-
@_before_failure ||= []
|
94
|
-
end
|
95
|
-
|
96
|
-
# A callback that runs just prior to the logout of each scope.
|
97
|
-
#
|
98
|
-
# Parameters:
|
99
|
-
# <block> A block to contain logic for the callback
|
100
|
-
# Block Parameters: |user, auth, scope|
|
101
|
-
# user - The authenticated user for the current scope
|
102
|
-
# auth - The warden proxy object
|
103
|
-
# scope - current logout scope
|
104
|
-
#
|
105
|
-
# Example:
|
106
|
-
# Warden::Manager.before_logout do |user, auth, scope|
|
107
|
-
# user.forget_me!
|
108
|
-
# end
|
109
|
-
#
|
110
|
-
# :api: public
|
111
|
-
def before_logout(&block)
|
112
|
-
_before_logout << block
|
113
|
-
end
|
114
|
-
|
115
|
-
# Provides access to the callback array for before_logout
|
116
|
-
# :api: private
|
117
|
-
def _before_logout
|
118
|
-
@_before_logout ||= []
|
119
|
-
end
|
120
|
-
|
121
|
-
end
|
122
|
-
|
123
|
-
end # Manager
|
124
|
-
end # Warden
|
@@ -1,59 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
module Warden
|
3
|
-
module Strategies
|
4
|
-
class << self
|
5
|
-
|
6
|
-
# Adds a strategy to the grab-bag of strategies available to use.
|
7
|
-
# A strategy is a place where you can put logic related to authentication.
|
8
|
-
# A strategy inherits from Warden::Strategies::Base. The _add_ method provides a clean way
|
9
|
-
# to declare your strategies.
|
10
|
-
# You _must_ declare an @authenticate!@ method.
|
11
|
-
# You _may_ provide a @valid?@ method.
|
12
|
-
# The valid method should return true or false depending on if the strategy is a valid one for the request.
|
13
|
-
#
|
14
|
-
# Parameters:
|
15
|
-
# <label: Symbol> The label is the name given to a strategy. Use the label to refer to the strategy when authenticating
|
16
|
-
# <strategy: Class|nil> The optional stragtegy argument if set _must_ be a class that inherits from Warden::Strategies::Base and _must_
|
17
|
-
# implement an @authenticate!@ method
|
18
|
-
# <block> The block acts as a convinient way to declare your strategy. Inside is the class definition of a strategy.
|
19
|
-
#
|
20
|
-
# Examples:
|
21
|
-
#
|
22
|
-
# Block Declared Strategy:
|
23
|
-
# Warden::Strategies.add(:foo) do
|
24
|
-
# def authenticate!
|
25
|
-
# # authentication logic
|
26
|
-
# end
|
27
|
-
# end
|
28
|
-
#
|
29
|
-
# Class Declared Strategy:
|
30
|
-
# Warden::Strategies.add(:foo, MyStrategy)
|
31
|
-
#
|
32
|
-
# :api: public
|
33
|
-
def add(label, strategy = nil, &blk)
|
34
|
-
strategy = strategy.nil? ? Class.new(Warden::Strategies::Base, &blk) : strategy
|
35
|
-
raise NoMethodError, "authenticate! is not declared in the #{label} strategy" if !strategy.method_defined?(:authenticate!)
|
36
|
-
raise "#{label.inspect} is Not a Warden::Strategy::Base" if !strategy.ancestors.include?(Warden::Strategies::Base)
|
37
|
-
_strategies[label] = strategy
|
38
|
-
end
|
39
|
-
|
40
|
-
# Provides access to declared strategies by label
|
41
|
-
# :api: public
|
42
|
-
def [](label)
|
43
|
-
_strategies[label]
|
44
|
-
end
|
45
|
-
|
46
|
-
# Clears all declared middleware.
|
47
|
-
# :api: public
|
48
|
-
def clear!
|
49
|
-
@strategies = {}
|
50
|
-
end
|
51
|
-
|
52
|
-
# :api: private
|
53
|
-
def _strategies
|
54
|
-
@strategies ||= {}
|
55
|
-
end
|
56
|
-
end # << self
|
57
|
-
|
58
|
-
end # Strategies
|
59
|
-
end # Warden
|