Class: Keycard::Authentication::Result

Inherits:
Object
  • Object
show all
Defined in:
lib/keycard/authentication/result.rb

Overview

A Result is the central point of information about an authentication attempt. It logs the authentication methods attempted with their statuses and reports the overall status. When authentication is successful, it holds the user/account that was verified.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeResult



13
14
15
16
17
18
# File 'lib/keycard/authentication/result.rb', line 13

def initialize
  @account = nil
  @log = []
  @failed = false
  @csrf_safe = false
end

Instance Attribute Details

#accountObject (readonly)

Returns the value of attribute account.



10
11
12
# File 'lib/keycard/authentication/result.rb', line 10

def 
  @account
end

#logObject (readonly)

Returns the value of attribute log.



11
12
13
# File 'lib/keycard/authentication/result.rb', line 11

def log
  @log
end

Instance Method Details

#authenticated?Boolean

Has this authentication completed successfully?



21
22
23
# File 'lib/keycard/authentication/result.rb', line 21

def authenticated?
  !.nil?
end

#csrf_safe?Boolean

Does a completed verification protect from Cross-Site Request Forgery?

This should be true in cases where the client presents authentication that is not automatic, like an authentication token, rather than automatic credentials like cookies or proxy-applied headers.



35
36
37
# File 'lib/keycard/authentication/result.rb', line 35

def csrf_safe?
  @csrf_safe
end

#failed(message) ⇒ Boolean

Log that the authentication method failed; terminate the chain.



52
53
54
55
# File 'lib/keycard/authentication/result.rb', line 52

def failed(message)
  log << "[FAILURE] #{message}"
  @failed = true
end

#failed?Boolean

Was there a failure for an attempted authentication method?



26
27
28
# File 'lib/keycard/authentication/result.rb', line 26

def failed?
  @failed
end

#skipped(message) ⇒ Boolean

Log that the authentication method was not applicable; continue the chain.



43
44
45
46
# File 'lib/keycard/authentication/result.rb', line 43

def skipped(message)
  log << "[SKIPPED] #{message}"
  false
end

#succeeded(account, message, csrf_safe: false) ⇒ Boolean

Log that the authentication method succeeded; terminate the chain.



64
65
66
67
68
69
# File 'lib/keycard/authentication/result.rb', line 64

def succeeded(, message, csrf_safe: false)
  @account = 
  @csrf_safe ||= csrf_safe
  log << "[SUCCESS] #{message}"
  true
end