Class: HasSecurePasskey::OptionsForCreate

Inherits:
Object
  • Object
show all
Defined in:
lib/has_secure_passkey/options_for_create.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(authenticatable:, options: nil, challenge: nil) ⇒ OptionsForCreate

Returns a new instance of OptionsForCreate.



14
15
16
17
18
# File 'lib/has_secure_passkey/options_for_create.rb', line 14

def initialize(authenticatable:, options: nil, challenge: nil)
  @authenticatable = authenticatable
  @options = options
  @challenge = challenge
end

Instance Attribute Details

#authenticatableObject (readonly)

Returns the value of attribute authenticatable.



38
39
40
# File 'lib/has_secure_passkey/options_for_create.rb', line 38

def authenticatable
  @authenticatable
end

Class Method Details

.from_message(message) ⇒ Object



7
8
9
10
11
# File 'lib/has_secure_passkey/options_for_create.rb', line 7

def from_message(message)
  new(**verifier.verify(message).symbolize_keys).tap do
    _1.authenticatable.symbolize_keys! if _1.authenticatable.is_a?(Hash)
  end
end

.verifierObject



3
4
5
# File 'lib/has_secure_passkey/options_for_create.rb', line 3

def verifier
  Rails.application.message_verifier("passkey_signup")
end

Instance Method Details

#as_jsonObject



30
31
32
# File 'lib/has_secure_passkey/options_for_create.rb', line 30

def as_json
  options
end

#challengeObject



34
35
36
# File 'lib/has_secure_passkey/options_for_create.rb', line 34

def challenge
  @challenge ||= credential.challenge
end

#messageObject



20
21
22
23
24
# File 'lib/has_secure_passkey/options_for_create.rb', line 20

def message
  self.class.verifier.generate(
    { challenge:, options:, authenticatable: authenticatable.as_json }.as_json
  )
end

#optionsObject



26
27
28
# File 'lib/has_secure_passkey/options_for_create.rb', line 26

def options
  @options ||= { publicKey: credential }
end