From 7dc3eed9e74971ea6e820f0025987b76ea4bcab7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20L=C3=A9veill=C3=A9?= Date: Wed, 4 Oct 2023 20:19:27 -0400 Subject: [PATCH] Fix axum example for credential creation (#361) While investigating #351 I noticed that the `excludeCredentials` id's were still in base64url and which was failing validation in 1Password. Here I mirror the same modifications done to the `allowCredentials` list. This also adds an optional chaining to the `allowCredentials` list in the request options. --- tutorial/server/axum/assets/auth.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tutorial/server/axum/assets/auth.js b/tutorial/server/axum/assets/auth.js index a2ceb1bc..a069dbea 100644 --- a/tutorial/server/axum/assets/auth.js +++ b/tutorial/server/axum/assets/auth.js @@ -12,6 +12,9 @@ function register () { .then(credentialCreationOptions => { credentialCreationOptions.publicKey.challenge = Base64.toUint8Array(credentialCreationOptions.publicKey.challenge); credentialCreationOptions.publicKey.user.id = Base64.toUint8Array(credentialCreationOptions.publicKey.user.id); + credentialCreationOptions.publicKey.excludeCredentials?.forEach(function (listItem) { + listItem.id = Base64.toUint8Array(listItem.id) + }); return navigator.credentials.create({ publicKey: credentialCreationOptions.publicKey @@ -57,7 +60,7 @@ function login() { .then(response => response.json()) .then((credentialRequestOptions) => { credentialRequestOptions.publicKey.challenge = Base64.toUint8Array(credentialRequestOptions.publicKey.challenge); - credentialRequestOptions.publicKey.allowCredentials.forEach(function (listItem) { + credentialRequestOptions.publicKey.allowCredentials?.forEach(function (listItem) { listItem.id = Base64.toUint8Array(listItem.id) });