Module: Warden::CookieSession

Defined in:
lib/warden/cookie_session.rb,
lib/warden/cookie_session/version.rb,
lib/warden/cookie_session/configuration.rb,
lib/warden/cookie_session/default_wrapper.rb

Defined Under Namespace

Classes: Configuration, DefaultWrapper, EncryptedCookie, Strategy

Constant Summary collapse

VERSION =
'0.1.2'.freeze

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.configObject

Returns the value of attribute config.



12
13
14
# File 'lib/warden/cookie_session.rb', line 12

def config
  @config
end

Class Method Details

.configure {|config| ... } ⇒ Object

Yields:



20
21
22
23
24
# File 'lib/warden/cookie_session.rb', line 20

def configure
  self.config ||= Warden::CookieSession::Configuration.new
  yield(config)
  setup_warden(config)
end

.setup_warden(config) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/warden/cookie_session.rb', line 26

def setup_warden(config)
  Warden::Strategies.add(:cookie_session, Warden::CookieSession::Strategy)

  Warden::Manager.after_set_user do |user, auth, _opts|
    encrypted_cookie = Warden::CookieSession::Strategy.encrypted_cookie(auth.cookies)
    encrypted_cookie.put(config.serialize_record(user), auth.request.domain)
  end

  Warden::Manager.before_logout do |_user, auth, _opts|
    encrypted_cookie = Warden::CookieSession::Strategy.encrypted_cookie(auth.cookies)
    encrypted_cookie.clear(auth.request.domain)
  end
end