Class: Junkfood::Rack::TransientSession
- Inherits:
-
Object
- Object
- Junkfood::Rack::TransientSession
- Defined in:
- lib/junkfood/rack/sessions.rb
Overview
Rack Middleware that sets the ‘rack.session’ environment variable with a new Hash object.
This is specifically useful for when an application, or other middleware, assumes that a rack session is set yet the developer doesn’t want to save an actual Cookie or Database session.
For example, one may want to use API tokens for authentication in a rack application protected by ‘warden`. Each request requires the API token for each call and we don’t want the authenticated user to be saved in a Cookie session.
Simply:
use Junkfood::Rack::TransientSession
use Warden::Manager do |manager|
manager.default_strategies :web_api_access_token
manager.failure_app = Junkfood::WebApi::UnauthenticatedHandler.new
end
use Junkfood::WebApi::AccessTokenAuthentication
Instance Method Summary collapse
-
#call(env) ⇒ Object
A Rack response from the application.
-
#initialize(app) ⇒ TransientSession
constructor
A new instance of TransientSession.
Constructor Details
#initialize(app) ⇒ TransientSession
Returns a new instance of TransientSession.
46 47 48 |
# File 'lib/junkfood/rack/sessions.rb', line 46 def initialize(app) @app = app end |
Instance Method Details
#call(env) ⇒ Object
Returns a Rack response from the application.
54 55 56 57 58 |
# File 'lib/junkfood/rack/sessions.rb', line 54 def call(env) new_env = env.dup new_env['rack.session'] = {} @app.call(new_env) end |