class WebAuthn::PublicKeyCredential

Attributes

client_extension_outputs[R]
id[R]
raw_id[R]
response[R]
type[R]

Public Class Methods

from_client(credential) click to toggle source
# File lib/webauthn/public_key_credential.rb, line 9
def self.from_client(credential)
  new(
    type: credential["type"],
    id: credential["id"],
    raw_id: WebAuthn.configuration.encoder.decode(credential["rawId"]),
    client_extension_outputs: credential["clientExtensionResults"],
    response: response_class.from_client(credential["response"])
  )
end
new(type:, id:, raw_id:, client_extension_outputs: {}, response:) click to toggle source
# File lib/webauthn/public_key_credential.rb, line 19
def initialize(type:, id:, raw_id:, client_extension_outputs: {}, response:)
  @type = type
  @id = id
  @raw_id = raw_id
  @client_extension_outputs = client_extension_outputs
  @response = response
end

Public Instance Methods

authenticator_extension_outputs() click to toggle source
# File lib/webauthn/public_key_credential.rb, line 38
def authenticator_extension_outputs
  authenticator_data.extension_data if authenticator_data&.extension_data_included?
end
sign_count() click to toggle source
# File lib/webauthn/public_key_credential.rb, line 34
def sign_count
  authenticator_data&.sign_count
end
verify(*_args) click to toggle source
# File lib/webauthn/public_key_credential.rb, line 27
def verify(*_args)
  valid_type? || raise("invalid type")
  valid_id? || raise("invalid id")

  true
end

Private Instance Methods

authenticator_data() click to toggle source
# File lib/webauthn/public_key_credential.rb, line 52
def authenticator_data
  response&.authenticator_data
end
encoder() click to toggle source
# File lib/webauthn/public_key_credential.rb, line 56
def encoder
  WebAuthn.configuration.encoder
end
valid_id?() click to toggle source
# File lib/webauthn/public_key_credential.rb, line 48
def valid_id?
  raw_id && id && raw_id == WebAuthn.standard_encoder.decode(id)
end
valid_type?() click to toggle source
# File lib/webauthn/public_key_credential.rb, line 44
def valid_type?
  type == TYPE_PUBLIC_KEY
end