Sha256: 6f270a4e2854f5c4fe9c68abfb15e210248e7291fb39ee2a73b34dde98b639da

Contents?: true

Size: 1.84 KB

Versions: 33

Compression:

Stored size: 1.84 KB

Contents

(function() {
  var pack = function(v) { return btoa(String.fromCharCode.apply(null, new Uint8Array(v))).replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, ''); };
  var unpack = function(v) { return Uint8Array.from(atob(v.replace(/-/g, '+').replace(/_/g, '/')), c => c.charCodeAt(0)); };
  var element = document.getElementById('webauthn-auth-form');
  var f = function(e) {
    //console.log(e);
    e.preventDefault();
    if (navigator.credentials) {
      var opts = JSON.parse(element.getAttribute("data-credential-options"));
      opts.challenge = unpack(opts.challenge);
      opts.allowCredentials.forEach(function(cred) { cred.id = unpack(cred.id); });
      //console.log(opts);
      navigator.credentials.get({publicKey: opts}).
        then(function(cred){
          //console.log(cred);
          //window.cred = cred

          var rawId = pack(cred.rawId);
          var authValue = {
            type: cred.type,
            id: rawId,
            rawId: rawId,
            response: {
              authenticatorData: pack(cred.response.authenticatorData),
              clientDataJSON: pack(cred.response.clientDataJSON),
              signature: pack(cred.response.signature)
            }
          };

          if (cred.response.userHandle) {
            authValue.response.userHandle = pack(cred.response.userHandle);
          }

          document.getElementById('webauthn-auth').value = JSON.stringify(authValue);
          element.removeEventListener("submit", f);
          element.submit();
        }).
        catch(function(e){document.getElementById('webauthn-auth-button').innerHTML = "Error authenticating using WebAuthn: " + e});
    } else {
        document.getElementById('webauthn-auth-button').innerHTML = "WebAuthn not supported by browser, or browser has disabled it on this page";
    }
  };
  element.addEventListener("submit", f);
})();

Version data entries

33 entries across 33 versions & 1 rubygems

Version Path
rodauth-2.38.0 javascript/webauthn_auth.js
rodauth-2.37.0 javascript/webauthn_auth.js
rodauth-2.36.0 javascript/webauthn_auth.js
rodauth-2.34.0 javascript/webauthn_auth.js
rodauth-2.33.0 javascript/webauthn_auth.js
rodauth-2.32.0 javascript/webauthn_auth.js
rodauth-2.31.0 javascript/webauthn_auth.js
rodauth-2.30.0 javascript/webauthn_auth.js
rodauth-2.29.0 javascript/webauthn_auth.js
rodauth-2.28.0 javascript/webauthn_auth.js
rodauth-2.27.0 javascript/webauthn_auth.js
rodauth-2.26.1 javascript/webauthn_auth.js
rodauth-2.26.0 javascript/webauthn_auth.js
rodauth-2.25.0 javascript/webauthn_auth.js
rodauth-2.24.0 javascript/webauthn_auth.js
rodauth-2.23.0 javascript/webauthn_auth.js
rodauth-2.22.0 javascript/webauthn_auth.js
rodauth-2.21.0 javascript/webauthn_auth.js
rodauth-2.20.0 javascript/webauthn_auth.js
rodauth-2.19.0 javascript/webauthn_auth.js