### Install Passkeys for Laravel via Composer and publish migrations Source: https://github.com/roundly-consulting/passkeys-for-laravel/blob/main/README.md Install the package with Composer, publish the migrations, and run them. Requires PHP 8.4 (ext-json; ext-sodium for EdDSA) and Laravel 12 or 13. Set PASSKEYS_ORIGINS before use; set PASSKEYS_KEY_TYPE before migrating if using UUID/ULID keys. ```bash composer require roundly-consulting/passkeys-for-laravel php artisan vendor:publish --tag="passkeys-migrations" php artisan migrate ``` -------------------------------- ### Sign in with passkey: authentication options and verify Source: https://github.com/roundly-consulting/passkeys-for-laravel/blob/main/README.md Generate authentication options, verify the browser's response, and log the user in. Uses AuthenticationResponseData and navigator.credentials.get() with parseRequestOptionsFromJSON(). ```php use RoundlyConsulting\Passkeys\DataTransferObjects\AuthenticationResponseData; return response()->json(Passkeys::authenticationOptions()); $passkey = Passkeys::authenticate(AuthenticationResponseData::fromArray($request->all())); Auth::login($passkey->authenticatable); ``` -------------------------------- ### Register a passkey: return options and verify browser response Source: https://github.com/roundly-consulting/passkeys-for-laravel/blob/main/README.md Generate registration options for a user and verify the browser's response. The register method accepts RegistrationResponseData and a name for the passkey. ```php use RoundlyConsulting\Passkeys\DataTransferObjects\RegistrationResponseData; use RoundlyConsulting\Passkeys\Facades\Passkeys; return response()->json(Passkeys::for($user)->registrationOptions()); $passkey = Passkeys::for($user)->register( RegistrationResponseData::fromArray($request->all()), name: 'MacBook Touch ID', ); ``` -------------------------------- ### Browser JavaScript for passkey registration ceremony Source: https://github.com/roundly-consulting/passkeys-for-laravel/blob/main/README.md Fetch registration options, create a credential with navigator.credentials.create(), and POST the credential with the ceremonyId. Uses PublicKeyCredential.parseCreationOptionsFromJSON(). ```javascript const options = await (await fetch('/passkeys/options')).json(); const credential = await navigator.credentials.create({ publicKey: PublicKeyCredential.parseCreationOptionsFromJSON(options.publicKey), }); await fetch('/passkeys', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ ...credential.toJSON(), ceremonyId: options.ceremonyId }) }); ``` -------------------------------- ### Add HasPasskeys contract and passkeyUserHandle column to User model Source: https://github.com/roundly-consulting/passkeys-for-laravel/blob/main/README.md Implement the HasPasskeys contract on the user model and add the passkey user handle column in a migration. The migration uses the passkeyUserHandle() Blueprint method. ```php use RoundlyConsulting\Passkeys\Concerns\InteractsWithPasskeys; use RoundlyConsulting\Passkeys\Contracts\HasPasskeys; final class User extends Authenticatable implements HasPasskeys { use InteractsWithPasskeys; } // in a migration Schema::table('users', fn (Blueprint $table) => $table->passkeyUserHandle()); ```