You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
1.3 KiB

  1. $(function() {
  2. var form = document.getElementById("login-tfa-form");
  3. var optionsBytes = Uint8Array.from(atob(form.dataset.options), c => c.charCodeAt(0));
  4. // cbor.js expects ArrayBuffer as input when decoding
  5. var options = CBOR.decode(optionsBytes.buffer);
  6. function b64(arraybuffer) {
  7. return btoa(String.fromCharCode.apply(null, new Uint8Array(arraybuffer)));
  8. }
  9. function authenticate() {
  10. $("#waiting").removeClass("hide");
  11. $("#error").addClass("hide");
  12. navigator.credentials.get(options).then(function(assertion) {
  13. $("#credential_id").val(b64(assertion.rawId));
  14. $("#authenticator_data").val(b64(assertion.response.authenticatorData));
  15. $("#client_data_json").val(b64(assertion.response.clientDataJSON));
  16. $("#signature").val(b64(assertion.response.signature));
  17. // Show the success message and save button
  18. $("#waiting").addClass("hide");
  19. $("#success").removeClass("hide");
  20. form.submit()
  21. }).catch(function(err) {
  22. // Show the error message
  23. $("#waiting").addClass("hide");
  24. $("#error-text").text(err);
  25. $("#error").removeClass("hide");
  26. });
  27. }
  28. $("#retry").click(authenticate);
  29. authenticate();
  30. });