Adding passkeys to Duende IdentityServer
Learn how to add passkeys to Duende IdentityServer using Authsignal.
The previous guide showed how to integrate IdentityServer with Authsignal in order to add MFA after a traditional username & password sign-in.
In this guide, we’ll demonstrate how to let the user create a passkey and use it instead of their password the next time they sign in.
Using passkey autofill to sign in
Configuring passkeys
In the Authsignal Portal we have configured localhost
as the Relying Party for the purposes of local development.
We also whitelist both the login server and the application server as expected origins.
Configuring the relying party ID and expected origins
This means the user can enroll a passkey directly from our web app running on https://localhost:5002
, then reauthenticate with the same passkey when signing in to IdentityServer running on https://localhost:5001
.
Enrolling a passkey
Once the user has logged in with MFA, we can use the Authsignal Web SDK to allow the user to add a passkey.
This can be done by adding a button to the application server (i.e. the WebClient).
Adding a passkey
To implement this we add a new page /src/WebClient/Pages/Passkeys.cshtml.
The enrollmentToken
here is fetched server-side in /src/WebClient/Pages/Passkeys.cshtml.cs when the page loads.
Finally, we need to add the client-side JS implementation for the addPasskey function which uses the Authsignal Web SDK.
Signing in with a passkey
Now that the user has enrolled a passkey, the next time they sign in via IdentityServer we would like to give them the option to use their passkey instead of their username & password.
This can be achieved simply by adding a small client-side JavaScript snippet which initializes the existing username field to allow passkeys.
First we need to ensure that the input field has the value username webauthn
in the autocomplete attribute.
Then we add some JavaScript to run when the page loads.
This will initialize the input field for passkey autofill, which means if a user has enrolled a passkey then they should be able to select it when focusing the text field.
Signing in with a passkey
The validation process here is the same as for signing in with MFA in the previous guide - the only difference here is that we now receive a token directly from the Authsignal Web SDK. In both cases, we pass this token to our callback page, which uses the token to validate the result of the challenge server-side and log the user in.
For more information, check out our passkeys documentation or to test out passkey compatibility on your browser you can play with our demo site.