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.
-
#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, 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
Constructor Details
#initialize(env, config = {}) ⇒ Base
:api: private
20 21 22 23 24 |
# File 'lib/warden/authentication/strategy_base.rb', line 20 def initialize(env, config = {}) # :nodoc: @config = config @env, @_status, @headers = env, nil, {} @halted = false end |
Instance Attribute Details
#_status ⇒ Object (readonly)
Setup for redirection :api: private
12 13 14 |
# File 'lib/warden/authentication/strategy_base.rb', line 12 def _status @_status end |
#custom_response ⇒ Object
:api: private
8 9 10 |
# File 'lib/warden/authentication/strategy_base.rb', line 8 def custom_response @custom_response end |
#env ⇒ Object (readonly)
Accessor for the rack env :api: public
16 17 18 |
# File 'lib/warden/authentication/strategy_base.rb', line 16 def env @env end |
#message ⇒ Object
:api: public
5 6 7 |
# File 'lib/warden/authentication/strategy_base.rb', line 5 def @message end |
#result ⇒ Object
:api: private
8 9 10 |
# File 'lib/warden/authentication/strategy_base.rb', line 8 def result @result end |
#user ⇒ Object
:api: public
5 6 7 |
# File 'lib/warden/authentication/strategy_base.rb', line 5 def user @user end |
Instance Method Details
#_run! ⇒ Object
The method that is called from above. This method calls the underlying authetniate! method :api: private
28 29 30 31 |
# File 'lib/warden/authentication/strategy_base.rb', line 28 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
116 117 118 119 120 |
# File 'lib/warden/authentication/strategy_base.rb', line 116 def custom!(response) halt! @custom_response = response @result = :custom end |
#errors ⇒ Object
Access to the errors object. :api: public
49 50 51 |
# File 'lib/warden/authentication/strategy_base.rb', line 49 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
86 87 88 89 90 |
# File 'lib/warden/authentication/strategy_base.rb', line 86 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
55 56 57 |
# File 'lib/warden/authentication/strategy_base.rb', line 55 def halt! @halted = true end |
#halted? ⇒ Boolean
Checks to see if a strategy was halted :api: public
61 62 63 |
# File 'lib/warden/authentication/strategy_base.rb', line 61 def halted? !!@halted end |
#headers(header = {}) ⇒ Object
Provides access to the headers hash for setting custom headers :api: public
41 42 43 44 45 |
# File 'lib/warden/authentication/strategy_base.rb', line 41 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
67 |
# File 'lib/warden/authentication/strategy_base.rb', line 67 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
101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/warden/authentication/strategy_base.rb', line 101 def redirect!(url, params = {}, opts = {}) halt! @_status = opts[:permanent] ? 301 : 302 headers["Location"] = url headers["Location"] << "?" << Rack::Utils.build_query(params) unless params.empty? @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
77 78 79 80 81 |
# File 'lib/warden/authentication/strategy_base.rb', line 77 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
37 |
# File 'lib/warden/authentication/strategy_base.rb', line 37 def valid?; true; end |