Skip to content

Commit 186be52

Browse files
Merge pull request #370 from 8ma10s/support_for_authenticator_attachment_in_public_key_credential
Add support for optional authenticator_attachment in PublicKeyCredential
2 parents e354924 + 3e17fcd commit 186be52

4 files changed

Lines changed: 10 additions & 1 deletion

File tree

lib/webauthn/fake_client.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ def create(
6464
"type" => "public-key",
6565
"id" => internal_encoder.encode(id),
6666
"rawId" => encoder.encode(id),
67+
"authenticatorAttachment" => 'platform',
6768
"clientExtensionResults" => extensions,
6869
"response" => {
6970
"attestationObject" => encoder.encode(attestation_object),
@@ -108,6 +109,7 @@ def get(challenge: fake_challenge,
108109
"id" => internal_encoder.encode(assertion[:credential_id]),
109110
"rawId" => encoder.encode(assertion[:credential_id]),
110111
"clientExtensionResults" => extensions,
112+
"authenticatorAttachment" => 'platform',
111113
"response" => {
112114
"clientDataJSON" => encoder.encode(client_data_json),
113115
"authenticatorData" => encoder.encode(assertion[:authenticator_data]),

lib/webauthn/public_key_credential.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@
44

55
module WebAuthn
66
class PublicKeyCredential
7-
attr_reader :type, :id, :raw_id, :client_extension_outputs, :response
7+
attr_reader :type, :id, :raw_id, :client_extension_outputs, :authenticator_attachment, :response
88

99
def self.from_client(credential, relying_party: WebAuthn.configuration.relying_party)
1010
new(
1111
type: credential["type"],
1212
id: credential["id"],
1313
raw_id: relying_party.encoder.decode(credential["rawId"]),
1414
client_extension_outputs: credential["clientExtensionResults"],
15+
authenticator_attachment: credential["authenticatorAttachment"],
1516
response: response_class.from_client(credential["response"], relying_party: relying_party),
1617
relying_party: relying_party
1718
)
@@ -22,13 +23,15 @@ def initialize(
2223
id:,
2324
raw_id:,
2425
response:,
26+
authenticator_attachment: nil,
2527
client_extension_outputs: {},
2628
relying_party: WebAuthn.configuration.relying_party
2729
)
2830
@type = type
2931
@id = id
3032
@raw_id = raw_id
3133
@client_extension_outputs = client_extension_outputs
34+
@authenticator_attachment = authenticator_attachment
3235
@response = response
3336
@relying_party = relying_party
3437
end

spec/webauthn/public_key_credential_with_assertion_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
let(:credential_raw_id) { credential[0] }
2222
let(:credential_id) { Base64.urlsafe_encode64(credential_raw_id) }
2323
let(:credential_type) { "public-key" }
24+
let(:credential_authenticator_attachment) { 'platform' }
2425
let(:credential_public_key) { Base64.urlsafe_encode64(credential[1]) }
2526
let(:credential_sign_count) { credential[2] }
2627

@@ -39,6 +40,7 @@
3940
type: credential_type,
4041
id: credential_id,
4142
raw_id: credential_raw_id,
43+
authenticator_attachment: credential_authenticator_attachment,
4244
response: assertion_response
4345
)
4446
end

spec/webauthn/public_key_credential_with_attestation_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,15 @@
1515
type: type,
1616
id: id,
1717
raw_id: raw_id,
18+
authenticator_attachment: authenticator_attachment,
1819
response: attestation_response
1920
)
2021
end
2122

2223
let(:type) { "public-key" }
2324
let(:id) { Base64.urlsafe_encode64(raw_id) }
2425
let(:raw_id) { SecureRandom.random_bytes(16) }
26+
let(:authenticator_attachment) { 'platform' }
2527

2628
let(:attestation_response) do
2729
response = client.create(challenge: raw_challenge)["response"]

0 commit comments

Comments
 (0)