Module: Warden::Strategies
- Defined in:
- lib/warden/authentication/strategies.rb,
lib/warden/authentication/strategy_base.rb
Defined Under Namespace
Classes: Base
Class Method Summary collapse
-
.[](label) ⇒ Object
Provides access to declared strategies by label :api: public.
-
._strategies ⇒ Object
:api: private.
-
.add(label, strategy = nil, &blk) ⇒ Object
Adds a strategy to the grab-bag of strategies available to use.
-
.clear! ⇒ Object
Clears all declared middleware.
Class Method Details
.[](label) ⇒ Object
Provides access to declared strategies by label :api: public
42 43 44 |
# File 'lib/warden/authentication/strategies.rb', line 42 def [](label) _strategies[label] end |
._strategies ⇒ Object
:api: private
53 54 55 |
# File 'lib/warden/authentication/strategies.rb', line 53 def _strategies @strategies ||= {} end |
.add(label, strategy = nil, &blk) ⇒ Object
Adds a strategy to the grab-bag of strategies available to use. A strategy is a place where you can put logic related to authentication. A strategy inherits from Warden::Strategies::Base. The add method provides a clean way to declare your strategies.
You must declare an @authenticate!@ method. You may provide a @valid?@ method. The valid method should return true or false depending on if the strategy is a valid one for the request.
Parameters:
<label: Symbol> The label is the name given to a strategy. Use the label to refer to the strategy when authenticating
<strategy: Class|nil> The optional stragtegy argument if set _must_ be a class that inherits from Warden::Strategies::Base and _must_
implement an @authenticate!@ method
<block> The block acts as a convinient way to declare your strategy. Inside is the class definition of a strategy.
Examples:
Block Declared Strategy:
Warden::Strategies.add(:foo) do
def authenticate!
# authentication logic
end
end
Class Declared Strategy:
Warden::Strategies.add(:foo, MyStrategy)
:api: public
33 34 35 36 37 38 |
# File 'lib/warden/authentication/strategies.rb', line 33 def add(label, strategy = nil, &blk) strategy = strategy.nil? ? Class.new(Warden::Strategies::Base, &blk) : strategy raise NoMethodError, "authenticate! is not declared in the #{label} strategy" if !strategy.method_defined?(:authenticate!) raise "#{label.inspect} is Not a Warden::Strategy::Base" if !strategy.ancestors.include?(Warden::Strategies::Base) _strategies[label] = strategy end |
.clear! ⇒ Object
Clears all declared middleware. :api: public
48 49 50 |
# File 'lib/warden/authentication/strategies.rb', line 48 def clear! @strategies = {} end |