class Authlogic::ControllerAdapters::RackAdapter
Adapter for authlogic to make it function as a Rack middleware. First you'll have write your own Rack adapter where you have to set your cookie domain.
class YourRackAdapter < Authlogic::ControllerAdapters::RackAdapter def cookie_domain 'your_cookie_domain_here.com' end end
Next you need to set up a rack middleware like this:
class AuthlogicMiddleware def initialize(app) @app = app end def call(env) YourRackAdapter.new(env) @app.call(env) end end
And that is all! Now just load this middleware into rack:
use AuthlogicMiddleware
Authlogic will expect a User and a UserSession object to be present:
class UserSession < Authlogic::Session::Base # Authlogic options go here end class User < ActiveRecord::Base acts_as_authentic end
Public Class Methods
new(env)
click to toggle source
Calls superclass method
Authlogic::ControllerAdapters::AbstractAdapter.new
# File lib/authlogic/controller_adapters/rack_adapter.rb, line 41 def initialize(env) # We use the Rack::Request object as the controller object. # For this to work, we have to add some glue. request = Rack::Request.new(env) request.instance_eval do def request; self; end def remote_ip; self.ip; end end super(request) Authlogic::Session::Base.controller = self end
Public Instance Methods
remote_ip()
click to toggle source
# File lib/authlogic/controller_adapters/rack_adapter.rb, line 48 def remote_ip; self.ip; end
request()
click to toggle source
# File lib/authlogic/controller_adapters/rack_adapter.rb, line 47 def request; self; end