2022-06-29 11:28:26 +02:00
|
|
|
{% extends "default.html" %}
|
2020-05-05 10:32:49 +02:00
|
|
|
|
2022-06-29 11:28:26 +02:00
|
|
|
{% set active_page = "setting" %}
|
|
|
|
{% block title %}Security Key Setup{% endblock %}
|
2020-05-05 10:32:49 +02:00
|
|
|
{% block head %}
|
2022-06-29 11:28:26 +02:00
|
|
|
|
2020-05-05 10:32:49 +02:00
|
|
|
<script src="{{ url_for('static', filename='node_modules/qrious/dist/qrious.min.js') }}"></script>
|
|
|
|
<script src="{{ url_for('static', filename='assets/js/vendors/base64.js') }}"></script>
|
2020-05-25 00:10:12 +02:00
|
|
|
<script src="/static/assets/js/vendors/webauthn.js?v={{ VERSION }}"></script>
|
2020-05-05 10:32:49 +02:00
|
|
|
{% endblock %}
|
|
|
|
{% block default_content %}
|
2022-06-29 11:28:26 +02:00
|
|
|
|
2020-05-11 23:22:06 +02:00
|
|
|
<div class="card">
|
|
|
|
<div class="card-body">
|
|
|
|
<h1 class="h2 text-center">Register Your Security Key</h1>
|
2022-07-04 16:01:04 +02:00
|
|
|
<p class="text-center">Follow your browser's steps to register your security key with SimpleLogin</p>
|
2020-05-11 23:22:06 +02:00
|
|
|
<form id="formRegisterKey" method="post">
|
|
|
|
{{ fido_token_form.csrf_token }}
|
|
|
|
{{ fido_token_form.sk_assertion(class="form-control", placeholder="") }}
|
2020-05-27 20:28:31 +02:00
|
|
|
{{ fido_token_form.key_name(id="key-name", class="form-control", placeholder="Name of your key (Required)") }}
|
2020-05-18 11:55:41 +02:00
|
|
|
{{ render_field_errors(fido_token_form.key_name) }}
|
2020-05-18 22:45:02 +02:00
|
|
|
<div class="text-center">
|
2022-06-29 11:28:26 +02:00
|
|
|
<span id="btnRegisterKey"
|
|
|
|
class="btn btn-lg btn-primary mt-2"
|
|
|
|
onclick="registerKey();">Register Key</span>
|
2020-05-18 22:45:02 +02:00
|
|
|
</div>
|
2020-05-11 23:22:06 +02:00
|
|
|
</form>
|
|
|
|
<script>
|
2020-05-27 20:28:31 +02:00
|
|
|
// disable submit when enter
|
|
|
|
$('form input').keydown(function (e) {
|
|
|
|
if (e.keyCode == 13) {
|
|
|
|
e.preventDefault();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-05-11 23:22:06 +02:00
|
|
|
async function registerKey() {
|
2020-05-27 20:28:31 +02:00
|
|
|
// make sure key name is not empty
|
|
|
|
if (!$("#key-name").val()) {
|
|
|
|
toastr.error("Key name cannot be empty.");
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-05-11 23:22:06 +02:00
|
|
|
$("#btnRegisterKey").prop('disabled', true);
|
|
|
|
$("#btnRegisterKey").text('Waiting for Security Key...');
|
|
|
|
|
|
|
|
const pkCredentialCreateOptions = transformCredentialCreateOptions(
|
|
|
|
JSON.parse('{{credential_create_options|tojson|safe}}')
|
|
|
|
)
|
|
|
|
|
2020-05-18 07:05:37 +02:00
|
|
|
|
2020-05-11 23:22:06 +02:00
|
|
|
let credential
|
|
|
|
try {
|
|
|
|
credential = await navigator.credentials.create({
|
|
|
|
publicKey: pkCredentialCreateOptions
|
|
|
|
});
|
|
|
|
} catch (err) {
|
|
|
|
toastr.error("An error occurred when we trying to register your key.");
|
|
|
|
$("#btnRegisterKey").prop('disabled', false);
|
|
|
|
$("#btnRegisterKey").text('Register Key');
|
|
|
|
return console.error("Error when trying to create credential:", err);
|
|
|
|
}
|
|
|
|
|
|
|
|
const skAssertion = transformNewAssertionForServer(credential);
|
|
|
|
|
|
|
|
$('#sk_assertion').val(JSON.stringify(skAssertion));
|
|
|
|
$('#formRegisterKey').submit();
|
2020-05-05 10:32:49 +02:00
|
|
|
}
|
|
|
|
|
2020-05-11 23:22:06 +02:00
|
|
|
</script>
|
|
|
|
</div>
|
2020-05-05 10:32:49 +02:00
|
|
|
</div>
|
|
|
|
{% endblock %}
|