Laragear WebAuthn
repository·5.x·Indexed 19 days ago
https://github.com/laragear/webauthnA Laravel package for authenticating users using Passkeys (WebAuthn), supporting biometric data, fingerprints, and patterns. It provides an Eloquent User Provider driver, a JavaScript helper (@laragear/webpass), and tools for managing attestation and assertion ceremonies. Note: This package is no longer maintained and has been superseded by laravel/passkeys.
What's inside laragear-webauthn
- This package is no longer maintained. It has been superseded by the official implementation: laravel/passkeys. Developers should use the official package for new projects or migrations.
Laravel Octane compatibility
5.xThis package is compatible with Laravel Octane. It does not use singletons that rely on stale application, config, or request instances, and it does not use static properties that are written to during a request.Manually Attest and Assert users
5.xIf you need to perform WebAuthn ceremonies manually (e.g., during user registration), you can use the following pipeline classes:
AttestationCreator: Creates a request to create a WebAuthn Credential.AttestationValidator: Validates a response with the WebAuthn Credential. Note: This instantiates a storable credential but does not save it automatically, allowing you to modify the model before persistence.AssertionCreator: Creates a request to validate a WebAuthn Credential.AssertionValidator: Validates a response for a WebAuthn Credential.
Validation methods no longer require the current
Requestinstance; they accept a JSON array of data. You can use thefromRequest()helper or manually useLaragear\WebAuthn\JsonTransport.Security considerations for WebAuthn implementation
5.xWhen using this WebAuthn implementation, be aware of the following security behaviors:
- Challenge Management: Registration (attestation) and Login (assertion) challenges use the request session by default. Challenges are created with random bytes, retrieved and deleted from the source upon resolution, and expire after 60 seconds.
- Concurrency: Only one ceremony can be performed at a time because ceremonies share the same challenge key.
- User Identity: The WebAuthn User Handle is a UUID v4 and is reused when creating new credentials for the same user.
- Credential Control: Credentials can be blacklisted (enabled/disabled).
- Data Protection: Public Keys are automatically encrypted in the database using the application key.
Add relationships to package models
5.xTo implement relationships between the package models and your own models, follow two steps:
- Register the relationship in the Model: Use
resolveRelationUsing()within thebooted()callback inbootstrap/app.phpto define how the relationship is resolved. - Add the foreign key column in the Migration: Use the
Car::migration()method and pass a callback to add the necessary foreign key column (e.g., usingforeignIdFor()).
// 1. Register relationship in bootstrap/app.php Car::resolveRelationUsing('driver', function (Car $car) { return $car->belongsTo(Driver::class, 'driver_id'); }); // 2. Add column in the migration file return Car::migration(function (Blueprint $table) { $table->foreignIdFor(Driver::class); });- Register the relationship in the Model: Use
Customize package migrations
5.xThe package uses a simplified migration approach where the migration file callsModel::migration(). You can extend this migration to add custom columns, handle relationships, or execute logic during the up/down lifecycle.Customize package Models
5.xYou can modify the default behavior of the package's Models (such as changing the table name, database connection, or hiding attributes) using the
customize()method. This should ideally be done within thebooted()callback in yourbootstrap/app.phpfile. The package migrations will automatically respect any table or connection changes made viacustomize().use Illuminateoundation\ use Illuminate\Foundation\Configuration\Exceptions; use Illuminate\Foundation\Configuration\Middleware; use Vendor\Package\Models\Driver; return Application::configure(basePath: dirname(__DIR__)) ->booted(function () { // Customize the model Car::customize(function (Car $model) { $model->setTable('my_custom_car'); $model->setConnection('readonly-mysql'); $model->setHidden('private_notes'); }); })->create();Configure Laragear WebAuthn settings
5.xYou can override the default WebAuthn configuration by publishing the config file to
config/webauthn.php.It is recommended to use environment variables instead of modifying the config file directly. The configuration includes settings for the Relying Party, allowed origins, and challenge parameters.
php artisan vendor:publish --provider="Laragear\WebAuthn\WebAuthnServiceProvider" --tag="config"Initialize WebAuthn with artisan commands
5.xUse the following commands to publish configuration, routes, and migration files, then apply the migrations to create the necessary table for WebAuthn Credentials (Passkeys).
php artisan webauthn:install php artisan migrateRequirements for laragear/webauthn
5.xEnsure your environment meets the following requirements:
- PHP: 8.3 or later
- Laravel: 12 or later
- Extensions:
ext-openssl(Required)ext-sodium(Optional, for EdDSA 25519 public keys. If unavailable, you can installparagonie/sodium_compat).
Implement a custom WebAuthnChallengeRepository
5.xBy default, challenges are stored in the application Session. To use a different storage mechanism (like Redis or a database) to share challenges across multiple instances, implement the
Laragear\WebAuthn\Contracts\WebAuthnChallengeRepositorycontract.Your implementation must include:
store(Challenge $challenge, AttestationCreation|AssertionCreation $ceremony): voidpull(AttestationValidation|AssertionValidation $ceremony): ?Challenge
Note that
pull()should delete the challenge from the repository once retrieved.namespace App\WebAuthn; use Illuminate\Support\\Facades\\Auth; use Illuminate\Support\\Facades\\Cache; use Illuminate\Support\\Facades\\Request; use Laragear\WebAuthn\\Assertion\\Creator\\AssertionCreation; use Laragear\WebAuthn\\Assertion\\Validator\\AssertionValidation; use Laragear\WebAuthn\\Attestation\\Creator\\AttestationCreation; use Laragear\WebAuthn\\Attestation\\Validator\\AttestationValidation; use Laragear\WebAuthn\\Contracts\WebAuthnChallengeRepository; use Laragear\WebAuthn\\Challenge\Challenge; class MyRepository implements WebAuthnChallengeRepository { /** * Puts a ceremony challenge into the repository. */ public function store(Challenge $challenge, AttestationCreation|AssertionCreation $ceremony): void { Cache::store('redis')->put($this->getFingerprint(), $challenge, $challenge->expiresAt()); } /** * Pulls a ceremony challenge out from the repository, if it exists. */ public function pull(AttestationValidation|AssertionValidation $ceremony): ?Challenge { return Cache::store('redis')->pull($this->getFingerprint()); } /** * Create a fingerprint as a cache key. */ protected function getFingerprint(): string { $user = Auth::user(); // Use the IP, the user class and its auth identifier to build the cache key. return implode('|', [ 'webauthn_challenge', Request::ip(), get_class($user), $user->getAuthIdentifier() ]); } }Install laragear/webauthn via Composer
5.xTo install the WebAuthn package into your Laravel project, use Composer:
composer require laragear/webauthn