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.

[View source]

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.


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

def authenticatable
  @authenticatable
end

Class Method Details

.from_message(message) ⇒ Object

[View source]

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

[View source]

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

[View source]

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

def as_json
  options
end

#challengeObject

[View source]

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

def challenge
  @challenge ||= credential.challenge
end

#messageObject

[View source]

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

def message
  self.class.verifier.generate(
    { challenge:, options:,
      authenticatable: authenticatable.as_json(only: %i(email_address webauthn_id)) }.as_json
  )
end

#optionsObject

[View source]

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

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