STING Passkey Implementation Guide
This guide provides detailed instructions for implementing WebAuthn/passkey authentication in your STING application. It covers both frontend and backend setup, troubleshooting steps, and testing procedures.
Overview
Passkeys (based on the WebAuthn standard) provide a modern, phishing-resistant authentication method that works across devices using biometrics or device PINs. This implementation:
- Supports registration with passkeys as a second factor
- Prioritizes passkey login while maintaining password fallback
- Works with the standard Kratos configuration
Prerequisites
Before implementing passkeys:
- STING must be installed and running (including Kratos authentication)
- Frontend must be running on HTTPS (localhost is fine for testing)
- Self-signed certificates should be properly configured
- WebAuthn API must be supported by your browser
Implementation Steps
1. Frontend Components Setup
Add Authentication Components
Copy these React components to your
frontend/src/components/authdirectory:DirectPasskeyRegistration.jsx- Password registration with passkey setupDirectPasskeyLogin.jsx- WebAuthn-first login with password fallbackDebugPage.jsx- Testing and troubleshooting page
Update Routes
Update your
AppRoutes.jsfile to include the new components:import DirectPasskeyRegistration from './components/auth/DirectPasskeyRegistration'; import DirectPasskeyLogin from './components/auth/DirectPasskeyLogin'; // Inside your Routes component <Route path="/login" element={<DirectPasskeyLogin />} /> <Route path="/register" element={<DirectPasskeyRegistration />} /> <Route path="/debug" element={<DebugPage />} />Add Passkey Test Page
Create a standalone HTML page at
frontend/public/passkey-test.htmlto directly test WebAuthn browser support.
2. Kratos Configuration
The standard Kratos configuration already supports WebAuthn, but we need to ensure it’s properly enabled:
Check Schema Configuration
Make sure your
identity.schema.jsonincludes WebAuthn as a credential type:"credentials": { "password": { "identifier": true }, "webauthn": { "identifier": true } }Enable WebAuthn in Kratos Config
In
kratos.ymlor equivalent configuration file:selfservice: methods: webauthn: enabled: true config: rp: id: localhost display_name: STING Authentication origins: - https://localhost:8443 - https://localhost:4433 passwordless: true
3. Testing and Verifying
Browser Support Check
Visit
/passkey-test.htmlto verify your browser supports WebAuthn.Registration Flow
- Visit
/registerto start the registration flow - Create an account with email and password
- Set up a passkey when prompted
- Verify the account creation and passkey setup in logs
- Visit
Login Flow
- Visit
/loginto start the login flow - Verify passkey login is offered first
- Try both passkey and password login
- Visit
Debugging
Visit
/debugto:- Check Kratos connection status
- View authentication status
- Try individual authentication flows
How It Works
Registration Process
The registration flow happens in two steps:
Account Creation
The user creates an account with email and password (required by Kratos).
Passkey Setup
After account creation, the component starts a settings flow to add a WebAuthn credential:
- Retrieves the WebAuthn registration trigger
- Executes the WebAuthn flow, prompting for biometrics
- Registers the credential with Kratos
Login Process
The login flow attempts WebAuthn first:
WebAuthn Detection
Component checks if WebAuthn is supported by the browser.
WebAuthn Login
If supported, offers passkey login as the primary option:
- Retrieves WebAuthn login trigger from Kratos
- Executes the trigger to start authentication
- Prompts for biometric verification
Password Fallback
If WebAuthn is not available or fails, offers password login.
Common Issues and Solutions
Email Verification Issues
Email verification emails should be sent by Kratos to your configured mail service (e.g., Mailpit).
Checking Mailpit:
- Access the Mailpit UI at
https://localhost:8025 - Look for verification emails there
WebAuthn Not Working
If WebAuthn isn’t working:
- Verify browser support with
/passkey-test.html - Check for console errors during WebAuthn operations
- Ensure you’re using HTTPS (required for WebAuthn)
- Check Kratos logs for WebAuthn-related errors
Dashboard Integration Issues
If dashboard doesn’t appear after authentication:
- Check browser console for errors
- Verify the
localStorageuser object is being set - Check Kratos session status in the debug page
- Try enabling the mock user in
MainInterface.js
Advanced Configuration
Multiple Domains
To support multiple domains (e.g., production and staging):
webauthn:
# ...
config:
rp:
origins:
- https://app.example.com
- https://staging.example.com
Custom Registration Flow
To customize the registration experience:
- Modify
DirectPasskeyRegistration.jsxto include additional fields - Update the payload in
submitPasswordRegistrationfunction - Adjust the UI elements to match your design
Security Considerations
- Secure Context: WebAuthn only works in secure contexts (HTTPS or localhost)
- Recovery Options: Always provide alternative recovery methods
- Password Fallback: Maintain password login as fallback
- Session Management: Configure appropriate session lifetimes
Resources
- WebAuthn.io - Test and learn about WebAuthn
- Ory Kratos Documentation
- W3C WebAuthn Specification
- Web Authentication API - MDN
This guide provides a comprehensive overview of implementing WebAuthn/passkey authentication in STING. For specific issues or customizations, refer to the browser console logs and Kratos documentation.