Class | Warden::Strategies::Base |
In: |
lib/warden/strategies/base.rb
|
Parent: | Object |
A strategy is a place where you can put logic related to authentication. Any strategy inherits from Warden::Strategies::Base.
The Warden::Strategies.add method is a simple way to provide custom 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.
The parameters for Warden::Strategies.add method is:
<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)
custom_response | [RW] | :api: private |
env | [R] | :api: public |
message | [RW] | :api: public |
result | [RW] | :api: private |
scope | [R] | :api: public |
status | [R] | :api: public |
user | [RW] | :api: public |
This causes the strategy to fail. It does not throw an :warden symbol to drop the request out to the failure application You must throw an :warden symbol somewhere in the application to enforce this Halts the strategies so that this is the last strategy checked :api: public
Causes the authentication to redirect. An :warden symbol must be thrown to actually execute this redirect
Parameters:
url <String> - The string representing the URL to be redirected to pararms <Hash> - Any parameters to encode into the URL opts <Hash> - Any options to recirect with. available options: permanent => (true || false)
:api: public
Whenever you want to provide a user object as "authenticated" use the +success!+ method. This will halt the strategy, and set the user in the approprieate scope. It is the "login" method
Parameters:
user - The user object to login. This object can be anything you have setup to serialize in and out of the session
:api: public