Class: EeIdVerification::AuthenticationSession
- Inherits:
-
Object
- Object
- EeIdVerification::AuthenticationSession
- Defined in:
- lib/ee_id_verification/models.rb
Overview
Authentication session model for Estonian ID card authentication workflow.
This class represents an active authentication session during the two-phase authentication process used by Estonian ID cards. The authentication workflow is designed to be secure and user-friendly:
- Session Creation: When authentication starts, a session is created with a unique ID and initial status of :waiting_for_pin
- PIN Entry: User provides PIN1 which is verified directly on the card
- Session Completion: Upon successful PIN verification, session status changes to :completed and personal data is extracted
The session-based approach provides several benefits:
- Separation of concerns between session management and authentication logic
- Timeout handling to prevent indefinite waiting for PIN entry
- State tracking for complex authentication workflows
- Security through session expiration and cleanup
Session states:
- :waiting_for_pin - Session created, waiting for user PIN input
- :completed - Authentication successful, personal data available
- :failed - Authentication failed (wrong PIN, card error, etc.)
- :expired - Session timed out waiting for PIN entry
Instance Attribute Summary collapse
-
#created_at ⇒ Time
When the session was created.
-
#expires_at ⇒ Time?
When the session expires (nil for no expiration).
-
#id ⇒ String
Unique session identifier (typically UUID).
-
#method ⇒ Symbol
Authentication method used (:digidoc_local).
-
#status ⇒ Symbol
Current session status (:waiting_for_pin, :completed, :failed, :expired).
Instance Method Summary collapse
-
#expired? ⇒ Boolean
Check if the authentication session has expired.
-
#initialize(attributes = {}) ⇒ AuthenticationSession
constructor
Initialize a new authentication session with the provided attributes.
Constructor Details
#initialize(attributes = {}) ⇒ AuthenticationSession
Initialize a new authentication session with the provided attributes.
This constructor uses a flexible attribute assignment approach that allows setting any of the session attributes through a hash. This pattern provides flexibility for different authentication scenarios while maintaining a clean interface.
74 75 76 77 78 79 80 81 |
# File 'lib/ee_id_verification/models.rb', line 74 def initialize(attributes = {}) # Dynamically set attributes using setter methods # This approach ensures only valid attributes are set and leverages # any custom setter logic that might be added in the future attributes.each do |key, value| send("#{key}=", value) if respond_to?("#{key}=") end end |
Instance Attribute Details
#created_at ⇒ Time
53 |
# File 'lib/ee_id_verification/models.rb', line 53 attr_accessor :id, :method, :status, :created_at, :expires_at |
#expires_at ⇒ Time?
53 |
# File 'lib/ee_id_verification/models.rb', line 53 attr_accessor :id, :method, :status, :created_at, :expires_at |
#id ⇒ String
53 54 55 |
# File 'lib/ee_id_verification/models.rb', line 53 def id @id end |
#method ⇒ Symbol
53 |
# File 'lib/ee_id_verification/models.rb', line 53 attr_accessor :id, :method, :status, :created_at, :expires_at |
#status ⇒ Symbol
53 |
# File 'lib/ee_id_verification/models.rb', line 53 attr_accessor :id, :method, :status, :created_at, :expires_at |
Instance Method Details
#expired? ⇒ Boolean
Check if the authentication session has expired.
Sessions expire to prevent security issues from long-lived authentication attempts and to free up system resources. An expired session cannot be used to complete authentication and should be discarded.
The expiration check handles cases where no expiration time is set (nil expires_at means the session never expires automatically).
96 97 98 |
# File 'lib/ee_id_verification/models.rb', line 96 def expired? expires_at && expires_at < Time.now end |