Class: EeIdVerification::AuthenticationResult
- Inherits:
-
Object
- Object
- EeIdVerification::AuthenticationResult
- Defined in:
- lib/ee_id_verification/models.rb
Overview
Authentication result model containing the outcome of Estonian ID card authentication.
This class encapsulates all information returned from a completed (or failed) authentication attempt. It provides a comprehensive view of the authentication outcome including:
- Authentication status and success/failure indicators
- Personal information extracted from the ID card certificate
- Error information if authentication failed
- Convenient methods for checking authentication state
The result object serves as the primary interface between the authentication system and consuming applications, providing all necessary information to make authorization decisions and display user information.
Personal data fields match those available in Estonian ID card certificates:
- personal_code: 11-digit Estonian personal identification code
- given_name: User's first/given name(s)
- surname: User's family/last name
- country: Country code (always "EE" for Estonian cards)
Instance Attribute Summary collapse
-
#authenticated ⇒ Boolean
Whether authentication was successful.
-
#country ⇒ String?
Country code from certificate (typically "EE").
-
#error ⇒ String?
Error message if authentication failed.
-
#given_name ⇒ String?
User's first/given name from certificate.
-
#personal_code ⇒ String?
Estonian 11-digit personal identification code.
-
#session_id ⇒ String
ID of the session this result belongs to.
-
#status ⇒ Symbol
Final authentication status (:completed, :failed, etc.).
-
#surname ⇒ String?
User's family/last name from certificate.
Instance Method Summary collapse
-
#authenticated? ⇒ Boolean
Check if the user was successfully authenticated.
-
#failure? ⇒ Boolean
Check if authentication failed or encountered an error.
-
#full_name ⇒ String?
Get the user's full name by combining given name and surname.
-
#initialize(attributes = {}) ⇒ AuthenticationResult
constructor
Initialize a new authentication result with the provided attributes.
-
#success? ⇒ Boolean
Check if authentication was successful and no errors occurred.
Constructor Details
#initialize(attributes = {}) ⇒ AuthenticationResult
Initialize a new authentication result with the provided attributes.
Similar to AuthenticationSession, this uses flexible attribute assignment to allow setting result fields through a hash. The authenticated flag defaults to false to ensure secure defaults - authentication must be explicitly marked as successful.
191 192 193 194 195 196 197 198 199 200 |
# File 'lib/ee_id_verification/models.rb', line 191 def initialize(attributes = {}) # Set provided attributes using dynamic attribute assignment attributes.each do |key, value| send("#{key}=", value) if respond_to?("#{key}=") end # Ensure authenticated defaults to false for security # Authentication must be explicitly set to true to be considered successful @authenticated ||= false end |
Instance Attribute Details
#authenticated ⇒ Boolean
Returns Whether authentication was successful.
167 168 |
# File 'lib/ee_id_verification/models.rb', line 167 attr_accessor :session_id, :status, :authenticated, :error, :personal_code, :given_name, :surname, :country |
#country ⇒ String?
Returns Country code from certificate (typically "EE").
167 168 |
# File 'lib/ee_id_verification/models.rb', line 167 attr_accessor :session_id, :status, :authenticated, :error, :personal_code, :given_name, :surname, :country |
#error ⇒ String?
Returns Error message if authentication failed.
167 168 |
# File 'lib/ee_id_verification/models.rb', line 167 attr_accessor :session_id, :status, :authenticated, :error, :personal_code, :given_name, :surname, :country |
#given_name ⇒ String?
Returns User's first/given name from certificate.
167 168 |
# File 'lib/ee_id_verification/models.rb', line 167 attr_accessor :session_id, :status, :authenticated, :error, :personal_code, :given_name, :surname, :country |
#personal_code ⇒ String?
Returns Estonian 11-digit personal identification code.
167 168 |
# File 'lib/ee_id_verification/models.rb', line 167 attr_accessor :session_id, :status, :authenticated, :error, :personal_code, :given_name, :surname, :country |
#session_id ⇒ String
Returns ID of the session this result belongs to.
167 168 169 |
# File 'lib/ee_id_verification/models.rb', line 167 def session_id @session_id end |
#status ⇒ Symbol
Returns Final authentication status (:completed, :failed, etc.).
167 168 |
# File 'lib/ee_id_verification/models.rb', line 167 attr_accessor :session_id, :status, :authenticated, :error, :personal_code, :given_name, :surname, :country |
#surname ⇒ String?
Returns User's family/last name from certificate.
167 168 |
# File 'lib/ee_id_verification/models.rb', line 167 attr_accessor :session_id, :status, :authenticated, :error, :personal_code, :given_name, :surname, :country |
Instance Method Details
#authenticated? ⇒ Boolean
Check if the user was successfully authenticated.
This is the primary method for determining authentication success. It directly returns the authenticated flag which should only be true if PIN verification succeeded and personal data was extracted.
209 210 211 |
# File 'lib/ee_id_verification/models.rb', line 209 def authenticated? @authenticated end |
#failure? ⇒ Boolean
Check if authentication failed or encountered an error.
This is the inverse of success? and provides a convenient way to check for any kind of authentication failure. Useful for error handling and conditional logic in authentication flows.
238 239 240 |
# File 'lib/ee_id_verification/models.rb', line 238 def failure? !success? end |
#full_name ⇒ String?
Get the user's full name by combining given name and surname.
Estonian ID certificates store names in separate fields (given name and surname) following international X.509 certificate standards. This method provides a convenient way to get the complete name for display purposes.
The method handles various edge cases:
- Missing given name or surname (returns partial name)
- Both names missing (returns nil)
- Extra whitespace (cleaned up by join)
262 263 264 265 266 267 268 269 |
# File 'lib/ee_id_verification/models.rb', line 262 def full_name # Return nil if neither name component is available return nil unless given_name || surname # Combine available name components, filtering out nil values # compact removes nil values, join combines with space [given_name, surname].compact.join(" ") end |
#success? ⇒ Boolean
Check if authentication was successful and no errors occurred.
This method provides a more comprehensive success check than authenticated? by also ensuring no error occurred during the process. This catches cases where authentication might be marked as successful but an error was encountered during personal data extraction.
227 228 229 |
# File 'lib/ee_id_verification/models.rb', line 227 def success? authenticated? && !error end |