| 1 |
{# |
| 2 |
This template receives the following pieces of context in addition to the form: |
| 3 |
#} |
| 4 |
{% set title = title|default(_fsdomain("Setup a New Passkey")) %} |
| 5 |
{% extends "security/base.html" %} |
| 6 |
{% from "security/_macros.html" import render_field_with_errors, render_field, render_field_errors, render_csrf, script_nonce %} |
| 7 |
|
| 8 |
{% block head_scripts %} |
| 9 |
{{ super() }} |
| 10 |
<script {{ script_nonce() }} src="{{ url_for('.static', filename='js/webauthn.js') }}"></script> |
| 11 |
<script {{ script_nonce() }} src="{{ url_for('.static', filename='js/base64.js') }}"></script> |
| 12 |
{% endblock head_scripts %} |
| 13 |
|
| 14 |
{% block content %} |
| 15 |
{% include "security/_messages.html" %} |
| 16 |
<h1>{{ _fsdomain("Setup a New Passkey") }}</h1> |
| 17 |
{% if not credential_options %} |
| 18 |
{# Initial form to get CreateOptions #} |
| 19 |
<div>{{ _fsdomain("Start by providing a unique name for your passkey:") }}</div> |
| 20 |
<form action="{{ url_for_security('wan_register') }}" method="post" name="wan_register_form" id="wan-register-form"> |
| 21 |
{{ wan_register_form.hidden_tag() }} |
| 22 |
{{ render_field_with_errors(wan_register_form.name) }} |
| 23 |
{# Default is just second factor #} |
| 24 |
{% if config["SECURITY_WAN_ALLOW_AS_FIRST_FACTOR"] %} |
| 25 |
<div> |
| 26 |
{% for subfield in wan_register_form.usage %}{{ render_field_with_errors(subfield) }}{% endfor %} |
| 27 |
</div> |
| 28 |
{% endif %} |
| 29 |
{{ render_field(wan_register_form.submit) }} |
| 30 |
</form> |
| 31 |
{% else %} |
| 32 |
<form action="{{ url_for_security('wan_register_response', token=wan_state) }}" method="post" name="wan_register_response_form" id="wan-register-response-form"> |
| 33 |
{{ wan_register_response_form.hidden_tag() }} |
| 34 |
<div id="wan-errors"></div> |
| 35 |
</form> |
| 36 |
<script {{ script_nonce() }} type="text/javascript"> |
| 37 |
handleRegister('{{ credential_options|safe }}') |
| 38 |
.then((result) => { |
| 39 |
if (result.error_msg) { |
| 40 |
const error_element = document.getElementById("wan-errors"); |
| 41 |
error_element.innerHTML = `<em>${result.error_msg}</em>`; |
| 42 |
} else { |
| 43 |
document.getElementById("credential").value = result.credential; |
| 44 |
{# We auto-submit this form - there is a Submit button on the |
| 45 |
form we could use - but there really isn't any reason to force the |
| 46 |
user to click yet another button |
| 47 |
#} |
| 48 |
document.forms["wan-register-response-form"].submit(); |
| 49 |
} |
| 50 |
}); |
| 51 |
</script> |
| 52 |
{% endif %} |
| 53 |
{% if registered_credentials %} |
| 54 |
<h3>{{ _fsdomain("Currently registered passkeys:") }}</h3> |
| 55 |
{% set listing = _fsdomain('Nickname: "%s" Usage: "%s" Transports: "%s" Discoverable: "%s" Device Type: "%s" Backed up? "%s" Last used on: %s') %} |
| 56 |
<ul> |
| 57 |
{% for cred in registered_credentials %} |
| 58 |
<li> |
| 59 |
{{ listing|format(cred.name, cred.usage, cred.transports|join(", "), cred.discoverable, cred.device_type, cred.backup_state, cred.lastuse) }} |
| 60 |
</li> |
| 61 |
{% endfor %} |
| 62 |
</ul> |
| 63 |
{% endif %} |
| 64 |
{% if wan_delete_form %} |
| 65 |
<hr> |
| 66 |
<h2>{{ _fsdomain("Delete an Existing Passkey") }}</h2> |
| 67 |
<form action="{{ url_for_security('wan_delete') }}" method="post" name="wan_delete_form"> |
| 68 |
{# explicitly render csrf_token so we can change the ID so we don't get duplicates #} |
| 69 |
{{ render_csrf(wan_delete_form, "delete") }} |
| 70 |
{{ render_field_with_errors(wan_delete_form.name) }} |
| 71 |
{{ render_field(wan_delete_form.submit) }} |
| 72 |
</form> |
| 73 |
{% endif %} |
| 74 |
{% if security.support_mfa and security.multi_factor_recovery_codes %} |
| 75 |
<hr> |
| 76 |
<h2>{{ _fsdomain("Recovery Codes") }}</h2> |
| 77 |
<div class="fs-div"> |
| 78 |
{{ _fsdomain("This application supports setting up recovery codes.") }} |
| 79 |
<a href="{{ url_for_security('mf_recovery_codes') }}">{{ _fsdomain("You can set them up here.") }}</a> |
| 80 |
</div> |
| 81 |
{% endif %} |
| 82 |
{% include "security/_menu.html" %} |
| 83 |
{% endblock content %} |