🐛 Fixed webauthn for root_url with port

This commit is contained in:
Mawoka
2022-12-19 13:30:43 +01:00
parent ec3f6f3dd2
commit ab1ab91153
3 changed files with 24 additions and 9 deletions
+2 -2
View File
@@ -85,7 +85,7 @@ def verify_webauthn(data, fidocredentialss: list[FidoCredentials], login_session
verify_authentication_response( verify_authentication_response(
credential=credential, credential=credential,
expected_challenge=base64.b64decode(login_session.webauthn_challenge), expected_challenge=base64.b64decode(login_session.webauthn_challenge),
expected_rp_id=urllib.parse.urlparse(settings.root_address).netloc, expected_rp_id=urllib.parse.urlparse(settings.root_address).hostname,
expected_origin=settings.root_address, expected_origin=settings.root_address,
credential_public_key=user_cred.public_key, credential_public_key=user_cred.public_key,
credential_current_sign_count=user_cred.sign_count, credential_current_sign_count=user_cred.sign_count,
@@ -116,7 +116,7 @@ async def start_login(data: StartLoginInput):
else: else:
step_1.add(StartLoginResponseTypes.PASSKEY) step_1.add(StartLoginResponseTypes.PASSKEY)
webauthn_data = generate_authentication_options( webauthn_data = generate_authentication_options(
rp_id=urllib.parse.urlparse(settings.root_address).netloc, rp_id=urllib.parse.urlparse(settings.root_address).hostname,
allow_credentials=[ allow_credentials=[
PublicKeyCredentialDescriptor(id=cred.id, type="public-key") for cred in user.fidocredentialss PublicKeyCredentialDescriptor(id=cred.id, type="public-key") for cred in user.fidocredentialss
], ],
+2 -2
View File
@@ -28,7 +28,7 @@ router = APIRouter()
async def request_add_key_data(user: User = Depends(get_current_user)): async def request_add_key_data(user: User = Depends(get_current_user)):
user = await User.objects.select_related("fidocredentialss").get(id=user.id) user = await User.objects.select_related("fidocredentialss").get(id=user.id)
options = generate_registration_options( options = generate_registration_options(
rp_id=urllib.parse.urlparse(settings.root_address).netloc, rp_id=urllib.parse.urlparse(settings.root_address).hostname,
rp_name="ClassQuiz", rp_name="ClassQuiz",
user_id=user.id.hex, user_id=user.id.hex,
user_name=user.email, user_name=user.email,
@@ -59,7 +59,7 @@ async def confirm_add_key_data(credential: RegistrationCredential, user: User =
verification = verify_registration_response( verification = verify_registration_response(
credential=credential, credential=credential,
expected_challenge=current_registration_challenge, expected_challenge=current_registration_challenge,
expected_rp_id=urllib.parse.urlparse(settings.root_address).netloc, expected_rp_id=urllib.parse.urlparse(settings.root_address).hostname,
expected_origin=settings.root_address, expected_origin=settings.root_address,
) )
new_credential = FidoCredentials( new_credential = FidoCredentials(
@@ -84,6 +84,9 @@
}; };
const get_backup_code = async () => { const get_backup_code = async () => {
if (!confirm('If you continue, your old backup-code will be removed.')) {
return;
}
const res = await fetch('/api/v1/users/2fa/backup_code'); const res = await fetch('/api/v1/users/2fa/backup_code');
backup_code = (await res.json()).code; backup_code = (await res.json()).code;
}; };
@@ -126,7 +129,7 @@
class="pointer-events-none inline-block h-4 w-4 translate-x-3 rounded-full bg-white transition will-change-transform" class="pointer-events-none inline-block h-4 w-4 translate-x-3 rounded-full bg-white transition will-change-transform"
/> />
</button> </button>
<span class="text-sm font-medium text-gray-700" <span class="text-sm font-medium text-gray-700 dark:text-white"
>Two Factor authentication is activated</span >Two Factor authentication is activated</span
> >
</div> </div>
@@ -147,7 +150,7 @@
class="pointer-events-none inline-block h-4 w-4 translate-x-0 rounded-full bg-white transition will-change-transform" class="pointer-events-none inline-block h-4 w-4 translate-x-0 rounded-full bg-white transition will-change-transform"
/> />
</button> </button>
<span class="text-sm font-medium text-gray-700" <span class="text-sm font-medium text-gray-700 dark:text-white"
>Two Factor authentication is deactivated</span >Two Factor authentication is deactivated</span
> >
</div> </div>
@@ -167,7 +170,11 @@
{/if} {/if}
</div> </div>
<div class="flex justify-center"> <div class="flex justify-center">
<button on:click={add_security_key}>Add Security-Key</button> <button
on:click={add_security_key}
class="m-auto rounded-lg bg-[#B07156] p-2 hover:bg-opacity-80 transition m-2"
>Add Security-Key</button
>
</div> </div>
<div class="flex justify-center"> <div class="flex justify-center">
<ul class="list-disc block"> <ul class="list-disc block">
@@ -196,9 +203,17 @@
<div class="flex justify-center"> <div class="flex justify-center">
{#if totp_activated} {#if totp_activated}
<button on:click={disable_totp}>Disable Totp</button> <button
on:click={disable_totp}
class="m-auto rounded-lg bg-[#B07156] p-2 hover:bg-opacity-80 transition m-2"
>Disable Totp</button
>
{:else} {:else}
<button on:click={enable_totp}>Enable Totp</button> <button
on:click={enable_totp}
class="m-auto rounded-lg bg-[#B07156] p-2 hover:bg-opacity-80 transition m-2"
>Enable Totp</button
>
{/if} {/if}
</div> </div>
</div> </div>