Module: BetterAuth::Passkey::Credentials
- Defined in:
- lib/better_auth/passkey/credentials.rb
Class Method Summary collapse
- .attestation_response(credential) ⇒ Object
- .authenticator_data(credential) ⇒ Object
- .credential_descriptor(record, kind: :allow) ⇒ Object
- .credential_id(record) ⇒ Object
- .webauthn_response(value) ⇒ Object
- .wire(record) ⇒ Object
Class Method Details
.attestation_response(credential) ⇒ Object
30 31 32 |
# File 'lib/better_auth/passkey/credentials.rb', line 30 def attestation_response(credential) credential.instance_variable_get(:@response) end |
.authenticator_data(credential) ⇒ Object
34 35 36 |
# File 'lib/better_auth/passkey/credentials.rb', line 34 def authenticator_data(credential) attestation_response(credential)&.authenticator_data end |
.credential_descriptor(record, kind: :allow) ⇒ Object
50 51 52 53 54 55 56 |
# File 'lib/better_auth/passkey/credentials.rb', line 50 def credential_descriptor(record, kind: :allow) descriptor = {id: credential_id(record)} descriptor[:type] = "public-key" if kind == :allow transports = (record["transports"] || record[:transports]).to_s.split(",").map(&:strip).reject(&:empty?) descriptor[:transports] = transports if transports.any? descriptor end |
.credential_id(record) ⇒ Object
46 47 48 |
# File 'lib/better_auth/passkey/credentials.rb', line 46 def credential_id(record) record["credentialID"] || record["credentialId"] || record[:credentialID] || record[:credential_id] end |
.webauthn_response(value) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/better_auth/passkey/credentials.rb', line 8 def webauthn_response(value) data = BetterAuth::Passkey::Utils.normalize_hash(value || {}) response = BetterAuth::Passkey::Utils.normalize_hash(data[:response] || {}) webauthn = { "type" => data[:type], "id" => data[:id], "rawId" => data[:raw_id], "authenticatorAttachment" => data[:authenticator_attachment], "clientExtensionResults" => data[:client_extension_results] || {}, "response" => { "attestationObject" => response[:attestation_object], "clientDataJSON" => response[:client_data_json], "transports" => response[:transports], "authenticatorData" => response[:authenticator_data], "signature" => response[:signature], "userHandle" => response[:user_handle] }.compact }.compact webauthn["rawId"] ||= webauthn["id"] webauthn end |
.wire(record) ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/better_auth/passkey/credentials.rb', line 38 def wire(record) return record unless record.is_a?(Hash) output = record.dup output["credentialID"] = output.delete("credentialId") if output.key?("credentialId") output end |