Class: StandardId::Passwordless::BaseStrategy
- Inherits:
-
Object
- Object
- StandardId::Passwordless::BaseStrategy
- Defined in:
- lib/standard_id/passwordless/base_strategy.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#request ⇒ Object
readonly
Returns the value of attribute request.
Instance Method Summary collapse
- #connection_type ⇒ Object
-
#find_account(username) ⇒ Object
Public wrapper to look up an existing account without creating one.
-
#find_or_create_account(username) ⇒ Object
Public wrapper to reuse account lookup/creation outside OTP verification.
- #identifier_class ⇒ Object
-
#initialize(request) ⇒ BaseStrategy
constructor
A new instance of BaseStrategy.
- #sender_callback ⇒ Object
-
#start!(attrs) ⇒ Object
Start flow: validate recipient, create challenge, and trigger sender attrs: { connection:, username: }.
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
#request ⇒ Object (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_type ⇒ Object
10 11 12 |
# File 'lib/standard_id/passwordless/base_strategy.rb', line 10 def connection_type raise NotImplementedError end |
#find_account(username) ⇒ Object
Public wrapper to look up an existing account without creating one. Returns nil if no account is found for the given username.
97 98 99 100 |
# File 'lib/standard_id/passwordless/base_strategy.rb', line 97 def find_account(username) validate_username!(username) find_existing_account(username) end |
#find_or_create_account(username) ⇒ Object
Public wrapper to reuse account lookup/creation outside OTP verification. When a custom account_factory is configured, delegates to it instead of the built-in find_or_create_account! logic.
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/standard_id/passwordless/base_strategy.rb', line 78 def find_or_create_account(username) validate_username!(username) factory = StandardId.config.passwordless.account_factory if factory.respond_to?(:call) account = factory.call( identifier: username, params: request_params, request: request ) raise StandardId::InvalidRequestError, "account_factory must return an account" unless account.present? account else find_or_create_account!(username) end end |
#identifier_class ⇒ Object
102 103 104 |
# File 'lib/standard_id/passwordless/base_strategy.rb', line 102 def identifier_class raise NotImplementedError end |
#sender_callback ⇒ Object
106 107 108 109 |
# File 'lib/standard_id/passwordless/base_strategy.rb', line 106 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 26 |
# File 'lib/standard_id/passwordless/base_strategy.rb', line 16 def start!(attrs) username = attrs[:username] validate_username!(username) run_username_validator!(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 |