FidoTest / static /index.html
PaulMartrenchar's picture
add permissions
1d31c73
<!DOCTYPE html>
<html>
<head><meta charset="utf-8"><title>Flask WebAuthn + MDS Demo</title></head>
<body>
<h1>Register Authenticator</h1>
<button id="btn">Register</button>
<pre id="out"></pre>
<script>
function b64toArr(s) {
return Uint8Array.from(atob(s), c=>c.charCodeAt(0));
}
document.getElementById('btn').onclick = async () => {
const opts = await fetch('/register/options').then(r=>r.json());
console.log("opts", opts);
opts.challenge = b64toArr(opts.challenge);
opts.user.id = b64toArr(opts.user.id);
opts.excludeCredentials?.forEach(c => c.id = b64toArr(c.id));
const cred = await navigator.credentials.create({ publicKey: opts });
const resp = {
id: cred.id,
rawId: btoa(String.fromCharCode(...new Uint8Array(cred.rawId))),
response: {
data: btoa(String.fromCharCode(...new Uint8Array(cred.response.clientDataJSON))),
attestation: btoa(String.fromCharCode(...new Uint8Array(cred.response.attestationObject)))
}
};
const res = await fetch('/register/verify', {
method: 'POST',
headers: {'Content-Type':'application/json'},
body: JSON.stringify(resp)
}).then(r=>r.json());
document.getElementById('out').textContent = JSON.stringify(res, null, 2);
};
</script>
</body>
</html>