70 lines
1.7 KiB
Plaintext
70 lines
1.7 KiB
Plaintext
|
{#- This file is part of sner4 project governed by MIT license, see the LICENSE.txt file. -#}
|
||
|
{% extends 'frontend/base.html.j2' %}
|
||
|
|
||
|
{% block script %}
|
||
|
<script>
|
||
|
let options_req = {{ options }};
|
||
|
let token = "{{ token }}";
|
||
|
|
||
|
// https://developer.mozilla.org/en-US/docs/Web/API/PublicKeyCredential/parseRequestOptionsFromJSON_static
|
||
|
// PublicKeyCredential.parseRequestOptionsFromJSON(
|
||
|
|
||
|
async function get_passkey_credentials(options) {
|
||
|
let option_obj = PublicKeyCredential.parseCreationOptionsFromJSON(options);
|
||
|
console.log(option_obj);
|
||
|
let credential = await navigator.credentials.create({
|
||
|
'publicKey': option_obj,
|
||
|
});
|
||
|
let credential_json = credential.toJSON()
|
||
|
console.log(credential_json);
|
||
|
return credential_json;
|
||
|
}
|
||
|
let form = document.getElementById('webauthn_register_form');
|
||
|
|
||
|
async function register() {
|
||
|
|
||
|
//let credential = await get_passkey_credentials(options_req);
|
||
|
let credential = await auth_passkey.sign_up(options_req);
|
||
|
let name = form.querySelector('#name').value;
|
||
|
|
||
|
let response = await fetch("{{ url_for('.passkey_new_process') }}", {
|
||
|
method: "POST",
|
||
|
headers: {
|
||
|
"Content-Type": "application/json",
|
||
|
},
|
||
|
body: JSON.stringify({
|
||
|
token,
|
||
|
credential,
|
||
|
name
|
||
|
}),
|
||
|
})
|
||
|
}
|
||
|
|
||
|
|
||
|
form.onsubmit = ev => {
|
||
|
ev.preventDefault()
|
||
|
register().then( result => {
|
||
|
document.location = "{{ url_for('.passkey') }}";
|
||
|
})
|
||
|
};
|
||
|
|
||
|
</script>
|
||
|
{% endblock %}
|
||
|
|
||
|
{% block content %}
|
||
|
<div class="profile">
|
||
|
<h1>Register new Passkey credential</h1>
|
||
|
|
||
|
<div>
|
||
|
To register new credential:
|
||
|
<ol>
|
||
|
<li>Insert/connect authenticator and verify user presence.</li>
|
||
|
<li>Set name for the new credential.</li>
|
||
|
<li>Submit the registration.</li>
|
||
|
</ol>
|
||
|
</div>
|
||
|
|
||
|
{{ render_form(form, id="webauthn_register_form") }}
|
||
|
</div>
|
||
|
{% endblock %}
|