Class: WebAuthn::AuthenticatorResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/webauthn/authenticator_response.rb

Instance Method Summary collapse

Constructor Details

#initialize(client_data_json:, relying_party: WebAuthn.configuration.relying_party) ⇒ AuthenticatorResponse

Returns a new instance of AuthenticatorResponse.



22
23
24
25
# File 'lib/webauthn/authenticator_response.rb', line 22

def initialize(client_data_json:, relying_party: WebAuthn.configuration.relying_party)
  @client_data_json = client_data_json
  @relying_party = relying_party
end

Instance Method Details

#client_dataObject



56
57
58
# File 'lib/webauthn/authenticator_response.rb', line 56

def client_data
  @client_data ||= WebAuthn::ClientData.new(client_data_json)
end

#valid?(*args, **keyword_arguments) ⇒ Boolean

Returns:

  • (Boolean)


50
51
52
53
54
# File 'lib/webauthn/authenticator_response.rb', line 50

def valid?(*args, **keyword_arguments)
  verify(*args, **keyword_arguments)
rescue WebAuthn::VerificationError
  false
end

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



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/webauthn/authenticator_response.rb', line 27

def verify(expected_challenge, expected_origin = nil, user_presence: nil, user_verification: nil, rp_id: nil)
  expected_origin ||= relying_party.origin || raise("Unspecified expected origin")
  rp_id ||= relying_party.id

  verify_item(:type)
  verify_item(:token_binding)
  verify_item(:challenge, expected_challenge)
  verify_item(:origin, expected_origin)
  verify_item(:authenticator_data)
  verify_item(:rp_id, rp_id || rp_id_from_origin(expected_origin))

  # Fallback to RP configuration unless user_presence is passed in explicitely
  if user_presence.nil? && !relying_party.silent_authentication || user_presence
    verify_item(:user_presence)
  end

  if user_verification
    verify_item(:user_verified)
  end

  true
end