Juice/templates/auth_fido.html
2019-06-16 18:22:47 -04:00

54 lines
1.8 KiB
HTML

<!DOCTYPE html>
<html>
<head>
<title>Juice - {{ title }}</title>
<link rel="stylesheet" type="text/css" href="/static/juice.css">
<script type="text/javascript" src="/static/cbor.js"></script>
</head>
<body>
<h1>{{ heading }}</h1>
<p>Touch your authenticactor device now...
<script>
fetch('{{ api_begin }}', {
method: 'POST',
}).then(function(response) {
if(!response.ok) { throw new Error('Error getting registration data!'); }
return response.arrayBuffer();
}).then(CBOR.decode).then(function(options) {
return navigator.credentials.{% if title == 'Register' %}create{% else %}get{% endif %}(options);
{% if title == 'Register' %}
}).then(function(attestation) {
return fetch('{{ api_complete }}', {
method: 'POST',
headers: {'Content-Type': 'application/cbor'},
body: CBOR.encode({
"attestationObject": new Uint8Array(attestation.response.attestationObject),
"clientDataJSON": new Uint8Array(attestation.response.clientDataJSON),
})
});
{% else %}
}).then(function(assertion) {
return fetch('{{ api_complete }}', {
method: 'POST',
headers: {'Content-Type': 'application/cbor'},
body: CBOR.encode({
"credentialId": new Uint8Array(assertion.rawId),
"authenticatorData": new Uint8Array(assertion.response.authenticatorData),
"clientDataJSON": new Uint8Array(assertion.response.clientDataJSON),
"signature": new Uint8Array(assertion.response.signature)
})
});
{% endif %}
}).then(function(response) {
let stat = response.ok ? 'successful' : 'unsuccessful';
alert('Registration ' + stat + ' More details in server log...');
}, function(reason) {
alert(reason);
}).then(function() {
window.location = '{{ url_for("app_views.index") }}';
});
</script>
</body>
</html>