Class: Warden::CookieSession::Strategy

Inherits:
Strategies::Base
  • Object
show all
Defined in:
lib/warden/cookie_session/strategy.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details



28
29
30
31
32
33
34
# File 'lib/warden/cookie_session/strategy.rb', line 28

def self.encrypted_cookie(cookies)
  Warden::CookieSession::EncryptedCookie.new(
    store:  cookies,
    cookie: Warden::CookieSession.config.cookie,
    secret: Warden::CookieSession.config.secret
  )
end

Instance Method Details

#authenticate!Object



17
18
19
20
21
22
23
24
25
26
# File 'lib/warden/cookie_session/strategy.rb', line 17

def authenticate!
  key, salt = @key_salt || encrypted_cookie.get
  record = Warden::CookieSession.config.fetch_record(key)

  success!(record) if record && Warden::CookieSession.config.validate_record(record, salt)
rescue StandardError => e
  logger.warn "Warden::CookieSession::Strategy failed: #{e}"
  fail!(e)
  logger.debug { e.backtrace }
end


36
37
38
# File 'lib/warden/cookie_session/strategy.rb', line 36

def encrypted_cookie
  @encrypted_cookie ||= Warden::CookieSession::Strategy.encrypted_cookie(cookies)
end

#store?Boolean

Returns:

  • (Boolean)


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

def store?
  false
end

#valid?Boolean

Returns:

  • (Boolean)


5
6
7
8
9
10
11
# File 'lib/warden/cookie_session/strategy.rb', line 5

def valid?
  @key_salt = cookies[Warden::CookieSession.config.cookie] && encrypted_cookie.get.presence
rescue StandardError => e
  logger.warn "Warden::CookieSession::Strategy#valid? failed: #{e}"
  logger.debug { e.backtrace }
  false
end