Class: StandardId::Passwordless::BaseStrategy

Inherits:
Object
  • Object
show all
Defined in:
lib/standard_id/passwordless/base_strategy.rb

Direct Known Subclasses

EmailStrategy, SmsStrategy

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request) ⇒ BaseStrategy

Returns a new instance of BaseStrategy.



6
7
8
# File 'lib/standard_id/passwordless/base_strategy.rb', line 6

def initialize(request)
  @request = request
end

Instance Attribute Details

#requestObject (readonly)

Returns the value of attribute request.



4
5
6
# File 'lib/standard_id/passwordless/base_strategy.rb', line 4

def request
  @request
end

Instance Method Details

#connection_typeObject

Raises:

  • (NotImplementedError)


10
11
12
# File 'lib/standard_id/passwordless/base_strategy.rb', line 10

def connection_type
  raise NotImplementedError
end

#find_or_create_account(username) ⇒ Object

Public wrapper to reuse account lookup/creation outside OTP verification



59
60
61
62
# File 'lib/standard_id/passwordless/base_strategy.rb', line 59

def (username)
  validate_username!(username)
  find_or_create_account!(username)
end

#identifier_classObject

Raises:

  • (NotImplementedError)


64
65
66
# File 'lib/standard_id/passwordless/base_strategy.rb', line 64

def identifier_class
  raise NotImplementedError
end

#sender_callbackObject



68
69
70
71
# File 'lib/standard_id/passwordless/base_strategy.rb', line 68

def sender_callback
  # Implement in subclasses
  nil
end

#start!(attrs) ⇒ Object

Start flow: validate recipient, create challenge, and trigger sender attrs: { connection:, username: }



16
17
18
19
20
21
22
23
24
25
# File 'lib/standard_id/passwordless/base_strategy.rb', line 16

def start!(attrs)
  username = attrs[:username]
  validate_username!(username)
  emit_code_requested(username)
  challenge = create_challenge!(username)
  emit_code_generated(challenge, username)
  sender_callback&.call(username, challenge.code)
  emit_code_sent(username)
  challenge
end