class Warden::Strategies::Base


Warden::Strategies.add(:foo, MyStrategy)
Class Declared Strategy:
end
end
# authentication logic
def authenticate!
Warden::Strategies.add(:foo) do
Block Declared Strategy:
Examples:
<block> The block acts as a convenient way to declare your strategy. Inside is the class definition of a strategy.
implement an @authenticate!@ method
<strategy: Class|nil> The optional strategy argument if set must be a class that inherits from Warden::Strategies::Base and must
<label: Symbol> The label is the name given to a strategy. Use the label to refer to the strategy when authenticating
The parameters for Warden::Strategies.add method are:
The valid method should return true or false depending on if the strategy is a valid one for the request.
You may provide a @valid?@ method.
You must declare an @authenticate!@ method.
The Warden::Strategies.add method is a simple way to provide custom strategies.
from Warden::Strategies::Base.
A strategy is a place where you can put logic related to authentication. Any strategy inherits

def _run! # :nodoc:

:nodoc:
:api: private
The method that is called from above. This method calls the underlying authenticate! method
def _run! # :nodoc:
  @performed = true
  authenticate!
  self
end

def clear!

:api: private
Marks this strategy as not performed.
def clear!
  @performed = false
end

def custom!(response)

:api: public
Return a custom rack array. You must throw an :warden symbol to activate this
def custom!(response)
  halt!
  @custom_response = response
  @result = :custom
end

def errors

:api: public
Access to the errors object.
def errors
  @env['warden'].errors
end

def fail(message = "Failed to Login")

:api: public
Causes the strategy to fail, but not halt. The strategies will cascade after this failure and warden will check the next strategy. The last strategy to fail will have it's message displayed.
def fail(message = "Failed to Login")
  @message = message
  @result = :failure
end

def fail!(message = "Failed to Login")

:api: public
Halts the strategies so that this is the last strategy checked
You must throw an :warden symbol somewhere in the application to enforce this
This causes the strategy to fail. It does not throw an :warden symbol to drop the request out to the failure application
def fail!(message = "Failed to Login")
  halt!
  @message = message
  @result = :failure
end

def halt!

:api: public
Cause the processing of the strategies to stop and cascade no further
def halt!
  @halted = true
end

def halted?

:api: public
Checks to see if a strategy was halted
def halted?
  !!@halted
end

def headers(header = {})

:api: public
Provides access to the headers hash for setting custom headers
def headers(header = {})
  @headers ||= {}
  @headers.merge! header
  @headers
end

def initialize(env, scope=nil) # :nodoc:

:nodoc:
:api: private
def initialize(env, scope=nil) # :nodoc:
  @env, @scope = env, scope
  @status, @headers = nil, {}
  @halted, @performed = false, false
  @result = nil
end

def pass; end

:api: public
A simple method to return from authenticate! if you want to ignore this strategy
def pass; end

def performed? #:nodoc:

:nodoc:
:api: private
Returns if this strategy was already performed.
def performed? #:nodoc:
  @performed
end

def redirect!(url, params = {}, opts = {})

:api: public

available options: permanent => (true || false)
opts - Any options to redirect with.
params - Any parameters to encode into the URL
url - The string representing the URL to be redirected to
Parameters:

Causes the authentication to redirect. An :warden symbol must be thrown to actually execute this redirect
def redirect!(url, params = {}, opts = {})
  halt!
  @status = opts[:permanent] ? 301 : 302
  headers["Location"] = url.dup
  headers["Location"] << "?" << Rack::Utils.build_query(params) unless params.empty?
  headers["Content-Type"] = opts[:content_type] || 'text/plain'
  @message = opts[:message] || "You are being redirected to #{headers["Location"]}"
  @result = :redirect
  headers["Location"]
end

def store?

:api: public
Checks to see if a strategy should result in a permanent login
def store?
  true
end

def success!(user, message = nil)

:api: public

user - The user object to login. This object can be anything you have setup to serialize in and out of the session
Parameters:

It is the "login" method
This will halt the strategy, and set the user in the appropriate scope.
Whenever you want to provide a user object as "authenticated" use the +success!+ method.
def success!(user, message = nil)
  halt!
  @user = user
  @message = message
  @result = :success
end

def successful?

Returns true only if the result is a success and a user was assigned.
def successful?
  @result == :success && !user.nil?
end

def valid?; true; end

:api: overwritable
Overwrite with your own logic
If #valid? responds false, the strategy will not be executed
Acts as a guarding method for the strategy.
def valid?; true; end