Class: Warden::Strategies::Base
- Inherits:
-
Object
- Object
- Warden::Strategies::Base
- Includes:
- Mixins::Common
- Defined in:
- lib/warden/authentication/strategy_base.rb
Instance Attribute Summary collapse
-
#_status ⇒ Object
readonly
Setup for redirection :api: private.
-
#custom_response ⇒ Object
:api: private.
-
#env ⇒ Object
readonly
Accessor for the rack env :api: public.
-
#message ⇒ Object
:api: public.
-
#result ⇒ Object
:api: private.
-
#scope ⇒ Object
readonly
Accessor for the rack env :api: public.
-
#user ⇒ Object
:api: public.
Instance Method Summary collapse
-
#_run! ⇒ Object
The method that is called from above.
-
#custom!(response) ⇒ Object
Return a custom rack array.
-
#errors ⇒ Object
Access to the errors object.
-
#fail!(message = "Failed to Login") ⇒ Object
This causes the strategy to fail.
-
#halt! ⇒ Object
Cause the processing of the strategies to stop and cascade no further :api: public.
-
#halted? ⇒ Boolean
Checks to see if a strategy was halted :api: public.
-
#headers(header = {}) ⇒ Object
Provides access to the headers hash for setting custom headers :api: public.
-
#initialize(env, scope = nil, config = {}) ⇒ Base
constructor
:api: private.
-
#pass ⇒ Object
A simple method to return from authenticate! if you want to ignore this strategy :api: public.
-
#redirect!(url, params = {}, opts = {}) ⇒ Object
Causes the authentication to redirect.
-
#success!(user) ⇒ Object
Whenever you want to provide a user object as “authenticated” use the
success!
method. -
#valid? ⇒ Boolean
Acts as a guarding method for the strategy.
Methods included from Mixins::Common
#params, #request, #reset_session!, #session
Constructor Details
#initialize(env, scope = nil, config = {}) ⇒ Base
:api: private
21 22 23 24 25 |
# File 'lib/warden/authentication/strategy_base.rb', line 21 def initialize(env, scope=nil, config={}) # :nodoc: @scope, @config = scope, config @env, @_status, @headers = env, nil, {} @halted = false end |
Instance Attribute Details
#_status ⇒ Object (readonly)
Setup for redirection :api: private
13 14 15 |
# File 'lib/warden/authentication/strategy_base.rb', line 13 def _status @_status end |
#custom_response ⇒ Object
:api: private
9 10 11 |
# File 'lib/warden/authentication/strategy_base.rb', line 9 def custom_response @custom_response end |
#env ⇒ Object (readonly)
Accessor for the rack env :api: public
17 18 19 |
# File 'lib/warden/authentication/strategy_base.rb', line 17 def env @env end |
#message ⇒ Object
:api: public
6 7 8 |
# File 'lib/warden/authentication/strategy_base.rb', line 6 def @message end |
#result ⇒ Object
:api: private
9 10 11 |
# File 'lib/warden/authentication/strategy_base.rb', line 9 def result @result end |
#scope ⇒ Object (readonly)
Accessor for the rack env :api: public
17 18 19 |
# File 'lib/warden/authentication/strategy_base.rb', line 17 def scope @scope end |
#user ⇒ Object
:api: public
6 7 8 |
# File 'lib/warden/authentication/strategy_base.rb', line 6 def user @user end |
Instance Method Details
#_run! ⇒ Object
The method that is called from above. This method calls the underlying authenticate! method :api: private
29 30 31 32 |
# File 'lib/warden/authentication/strategy_base.rb', line 29 def _run! # :nodoc: result = authenticate! self end |
#custom!(response) ⇒ Object
Return a custom rack array. You must throw an :warden symbol to activate this :api: public
118 119 120 121 122 |
# File 'lib/warden/authentication/strategy_base.rb', line 118 def custom!(response) halt! @custom_response = response @result = :custom end |
#errors ⇒ Object
Access to the errors object. :api: public
50 51 52 |
# File 'lib/warden/authentication/strategy_base.rb', line 50 def errors @env['warden.errors'] end |
#fail!(message = "Failed to Login") ⇒ Object
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 :api: public
87 88 89 90 91 |
# File 'lib/warden/authentication/strategy_base.rb', line 87 def fail!( = "Failed to Login") halt! @message = @result = :failure end |
#halt! ⇒ Object
Cause the processing of the strategies to stop and cascade no further :api: public
56 57 58 |
# File 'lib/warden/authentication/strategy_base.rb', line 56 def halt! @halted = true end |
#halted? ⇒ Boolean
Checks to see if a strategy was halted :api: public
62 63 64 |
# File 'lib/warden/authentication/strategy_base.rb', line 62 def halted? !!@halted end |
#headers(header = {}) ⇒ Object
Provides access to the headers hash for setting custom headers :api: public
42 43 44 45 46 |
# File 'lib/warden/authentication/strategy_base.rb', line 42 def headers(header = {}) @headers ||= {} @headers.merge! header @headers end |
#pass ⇒ Object
A simple method to return from authenticate! if you want to ignore this strategy :api: public
68 |
# File 'lib/warden/authentication/strategy_base.rb', line 68 def pass; end |
#redirect!(url, params = {}, opts = {}) ⇒ Object
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
102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/warden/authentication/strategy_base.rb', line 102 def redirect!(url, params = {}, opts = {}) halt! @_status = opts[:permanent] ? 301 : 302 headers["Location"] = url headers["Location"] << "?" << Rack::Utils.build_query(params) unless params.empty? headers["Content-Type"] = opts[:content_type] || 'text/plain' @message = opts[:message].nil? ? "You are being redirected to #{headers["Location"]}" : opts[:message] @result = :redirect headers["Location"] end |
#success!(user) ⇒ Object
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
78 79 80 81 82 |
# File 'lib/warden/authentication/strategy_base.rb', line 78 def success!(user) halt! @user = user @result = :success end |
#valid? ⇒ Boolean
Acts as a guarding method for the strategy. If #valid? responds false, the strategy will not be executed Overwrite with your own logic :api: overwritable
38 |
# File 'lib/warden/authentication/strategy_base.rb', line 38 def valid?; true; end |