Class: EeIdVerification::AuthenticationSession

Inherits:
Object
  • Object
show all
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:

  1. Session Creation: When authentication starts, a session is created with a unique ID and initial status of :waiting_for_pin
  2. PIN Entry: User provides PIN1 which is verified directly on the card
  3. 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

Examples:

Creating and managing a session

session = AuthenticationSession.new(
  id: SecureRandom.uuid,
  method: :digidoc_local,
  status: :waiting_for_pin,
  created_at: Time.now,
  expires_at: Time.now + 300  # 5 minutes
)

# Check if session is still valid
if session.expired?
  puts "Session expired, please try again"
end

Instance Attribute Summary collapse

Instance Method Summary collapse

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.

Examples:

session = AuthenticationSession.new(
  id: "auth-123",
  status: :waiting_for_pin,
  created_at: Time.now
)

Options Hash (attributes):

  • :id (String)

    Unique session identifier

  • :method (Symbol)

    Authentication method

  • :status (Symbol)

    Initial session status

  • :created_at (Time)

    Session creation time

  • :expires_at (Time)

    Session expiration time



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_atTime



53
# File 'lib/ee_id_verification/models.rb', line 53

attr_accessor :id, :method, :status, :created_at, :expires_at

#expires_atTime?



53
# File 'lib/ee_id_verification/models.rb', line 53

attr_accessor :id, :method, :status, :created_at, :expires_at

#idString



53
54
55
# File 'lib/ee_id_verification/models.rb', line 53

def id
  @id
end

#methodSymbol



53
# File 'lib/ee_id_verification/models.rb', line 53

attr_accessor :id, :method, :status, :created_at, :expires_at

#statusSymbol



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).

Examples:

session = AuthenticationSession.new(expires_at: Time.now - 60)
puts "Expired!" if session.expired?


96
97
98
# File 'lib/ee_id_verification/models.rb', line 96

def expired?
  expires_at && expires_at < Time.now
end