Class: Warden::Manager
- Inherits:
-
Object
- Object
- Warden::Manager
- Extended by:
- Hooks, ManagerDeprecation
- Defined in:
- lib/warden/manager.rb
Overview
The middleware for Rack Authentication The middlware requires that there is a session upstream The middleware injects an authentication object into the rack environment hash
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
Class Method Summary collapse
-
.serialize_from_session(&block) ⇒ Object
Reconstitues the user from the session.
-
.serialize_into_session(&block) ⇒ Object
Prepares the user to serialize into the session.
Instance Method Summary collapse
-
#_run_callbacks(*args) ⇒ Object
:api: private.
-
#call(env) ⇒ Object
Invoke the application guarding for throw :warden.
-
#initialize(app, options = {}) {|@config| ... } ⇒ Manager
constructor
Initialize the middleware.
Methods included from Hooks
_after_set_user, _before_failure, _before_logout, _on_request, after_authentication, after_fetch, after_set_user, before_failure, before_logout, on_request
Methods included from ManagerDeprecation
default_scope, default_scope=, serializers
Constructor Details
#initialize(app, options = {}) {|@config| ... } ⇒ Manager
Initialize the middleware. If a block is given, a Warden::Config is yielded so you can properly configure the Warden::Manager. :api: public
20 21 22 23 24 |
# File 'lib/warden/manager.rb', line 20 def initialize(app, ={}) @app, @config = app, Warden::Config.new() yield @config if block_given? self end |
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
15 16 17 |
# File 'lib/warden/manager.rb', line 15 def config @config end |
Class Method Details
.serialize_from_session(&block) ⇒ Object
77 78 79 |
# File 'lib/warden/manager.rb', line 77 def serialize_from_session(&block) Warden::SessionSerializer.send :define_method, :deserialize, &block end |
.serialize_into_session(&block) ⇒ Object
Prepares the user to serialize into the session. Any object that can be serialized into the session in some way can be used as a “user” object Generally however complex object should not be stored in the session. If possible store only a “key” of the user object that will allow you to reconstitute it.
Example:
Warden::Manager.serialize_into_session{ |user| user.id }
:api: public
66 67 68 |
# File 'lib/warden/manager.rb', line 66 def serialize_into_session(&block) Warden::SessionSerializer.send :define_method, :serialize, &block end |
Instance Method Details
#_run_callbacks(*args) ⇒ Object
:api: private
52 53 54 |
# File 'lib/warden/manager.rb', line 52 def _run_callbacks(*args) #:nodoc: self.class._run_callbacks(*args) end |
#call(env) ⇒ Object
Invoke the application guarding for throw :warden. If this is downstream from another warden instance, don’t do anything. :api: private
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/warden/manager.rb', line 29 def call(env) # :nodoc: return @app.call(env) unless env['warden'].nil? env['warden'] = Proxy.new(env, self) result = catch(:warden) do @app.call(env) end result ||= {} case result when Array if result.first == 401 process_unauthenticated({:original_response => result, :action => :unauthenticated}, env) else result end when Hash result[:action] ||= :unauthenticated process_unauthenticated(result, env) end end |