Sha256: 366f25fd5ef629278740878211c1ac72aa91aac2abfd120f0b55f71a2aab379d

Contents?: true

Size: 1.8 KB

Versions: 6

Compression:

Stored size: 1.8 KB

Contents

(function() {
  var element = document.getElementById('webauthn-setup-form');
  var f = function(e) {
    //console.log(e);
    e.preventDefault();
    if (navigator.credentials) {
      var opts = JSON.parse(element.getAttribute("data-credential-options"));
      opts.challenge = Uint8Array.from(atob(opts.challenge.replace(/-/g, '+').replace(/_/g, '/')), c => c.charCodeAt(0));
      opts.user.id = Uint8Array.from(atob(opts.user.id.replace(/-/g, '+').replace(/_/g, '/')), c => c.charCodeAt(0));
      //console.log(opts);
      navigator.credentials.create({publicKey: opts}).
        then(function(cred){
          //console.log(cred);
          //window.cred = cred
          
          var rawId = btoa(String.fromCharCode.apply(null, new Uint8Array(cred.rawId))).replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, '');
          document.getElementById('webauthn-setup').value = JSON.stringify({
            type: cred.type,
            id: rawId,
            rawId: rawId,
            response: {
              attestationObject: btoa(String.fromCharCode.apply(null, new Uint8Array(cred.response.attestationObject))).replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, ''),
              clientDataJSON: btoa(String.fromCharCode.apply(null, new Uint8Array(cred.response.clientDataJSON))).replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, '')
            }
          });
          element.removeEventListener("submit", f);
          element.submit();
        }).
        catch(function(e){document.getElementById('webauthn-setup-button').innerHTML = "Error creating public key in authenticator: " + e});
    } else {
        document.getElementById('webauthn-setup-button').innerHTML = "WebAuthn not supported by browser, or browser has disabled it on this page";
    }
  };
  element.addEventListener("submit", f);
})();

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
rodauth-2.5.0 javascript/webauthn_setup.js
rodauth-2.4.0 javascript/webauthn_setup.js
rodauth-2.3.0 javascript/webauthn_setup.js
rodauth-2.2.0 javascript/webauthn_setup.js
rodauth-2.1.0 javascript/webauthn_setup.js
rodauth-2.0.0 javascript/webauthn_setup.js