hydra-webauthn/public/js/register.js

17 lines
883 B
JavaScript

const rawWebAuthnOptions = HydraWebAuthn.fromBase64URL(document.currentScript.dataset.webAuthnOptions);
const webAuthnOptions = JSON.parse(rawWebAuthnOptions);
webAuthnOptions.publicKey.challenge = HydraWebAuthn.base64ToArrayBuffer(webAuthnOptions.publicKey.challenge);
webAuthnOptions.publicKey.user.id = HydraWebAuthn.base64ToArrayBuffer(webAuthnOptions.publicKey.user.id);
console.log(webAuthnOptions)
function generateCredentials() {
navigator.credentials.create(webAuthnOptions).then(credentials => {
if (!credentials) return;
const jsonCredentials = JSON.stringify(HydraWebAuthn.toJSONCredentials(credentials), null, 2);
console.log(jsonCredentials);
document.getElementById("credentials").value = HydraWebAuthn.toBase64URL(jsonCredentials);
document.getElementById("register").submit();
}).catch(err => console.error(err));
}