Files
fizzy/lib/action_pack/web_authn/public_key_credential.rb
T
Stanko K.R. fbe9252db1 Auto-suggest name for new Passkeys
- Use plain client data json everywhere
- Expose AAGUID and backed_up on Credentials
- Make attestation verifiers configurable
- Auto-suggest names for passkeys and show icons
2026-03-18 11:49:59 +01:00

49 lines
1.6 KiB
Ruby

class ActionPack::WebAuthn::PublicKeyCredential
attr_reader :id, :public_key, :sign_count, :aaguid, :backed_up, :transports, :owner
class << self
def create(client_data_json:, attestation_object:, challenge:, origin:, transports: [], owner: nil)
response = ActionPack::WebAuthn::Authenticator::AttestationResponse.new(
client_data_json: client_data_json,
attestation_object: attestation_object
)
response.validate!(challenge: challenge, origin: origin)
new(
id: response.attestation.credential_id,
public_key: response.attestation.public_key,
sign_count: response.attestation.sign_count,
aaguid: response.attestation.aaguid,
backed_up: response.attestation.backed_up?,
transports: transports,
owner: owner
)
end
end
def initialize(id:, public_key:, sign_count:, aaguid: nil, backed_up: nil, transports: [], owner: nil)
@id = id
@public_key = public_key
@sign_count = sign_count
@aaguid = aaguid
@backed_up = backed_up
@transports = transports
@owner = owner
end
def authenticate(client_data_json:, authenticator_data:, signature:, challenge:, origin:)
response = ActionPack::WebAuthn::Authenticator::AssertionResponse.new(
client_data_json: client_data_json,
authenticator_data: authenticator_data,
signature: signature,
credential: self
)
response.validate!(challenge: challenge, origin: origin)
@sign_count = response.authenticator_data.sign_count
@backed_up = response.authenticator_data.backed_up?
end
end