hydra-webauthn/public/js/login.js

20 lines
979 B
JavaScript

const rawAssertionRequest = HydraWebAuthn.fromBase64URL(document.currentScript.dataset.assertionRequest);
const assertionRequest = JSON.parse(rawAssertionRequest);
assertionRequest.publicKey.challenge = HydraWebAuthn.base64ToArrayBuffer(assertionRequest.publicKey.challenge)
assertionRequest.publicKey.allowCredentials.forEach(credential => credential.id = HydraWebAuthn.base64ToArrayBuffer(credential.id))
console.log("Assertion request", assertionRequest)
navigator.credentials.get(assertionRequest)
.then(assertion => {
console.log("Assertion", assertion)
if (assertion) {
const jsonAssertion = JSON.stringify(HydraWebAuthn.toJSONAssertion(assertion), null, 2);
console.log(jsonAssertion);
document.getElementById("assertion").value = HydraWebAuthn.toBase64URL(jsonAssertion);
}
}).catch(err => {
console.error(err);
}).finally(() => {
document.getElementById("login").submit();
})