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.

36 lines
1.4 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. $("#pick-method").addClass("hide");
  11. $("#waiting").removeClass("hide");
  12. $("#error").addClass("hide");
  13. navigator.credentials.get(options).then(function(assertion) {
  14. $("#credential_id").val(b64(assertion.rawId));
  15. $("#authenticator_data").val(b64(assertion.response.authenticatorData));
  16. $("#client_data_json").val(b64(assertion.response.clientDataJSON));
  17. $("#signature").val(b64(assertion.response.signature));
  18. // Show the success message and save button
  19. $("#waiting").addClass("hide");
  20. $("#success").removeClass("hide");
  21. form.submit()
  22. }).catch(function(err) {
  23. // Show the error message
  24. $("#waiting").addClass("hide");
  25. $("#error-text").text(err);
  26. $("#error").removeClass("hide");
  27. });
  28. }
  29. $("#use-key-btn").click(authenticate);
  30. $("#retry").click(authenticate);
  31. });