Installation
The Symfony UX Initiative enables high-interaction applications directly from Twig templates without writing custom JavaScript. The WebAuthn Stimulus Controller makes implementing passwordless authentication as simple as adding a few Twig functions to your forms.
Prerequisites
Before installing the Stimulus Controller, you need:
Symfony UX configured - Follow the official Symfony UX documentation
WebAuthn Bundle installed - See Symfony Bundle Installation
Installation
Install the WebAuthn Stimulus Controller via Composer:
composer require web-auth/webauthn-stimulusThis command will automatically:
Install the PHP package
Register the Stimulus controller via Symfony Flex
Configure AssetMapper to import the necessary JavaScript files
No build step required! The package works with Symfony AssetMapper, so you don't need Node.js, npm, yarn, or any JavaScript build tools. The browser imports the JavaScript files directly.
Verify Installation
Check that the Stimulus controller is properly registered in your assets/controllers.json:
What's Included
The package provides Stimulus controllers that handle:
Registration flows - Calls
navigator.credentials.create()for youAuthentication flows - Calls
navigator.credentials.get()for youBase64 encoding/decoding - Automatically handles data conversion
Error handling - Gracefully handles common WebAuthn errors
Browser autofill - Supports conditional UI for passkey selection
Conditional create (v5.3.0+) - Enhanced conditional UI support for both registration and authentication
PRF extension - Built-in support for the Pseudo-Random Function extension
Enhanced in v5.3.0: The Stimulus package now provides three controllers:
@web-auth/webauthn-stimulus- Combined controller (legacy, still supported)@web-auth/webauthn-stimulus/authentication- Dedicated authentication controller@web-auth/webauthn-stimulus/registration- Dedicated registration controller
The dedicated controllers offer better separation of concerns, enhanced conditional UI support, and improved error handling. The combined controller remains available for backward compatibility.
Basic Usage
Once installed, you can use the Stimulus controller in your Twig templates with two simple functions:
stimulus_controller()- Attach the controller to your formstimulus_action()- Trigger WebAuthn operations on button clicks
Registration Form Example
Authentication Form Example
Controller Options
The Stimulus controller accepts various configuration options:
Registration Options
creationOptionsUrl
string
Yes
URL endpoint that returns PublicKeyCredentialCreationOptions
creationResultField
string
Yes
CSS selector for hidden field to store attestation response
Authentication Options
requestOptionsUrl
string
Yes
URL endpoint that returns PublicKeyCredentialRequestOptions
requestResultField
string
Yes
CSS selector for hidden field to store assertion response
useBrowserAutofill
boolean
No
Enable conditional UI for browser autofill (default: false)
Testing Your Installation
Create a simple test page to verify everything works:
Troubleshooting
Controller Not Found
If you see "Controller '@web-auth/webauthn-stimulus' not found":
Verify
assets/controllers.jsonincludes the controller with"enabled": trueClear Symfony cache:
php bin/console cache:clearCheck that AssetMapper is properly configured in
config/packages/asset_mapper.yaml
JavaScript Errors
If you see console errors:
Ensure you're using HTTPS (required for WebAuthn)
Check browser console for specific error messages
Verify WebAuthn routes are properly configured in
config/routes/webauthn.yamlEnsure the controller is loaded by checking the browser's network tab
Assets Not Loading
If the Stimulus controller doesn't load:
Verify your base template includes the AssetMapper importmap:
Check that Stimulus is properly configured in your application
HTTPS Requirement
WebAuthn requires HTTPS to function. For development, use the Symfony CLI for automatic HTTPS:
For production, ensure HTTPS is properly configured on your web server.
Next Steps
Now that the Stimulus Controller is installed, proceed to:
User Registration - Create registration forms
User Authentication - Implement login flows
Additional Authenticators - Allow users to register backup devices
See Also
Symfony UX Documentation - Official UX guide
Stimulus Documentation - Stimulus framework reference
WebAuthn Bundle - Backend configuration
JavaScript Integration - Manual JavaScript implementation
Last updated
Was this helpful?