|
|
@ -3,23 +3,34 @@ $(function() { |
|
|
|
var optionsBytes = Uint8Array.from(atob(form.dataset.options), c => c.charCodeAt(0)); |
|
|
|
// cbor.js expects ArrayBuffer as input when decoding
|
|
|
|
var options = CBOR.decode(optionsBytes.buffer); |
|
|
|
console.log("decoded options:", options); |
|
|
|
|
|
|
|
function b64(arraybuffer) { |
|
|
|
return btoa(String.fromCharCode.apply(null, new Uint8Array(arraybuffer))); |
|
|
|
} |
|
|
|
|
|
|
|
navigator.credentials.create(options).then(function(attestation) { |
|
|
|
console.log("got attestation: ", attestation); |
|
|
|
function requestCredentials() { |
|
|
|
// Hide error & success messages, show the "waiting" message
|
|
|
|
$("#name-next").addClass("hide"); |
|
|
|
$("#add-credential-waiting").removeClass("hide"); |
|
|
|
$("#add-credential-error").addClass("hide"); |
|
|
|
$("#add-credential-success").addClass("hide"); |
|
|
|
|
|
|
|
$("#attestation_object").val(b64(attestation.response.attestationObject)); |
|
|
|
$("#client_data_json").val(b64(attestation.response.clientDataJSON)); |
|
|
|
console.log("form updated, all is well"); |
|
|
|
navigator.credentials.create(options).then(function(attestation) { |
|
|
|
$("#attestation_object").val(b64(attestation.response.attestationObject)); |
|
|
|
$("#client_data_json").val(b64(attestation.response.clientDataJSON)); |
|
|
|
|
|
|
|
// Show the success message and save button
|
|
|
|
$("#add-credential-waiting").addClass("hide"); |
|
|
|
$("#add-credential-success").removeClass("hide"); |
|
|
|
}).catch(function(err) { |
|
|
|
// Show the error message
|
|
|
|
$("#add-credential-waiting").addClass("hide"); |
|
|
|
$("#add-credential-error-text").text(err); |
|
|
|
$("#add-credential-error").removeClass("hide"); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
$("#name-next").click(requestCredentials); |
|
|
|
$("#retry").click(requestCredentials); |
|
|
|
|
|
|
|
$("#add-credential-submit").prop("disabled", ""); |
|
|
|
$("#add-credential-success").removeClass("hide"); |
|
|
|
}).catch(function(err) { |
|
|
|
$("#add-credential-error span").text(err); |
|
|
|
$("#add-credential-error").removeClass("hide"); |
|
|
|
}); |
|
|
|
}); |