biokey-js) provides a simple API for implementing passwordless authentication using WebAuthn and biometric sensors.
Installation
Basic Usage
Initialize the Client
Create a newBioKeyClient instance with your configuration:
rpId- Relying Party ID (your domain). Defaults tolocation.hostnamerpName- Display name shown during biometric prompts. Defaults to'BioKey'serverUrl- Optional server URL for syncing credentials across devices. Set tonullfor offline-only mode
Complete Authentication Flow
Enroll a new user
When a user first signs up or enables biometric authentication:The browser will prompt the user to use their biometric sensor (Face ID, Touch ID, Windows Hello, etc.).
Complete Example
Here’s a full working example with UI:API Reference
Constructor
Methods
enroll(userId)
Enrolls a new credential for the user. Returns a Promise that resolves to an identity object.
Parameters:
userId(string, optional) - Unique identifier for the user. If omitted, a random ID is generated.
authenticate(userId)
Authenticates the user using their enrolled credential.
Parameters:
userId(string, optional) - User identifier. Required if using server mode.
getIdentity()
Returns the currently enrolled identity from local storage, or null if not enrolled.
clearIdentity()
Removes the enrolled credential from local storage.
Key Derivation Methods
BioKey automatically selects the best available method:- PRF Extension (preferred) - Uses the WebAuthn PRF extension for deterministic key derivation
- RawId HKDF (fallback) - Uses HKDF on the credential’s rawId for older platforms
Error Handling
Common errors and how to handle them:Browser Compatibility
BioKey requires:- WebAuthn API support
- Platform authenticator (biometric sensor)
- HTTPS (required by WebAuthn)
- iOS/iPadOS with Face ID or Touch ID
- macOS with Touch ID
- Android with fingerprint sensor
- Windows with Windows Hello
Next Steps
React Integration
Use the React hook for simpler integration
Server Setup
Set up the server for multi-device sync
Offline Mode
Build without a backend server
API Reference
Full API documentation