Class: WebAuthn::AuthenticatorAssertionResponse

Inherits:
AuthenticatorResponse show all
Defined in:
lib/webauthn/authenticator_assertion_response.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from AuthenticatorResponse

#client_data, #valid?

Constructor Details

#initialize(authenticator_data:, signature:, user_handle: nil, **options) ⇒ AuthenticatorAssertionResponse

Returns a new instance of AuthenticatorAssertionResponse.


31
32
33
34
35
36
37
# File 'lib/webauthn/authenticator_assertion_response.rb', line 31

def initialize(authenticator_data:, signature:, user_handle: nil, **options)
  super(**options)

  @authenticator_data_bytes = authenticator_data
  @signature = signature
  @user_handle = user_handle
end

Instance Attribute Details

#user_handleObject (readonly)

Returns the value of attribute user_handle


29
30
31
# File 'lib/webauthn/authenticator_assertion_response.rb', line 29

def user_handle
  @user_handle
end

Class Method Details

.from_client(response) ⇒ Object


13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/webauthn/authenticator_assertion_response.rb', line 13

def self.from_client(response)
  encoder = WebAuthn.configuration.encoder

  user_handle =
    if response["userHandle"]
      encoder.decode(response["userHandle"])
    end

  new(
    authenticator_data: encoder.decode(response["authenticatorData"]),
    client_data_json: encoder.decode(response["clientDataJSON"]),
    signature: encoder.decode(response["signature"]),
    user_handle: user_handle
  )
end

Instance Method Details

#authenticator_dataObject


47
48
49
# File 'lib/webauthn/authenticator_assertion_response.rb', line 47

def authenticator_data
  @authenticator_data ||= WebAuthn::AuthenticatorData.deserialize(authenticator_data_bytes)
end

#verify(expected_challenge, expected_origin = nil, public_key:, sign_count:, user_verification: nil, rp_id: nil) ⇒ Object


39
40
41
42
43
44
45
# File 'lib/webauthn/authenticator_assertion_response.rb', line 39

def verify(expected_challenge, expected_origin = nil, public_key:, sign_count:, user_verification: nil, rp_id: nil)
  super(expected_challenge, expected_origin, user_verification: user_verification, rp_id: rp_id)
  verify_item(:signature, WebAuthn::PublicKey.deserialize(public_key))
  verify_item(:sign_count, sign_count)

  true
end