Keycloak Passkey Autofill
Learn how to add passkey autofill using Authsignal with Keycloak.
Overview
Passkey autofill provides an incredibly seamless and secure way for users to sign-in using their passkey.
In the previous guide, we demonstrated how to allow users to enroll a passkey using the pre-built UI.
In this guide, we will show you how to add passkey autofill to your Keycloak sign-in flow using Authsignal. Users will be able to sign-in by simply clicking the input and authenticating with the passkey that they enrolled with the prebuilt UI.
Passkey autofill.
Code example
If you haven’t already added our provider to your Keycloak instance, see our guide on adding the Authsignal Keycloak provider for instructions.
You can find the Keycloak provider code example referenced in this guide on GitHub. For advanced situations, you can modify the provider to meet your specific requirements. However, this provider will work for most use cases.
Authsignal configuration
Setup a custom domain
In the previous guide, we setup a custom domain on Authsignal. If you haven’t done this already, see our guide on setting up a custom domain for instructions.
Local development
To make things easy, we will make a few simple changes to your local development setup so that you can simulate a production environment, locally.
We will use mkcert
to create a local SSL certificate and local-ssl-proxy
to proxy requests to your local Keycloak server.
Replace keycloak-demo.authsignallabs.com
with your domain. If using the prebuilt UI, this will differ from your Authsignal custom domain. i.e. keycloak-demo.authsignallabs.com
which our demo app uses vs keycloak-demo-auth.authsignallabs.com
where the prebuilt UI is running - in this demonstration.
1. SSL Certificate Setup
Take note of the path to the .pem
files that are created as you’ll need them in the next steps.
2. Custom Domain to Local IP Address Mapping
Map your custom domain to your local IP address by adding the following line to your hosts
file:
Add this line:
3. Run the proxy server
4. Run your Keycloak server
Learn more about the Keycloak server configuration options.
5. Sign in to your Keycloak server
Open your browser and navigate to https://your_domain:8443
(e.g. https://keycloak-demo.authsignallabs.com:8443
) which will redirect you to the admin sign-in page on your proxied https Keycloak server.
Opening the Keycloak admin sign-in page
Changes to your Keycloak configuration
In your Keycloak admin UI, navigate to the Authentication
section and click on your custom flow. Delete the default username and password flow.
Delete the default username and password flow
Click on the Authsignal Authenticator settings and toggle on Enable Passkey Autofill
.
Enable Passkey Autofill
Enable Passkey Autofill
Sign-in UI configuration
We need to add some custom code to the Keycloak sign-in page so that it can use Authsignal’s Browser SDK to handle passkey autofill.
Start by creating a new theme for your Keycloak instance, at the following path: themes/mytheme/login/login.ftl
on your keycloak server.
You can call the theme whatever you want, but for this example, we will call it mytheme
.
Add the following code to the login.ftl
file. This code will allow autofill to work when the user clicks the input.
Create a Javascript file at themes/mytheme/login/resources/js/script.js
and add the following code. This code is required to allow autofill to work when the user clicks the input.
Restart your Keycloak server, and navigate to the Realm settings
section in the Keycloak admin UI. Click Themes
.
On the Login theme
line, select mytheme
and click Save
.
Opening the Keycloak admin sign-in page
You can style your theme by adding your own CSS to the themes/mytheme/login/resources/css/styles.css
file.
Navigate to your realm’s sign-in page and you should see the new theme.
You can find your realm’s sign in page URL by selecting your realm and then navigating to the Clients
section in the Keycloak admin UI and clicking Home URL
.
Find your realm's Home URL
Passkeys that have been enrolled using the Authsignal prebuilt UI will be available for autofill when both:
- Your Keycloak login page is hosted on the same domain or subdomain as where the passkeys were enrolled.
- The relying party ID (RP ID) matches the domain where the passkeys were enrolled
In this demo we enrolled passkeys on the keycloak-demo-auth.authsignallabs.com
domain, and have an RP ID of authsignallabs.com
, so we can autofill passkeys on the keycloak-demo.authsignallabs.com
domain.
This is due to the security model of WebAuthn/passkeys, which restricts passkey usage to the domain (or its subdomains) where they were originally registered.
Passkey autofill.
Conclusion
That’s it! You’ve successfully added passkey autofill to your Keycloak sign-in flow using Authsignal.
Was this page helpful?