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, InvalidChallengeError, Options, RPEntity, RequestOptions, UserEntity

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type:, id:, raw_id:, response:, authenticator_attachment: nil, client_extension_outputs: {}, relying_party: WebAuthn.configuration.relying_party) ⇒ PublicKeyCredential

Returns a new instance of PublicKeyCredential.



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/webauthn/public_key_credential.rb', line 23

def initialize(
  type:,
  id:,
  raw_id:,
  response:,
  authenticator_attachment: nil,
  client_extension_outputs: {},
  relying_party: WebAuthn.configuration.relying_party
)
  @type = type
  @id = id
  @raw_id = raw_id
  @client_extension_outputs = client_extension_outputs
  @authenticator_attachment = authenticator_attachment
  @response = response
  @relying_party = relying_party
end

Instance Attribute Details

#authenticator_attachmentObject (readonly)

Returns the value of attribute authenticator_attachment.



9
10
11
# File 'lib/webauthn/public_key_credential.rb', line 9

def authenticator_attachment
  @authenticator_attachment
end

#client_extension_outputsObject (readonly)

Returns the value of attribute client_extension_outputs.



9
10
11
# File 'lib/webauthn/public_key_credential.rb', line 9

def client_extension_outputs
  @client_extension_outputs
end

#idObject (readonly)

Returns the value of attribute id.



9
10
11
# File 'lib/webauthn/public_key_credential.rb', line 9

def id
  @id
end

#raw_idObject (readonly)

Returns the value of attribute raw_id.



9
10
11
# File 'lib/webauthn/public_key_credential.rb', line 9

def raw_id
  @raw_id
end

#responseObject (readonly)

Returns the value of attribute response.



9
10
11
# File 'lib/webauthn/public_key_credential.rb', line 9

def response
  @response
end

#typeObject (readonly)

Returns the value of attribute type.



9
10
11
# File 'lib/webauthn/public_key_credential.rb', line 9

def type
  @type
end

Class Method Details

.from_client(credential, relying_party: WebAuthn.configuration.relying_party) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/webauthn/public_key_credential.rb', line 11

def self.from_client(credential, relying_party: WebAuthn.configuration.relying_party)
  new(
    type: credential["type"],
    id: credential["id"],
    raw_id: relying_party.encoder.decode(credential["rawId"]),
    client_extension_outputs: credential["clientExtensionResults"],
    authenticator_attachment: credential["authenticatorAttachment"],
    response: response_class.from_client(credential["response"], relying_party: relying_party),
    relying_party: relying_party
  )
end

Instance Method Details

#authenticator_extension_outputsObject



58
59
60
# File 'lib/webauthn/public_key_credential.rb', line 58

def authenticator_extension_outputs
  authenticator_data.extension_data if authenticator_data&.extension_data_included?
end

#backed_up?Boolean

Returns:

  • (Boolean)


66
67
68
# File 'lib/webauthn/public_key_credential.rb', line 66

def backed_up?
  authenticator_data&.credential_backed_up?
end

#backup_eligible?Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/webauthn/public_key_credential.rb', line 62

def backup_eligible?
  authenticator_data&.credential_backup_eligible?
end

#sign_countObject



54
55
56
# File 'lib/webauthn/public_key_credential.rb', line 54

def sign_count
  authenticator_data&.sign_count
end

#verify(challenge, *_args) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/webauthn/public_key_credential.rb', line 41

def verify(challenge, *_args)
  unless valid_class?(challenge)
    msg = "challenge must be a String. input challenge class: #{challenge.class}"

    raise(InvalidChallengeError, msg)
  end

  valid_type? || raise("invalid type")
  valid_id? || raise("invalid id")

  true
end