WebAuthn authentication package for Laravel 12 using Livewire
scriptoshi/livewire-webauthn is a Laravel package for webauthn authentication package for laravel 12 using livewire.
It currently has 1 GitHub stars and 19 downloads on Packagist (latest version 1.0.2).
Install it with composer require scriptoshi/livewire-webauthn.
Discover more Laravel packages by scriptoshi
or browse all Laravel packages to compare alternatives.
Last updated
A modern WebAuthn (FIDO2) authentication package for Laravel 12 using Livewire and Flux components. Enables passwordless and two-factor authentication using security keys, biometrics, and mobile devices.
Laravel Livewire WebAuthn provides an easy way to integrate WebAuthn (Web Authentication) capabilities into your Laravel 12 application. Built with Livewire and Flux components, it offers a modern, interactive user experience with minimal configuration.
composer require scriptoshi/livewire-webauthn
php artisan vendor:publish --provider="Scriptoshi\LivewireWebauthn\WebAuthnServiceProvider" --tag="config"
php artisan vendor:publish --provider="Scriptoshi\LivewireWebauthn\WebAuthnServiceProvider" --tag="views"
php artisan vendor:publish --provider="Scriptoshi\LivewireWebauthn\WebAuthnServiceProvider" --tag="migrations"
This will add the required columns to your users table and create the credentials table.
php artisan migrate
use Scriptoshi\LivewireWebauthn\Traits\WebAuthnAuthenticatable;
class User extends Authenticatable
{
use WebAuthnAuthenticatable;
// ...
}
The package comes with sensible defaults, but you can customize it using the corresponding .env variables.
Add the following lines to your .env to customize the configuration:
# Enable or disable WebAuthn functionality entirely
WEBAUTHN_ENABLED=true
# Relying party name (shown to users during authentication)
WEBAUTHN_RP_NAME="${APP_NAME}"
# Relying party ID (usually your domain name)
WEBAUTHN_RP_ID="${APP_URL}"
# Table name for WebAuthn credentials
WEBAUTHN_CREDENTIALS_TABLE=webauthn_credentials
# Timeout for WebAuthn verification (in seconds, default 15 minutes)
WEBAUTHN_TIMEOUT=900
# Attestation conveyance preference (none, indirect, direct, enterprise)
WEBAUTHN_ATTESTATION_CONVEYANCE=none
# User verification requirement (required, preferred, discouraged)
WEBAUTHN_USER_VERIFICATION=preferred
Add the middleware to intercept your login logic. Note: this is the route for POST when users submit the login form. In volt components this route is missing !.
routes/web.php:use Scriptoshi\LivewireWebauthn\Http\Middleware\WebAuthn;
// Intercept login attempts and handle WebAuthn if needed
Route::post('/login', [AuthenticatedSessionController::class, 'store'])
->middleware(['guest', WebAuthn::class])
->name('login');
Add the Livewire component to your user profile or settings page:
<livewire:webauthn-management />
With Laravel 12 Starter Kit, you can add a new section for WebAuthn management:
resources/views/components/settings/layout.blade.php to add the menu item:<flux:navlist>
<flux:navlist.item :href="route('settings.profile')" wire:navigate>{{ __('Profile') }}</flux:navlist.item>
<flux:navlist.item :href="route('settings.password')" wire:navigate>{{ __('Password') }}</flux:navlist.item>
<flux:navlist.item :href="route('settings.appearance')" wire:navigate>{{ __('Appearance') }}</flux:navlist.item>
<!-- Add WebAuthn -->
<flux:navlist.item :href="route('settings.webauthn')" wire:navigate>{{ __('Security Keys') }}</flux:navlist.item>
</flux:navlist>
resources/views/livewire/settings/webauthn.blade.php<?php
use Livewire\Volt\Component;
new class extends Component {
}; ?>
<section class="w-full">
@include('partials.settings-heading')
<x-settings.layout :heading="__('Security Keys')" :subheading="__('Manage security keys and biometric devices')">
<livewire:webauthn-management />
</x-settings.layout>
</section>
routes/web.php:Volt::route('settings/webauthn', 'settings.webauthn')->name('settings.webauthn');
That's it! The component will handle registering, managing, and using WebAuthn credentials.
To ensure that Tailwind CSS properly processes the component styles, add this package to your content sources in your CSS file (typically resources/css/app.css):
/* Add this line with your other @source directives */
@source '../../vendor/scriptoshi/livewire-webauthn/resources/views/**/*.blade.php';
For example, your CSS file might look similar to this:
@import "tailwindcss";
@source "../views";
@source '../../vendor/laravel/framework/src/Illuminate/Pagination/resources/views/*.blade.php';
@source '../../vendor/scriptoshi/livewire-webauthn/resources/views/**/*.blade.php';
/* Rest of your CSS file */
For enhanced security, you can require WebAuthn confirmation for sensitive operations. This is similar to password confirmation but uses a security key or biometric instead. You can then call call $this->ensureWebAuthnIsConfirmed(); before performing any critical actions.
use Scriptoshi\LivewireWebauthn\Traits\ConfirmsWebAuthn;
class AdminSettings extends Component
{
use ConfirmsWebAuthn; // include the Trait
/**
* Enable administration mode for user.
*/
public function enableAdminMode(): void
{
$this->ensureWebAuthnIsConfirmed();
// Critical operation code here...
}
}
<x-confirms-webauthn wire:then="enableAdminMode">
<flux:button type="button" wire:loading.attr="disabled">
{{ __('Enable Admin Mode') }}
</flux:button>
</x-confirms-webauthn>
You can use the WebAuthn facade directly for advanced use cases:
use Scriptoshi\LivewireWebauthn\Facades\WebAuthn;
// Generate registration options
$options = WebAuthn::generateRegistrationOptions($user);
// Verify a WebAuthn response
$result = WebAuthn::verifyRegistrationResponse($response, $options, $user, 'My Security Key');
// Generate authentication options
$authOptions = WebAuthn::generateAuthenticationOptions($user);
// Verify authentication response
$authenticatedUser = WebAuthn::verifyAuthenticationResponse($response, $authOptions, $user);
The package dispatches Livewire events that you can listen for:
webauthn-registration-started - When registration beginswebauthn-credential-registered - When a credential is registeredwebauthn-credential-removed - When a credential is removedwebauthn-authentication-started - When authentication beginswebauthn-confirmed - When WebAuthn verification is confirmedUse these events in your Livewire components to respond to WebAuthn actions.
The package includes all necessary JavaScript for interacting with the WebAuthn API. The included functions handle:
WebAuthn is supported in all major modern browsers:
Mobile support:
WebAuthn requires HTTPS in production. For local development, localhost is considered a secure context by most browsers.
Contributions are welcome! Please feel free to submit a pull request.
This package is open-sourced software licensed under the MIT license.