Many websites now use WebAuthn passkeys for sign-in. In a standard browser, passkey requests open an operating system prompt such as Windows Hello, macOS Touch ID, or a USB security key dialog.
When you use a Java webview or embed a Chromium browser in a desktop application (such as an enterprise client, an internal SSO workspace, a kiosk app, or a browser automation tool), that default behavior gets in the way. The native OS dialog blocks automated sign-in, and the passkeys stay locked to a single machine instead of your own database or credential vault.
To solve this, you can build a custom passkey manager that acts as a virtual WebAuthn authenticator in Java. Password managers like 1Password and Bitwarden use the same technique: they intercept passkey requests in JavaScript and handle key generation and signing in their own code. With Fuzio, we can override the browser’s credential API before page scripts run and forward passkey requests to the JVM through the JavaScript-Java bridge.
In this article, we will build a custom passkey manager for a Java webview using Fuzio to automate passkey registration and sign-in.
Prerequisites
To follow this tutorial, you need JDK 17 or later.
Architecture
We will build a Java desktop application that embeds a Fuzio BrowserView
component. We use Swing in this tutorial for simplicity, but the same passkey
manager works with any Java UI toolkit (Swing, JavaFX, SWT, or Compose
Multiplatform) as well as in headless browser mode.
Specifically, our example demonstrates how to:
- Complete passkey registration and sign-in in code without triggering Windows Hello, Touch ID, or USB security key prompts.
- Return a standard
PublicKeyCredentialresponse so target websites (called Relying Parties, or RPs, in the WebAuthn specification) work without changes. - Store private keys and credential data in Java so you can save them locally or sync them with a backend server.
The passkey manager follows a four-step interception flow:
- Inject at document start: Use Fuzio’s
InjectJsCallbackto inject a script before page scripts run. - Forward options to Java: Override
navigator.credentials.create()andnavigator.credentials.get()in JavaScript and send the WebAuthn options to a@JsAccessibleJava object. - Execute authenticator ceremonies in Java: Run the WebAuthn registration
and sign-in flows (called ceremonies in the WebAuthn spec) in Java,
generating EC P-256 (
ES256) keys oncreateand signing assertions withSHA256withECDSAonget. - Return a standard
PublicKeyCredential: Reconstruct the browser’sPublicKeyCredentialobject from the Java response so the website accepts it as a standard passkey.
Passkey manager architecture in Fuzio.
Project Structure
Create a new Gradle project directory named passkey-manager/ with Fuzio
configured. If you are new to Fuzio, follow the Quick Start
guide to set up your build.gradle.kts and license key.
Throughout this tutorial, all commands and file paths are relative to
passkey-manager/:
passkey-manager/
├── build.gradle.kts
└── src/main/
├── java/tech/fuzio/passkey/
│ ├── PasskeyManagerApp.java
│ ├── PasskeyAuthenticator.java
│ └── InMemoryPasskeyVault.java
└── resources/
└── passkey-interceptor.js
The Fuzio integration lives in PasskeyManagerApp.java,
PasskeyAuthenticator.java, and passkey-interceptor.js.
InMemoryPasskeyVault.java is an in-memory mock store for testing against
webauthn.io. In production, PasskeyAuthenticator delegates to your own
credential vault or backend service instead.
Step 1: Inject the Interceptor and Java Bridge
In src/main/java/tech/fuzio/passkey/PasskeyManagerApp.java, use Fuzio’s
JavaScript-Java bridge (InjectJsCallback) to attach a
PasskeyAuthenticator instance to window.passkeyBridge and execute
passkey-interceptor.js in every frame:
browser.set(InjectJsCallback.class, params -> {
var frame = params.frame();
JsObject window = frame.executeJavaScript("window");
if (window != null) {
window.putProperty("passkeyBridge", authenticator);
frame.executeJavaScript(interceptorScript);
}
return InjectJsCallback.Response.proceed();
});
InjectJsCallback runs for every frame as soon as Chromium creates its
document, before any page scripts execute. As a result, the interceptor
replaces navigator.credentials before a page can trigger WebAuthn on initial
load.
Step 2: Override navigator.credentials in JavaScript
In src/main/resources/passkey-interceptor.js, we save references to the
original navigator.credentials.create and navigator.credentials.get methods
so non-WebAuthn requests fall through to Chromium unchanged. When a WebAuthn
request arrives, we forward it to the window.passkeyBridge object from
Step 1:
const originalCreate =
navigator.credentials.create.bind(navigator.credentials);
const originalGet =
navigator.credentials.get.bind(navigator.credentials);
function toArrayBuffer(bufferSource) {
return new Uint8Array(bufferSource).buffer;
}
navigator.credentials.create = async function(options) {
if (!options || !options.publicKey || !window.passkeyBridge) {
return originalCreate(options);
}
const pk = options.publicKey;
const rpId = (pk.rp && pk.rp.id) || window.location.hostname;
const responseJson = window.passkeyBridge.create(
window.location.origin,
rpId,
toArrayBuffer(pk.challenge),
toArrayBuffer(pk.user.id)
);
return buildAttestationCredential(JSON.parse(responseJson));
};
navigator.credentials.get = async function(options) {
if (!options || !options.publicKey ||
options.mediation === "conditional" || !window.passkeyBridge) {
return originalGet(options);
}
const pk = options.publicKey;
const rpId = pk.rpId || window.location.hostname;
const responseJson = window.passkeyBridge.get(
window.location.origin,
rpId,
toArrayBuffer(pk.challenge)
);
return buildAssertionCredential(JSON.parse(responseJson));
};
WebAuthn options pass challenge and user.id as either an ArrayBuffer or a
TypedArray view (such as Uint8Array). Normalizing them with
new Uint8Array(bufferSource).buffer lets Fuzio’s JavaScript-Java bridge pass
each binary buffer directly to Java as a JsArrayBuffer without manual binary
serialization in JavaScript.
In navigator.credentials.get, we also skip "conditional" mediation requests
so background browser autofill checks on page load do not trigger an unintended
sign-in. Passing window.location.origin explicitly lets the Java authenticator
include the caller’s origin in clientDataJSON. Next, we will implement the
window.passkeyBridge methods in Java to return responseJson, and then
implement buildAttestationCredential and buildAssertionCredential in Step 4.
Step 3: Handle Passkey Requests in Java
Create src/main/java/tech/fuzio/passkey/PasskeyAuthenticator.java to handle
the intercepted calls from window.passkeyBridge. The class and its
@JsAccessible create and get methods are public so Fuzio’s bridge can
invoke them from JavaScript:
public final class PasskeyAuthenticator {
private final InMemoryPasskeyVault vault = new InMemoryPasskeyVault();
@JsAccessible
public String create(
String origin,
String rpId,
JsArrayBuffer challenge,
JsArrayBuffer userId
) {
var attestation = vault.create(
origin,
rpId,
challenge.bytes(),
userId.bytes()
);
return attestation.toJson();
}
@JsAccessible
public String get(
String origin,
String rpId,
JsArrayBuffer challenge
) {
var assertion = vault.get(origin, rpId, challenge.bytes());
return assertion.toJson();
}
}
Each method reads the raw ArrayBuffer bytes from Chromium via
JsArrayBuffer.bytes(), delegates the WebAuthn ceremony to the credential
vault, and returns a JSON object with Base64URL-encoded binary fields (id,
rawId, clientDataJSON, authenticatorData, and the ceremony-specific
attestation or signature fields).
In the example project, InMemoryPasskeyVault implements both
ceremonies in memory using standard JDK java.security APIs (KeyPairGenerator
with secp256r1 on create and SHA256withECDSA on get). In your
application, replace InMemoryPasskeyVault with calls to your own credential
store or backend service.
Step 4: Reconstruct PublicKeyCredential in JavaScript
Many relying parties check credential instanceof PublicKeyCredential or call
credential.toJSON() before sending the payload to their backend. However,
native browser getters on PublicKeyCredential.prototype throw
TypeError: Illegal invocation if accessed on a plain object.
In src/main/resources/passkey-interceptor.js, implement a defineProps helper
that creates an object inheriting from the target WebAuthn prototype with
Object.create and attaches enumerable properties to it with
Object.defineProperties. Use it inside buildAssertionCredential (and
similarly in buildAttestationCredential with
AuthenticatorAttestationResponse.prototype):
function buildAssertionCredential(data) {
const response = defineProps(AuthenticatorAssertionResponse.prototype, {
clientDataJSON: fromBase64Url(data.clientDataJSON),
authenticatorData: fromBase64Url(data.authenticatorData),
signature: fromBase64Url(data.signature),
userHandle: fromBase64Url(data.userHandle)
});
return defineProps(PublicKeyCredential.prototype, {
id: data.id,
rawId: fromBase64Url(data.rawId),
type: data.type,
authenticatorAttachment: data.authenticatorAttachment,
response,
getClientExtensionResults: () => ({}),
toJSON: () => ({ /* WebAuthn Level 3 JSON serialization. */ })
});
}
This satisfies both instanceof checks and binary ArrayBuffer property
reads on the returned credential.
Running the Example
Start the application from passkey-manager/ (or run
./gradlew :passkey-manager:run -Dfuzio.license.key="<your-license-key>" from
the fuzio-examples root):
./gradlew run
PasskeyManagerApp opens webauthn.io inside Fuzio’s
BrowserView.
Enter any username on the page, click Register, and then click Authenticate. Both registration and sign-in complete in Java without triggering operating system dialogs, and the console logs each ceremony:
[Passkey Created] rpId=webauthn.io, credId=r4X8...
[Passkey Signed] rpId=webauthn.io, credId=r4X8..., signCount=1
You can find the complete runnable project in the Gitee repository.
Conclusion
In this tutorial, we built a custom WebAuthn passkey manager for an embedded Java webview using Fuzio:
- We used
InjectJsCallbackto overridenavigator.credentials.create()andnavigator.credentials.get()before page scripts run. - We forwarded WebAuthn options to a
@JsAccessibleJava authenticator that performs EC P-256 key generation andSHA256withECDSAsigning. - We reconstructed
PublicKeyCredential.prototypeobjects in JavaScript so standard relying parties accept the responses without changes.
Add a Chromium-based browser engine to your Java desktop app with Fuzio.
Try for free

