Class: WebAuthn::PublicKeyCredential

Inherits:
Object
  • Object
show all
Defined in:
lib/webauthn/public_key_credential.rb,
lib/webauthn/public_key_credential/entity.rb,
lib/webauthn/public_key_credential/options.rb,
lib/webauthn/public_key_credential/rp_entity.rb,
lib/webauthn/public_key_credential/user_entity.rb,
lib/webauthn/public_key_credential/request_options.rb,
lib/webauthn/public_key_credential/creation_options.rb

Defined Under Namespace

Classes: CreationOptions, Entity, Options, RPEntity, RequestOptions, UserEntity

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type:, id:, raw_id:, response:) ⇒ PublicKeyCredential

Returns a new instance of PublicKeyCredential.



18
19
20
21
22
23
# File 'lib/webauthn/public_key_credential.rb', line 18

def initialize(type:, id:, raw_id:, response:)
  @type = type
  @id = id
  @raw_id = raw_id
  @response = response
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



7
8
9
# File 'lib/webauthn/public_key_credential.rb', line 7

def id
  @id
end

#raw_idObject (readonly)

Returns the value of attribute raw_id.



7
8
9
# File 'lib/webauthn/public_key_credential.rb', line 7

def raw_id
  @raw_id
end

#responseObject (readonly)

Returns the value of attribute response.



7
8
9
# File 'lib/webauthn/public_key_credential.rb', line 7

def response
  @response
end

#typeObject (readonly)

Returns the value of attribute type.



7
8
9
# File 'lib/webauthn/public_key_credential.rb', line 7

def type
  @type
end

Class Method Details

.from_client(credential) ⇒ Object



9
10
11
12
13
14
15
16
# 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"]),
    response: response_class.from_client(credential["response"])
  )
end

Instance Method Details

#sign_countObject



32
33
34
# File 'lib/webauthn/public_key_credential.rb', line 32

def sign_count
  response&.authenticator_data&.sign_count
end

#verify(*_args) ⇒ Object



25
26
27
28
29
30
# File 'lib/webauthn/public_key_credential.rb', line 25

def verify(*_args)
  valid_type? || raise("invalid type")
  valid_id? || raise("invalid id")

  true
end