Class: Keycard::Authentication::Result
- Inherits:
-
Object
- Object
- Keycard::Authentication::Result
- 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
-
#account ⇒ Object
readonly
Returns the value of attribute account.
-
#log ⇒ Object
readonly
Returns the value of attribute log.
Instance Method Summary collapse
-
#authenticated? ⇒ Boolean
Has this authentication completed successfully?.
-
#csrf_safe? ⇒ Boolean
Does a completed verification protect from Cross-Site Request Forgery?.
-
#failed(message) ⇒ Boolean
Log that the authentication method failed; terminate the chain.
-
#failed? ⇒ Boolean
Was there a failure for an attempted authentication method?.
-
#initialize ⇒ Result
constructor
A new instance of Result.
-
#skipped(message) ⇒ Boolean
Log that the authentication method was not applicable; continue the chain.
-
#succeeded(account, message, csrf_safe: false) ⇒ Boolean
Log that the authentication method succeeded; terminate the chain.
Constructor Details
#initialize ⇒ Result
Returns a new instance of Result.
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
#account ⇒ Object (readonly)
Returns the value of attribute account.
10 11 12 |
# File 'lib/keycard/authentication/result.rb', line 10 def account @account end |
#log ⇒ Object (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? !account.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() log << "[FAILURE] #{}" @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() log << "[SKIPPED] #{}" 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(account, , csrf_safe: false) @account = account @csrf_safe ||= csrf_safe log << "[SUCCESS] #{}" true end |