This package has been superseded by laravel/passkeys
This package is no longer maintained due to an official implementation.
WebAuthn
Authenticate users with Passkeys: fingerprints, patterns and biometric data.
// App\Http\Controllers\LoginController.php
use Laragear\WebAuthn\Http\Requests\AssertedRequest;
public function login(AssertedRequest $request)
{
$user = $request->login();
return response()->json(['message' => "Welcome back, $user->name!"]);
}
[!TIP]
You want to add two-factor authentication to your app? Check out Laragear TwoFactor.
Become a sponsor

Your support allows me to keep this package free, up-to-date and maintainable. Alternatively, you can spread the word on social media!
Requirements
- PHP 8.3 or later
- Laravel 12 or later
- The
ext-openssl extension.
- The
ext-sodium extension (optional, for EdDSA 25519 public keys).
[!TIP]
If you can't enable the ext-sodium extension for whatever reason, you may try installing paragonie/sodium_compat.
Installation
Require this package into your project using Composer:
composer require laragear/webauthn
How Passkeys work?
Passkeys, hence WebAuthn, consists in two ceremonies: attestation, and assertion.
Attestation is the process of asking the authenticator (a phone, laptop, USB key...) to create a private-public key pair, save the private key internally, and store the public key inside your app. For that to work, the browser must support WebAuthn, which is what intermediates between the authenticator (OS & device hardware) and the server.
Assertion is the process of pushing a cryptographic challenge to the authenticator, which will return back to the server signed by the private key of the device. Upon arrival, the server checks the signature is correct with the stored public key, ready to log in.
The private key doesn't leave the authenticator, there are no shared passwords stored anywhere, and Passkeys only work on the server domain (like google.com) or subdomain (like auth.google.com).
Set up
We need to make sure your users can register their devices and authenticate with them.
- Add the WebAuthn driver
- Publish the files and migrate
- Implement the contract and trait
- Register the controllers (optional)
- Use the Javascript helper (optional)
1. Add the WebAuthn driver
Laragear WebAuthn works by extending the Eloquent User Provider with a simple additional check to find a user for the given WebAuthn Credentials (Assertion). This makes this WebAuthn package compatible with any guard you may have.
Simply go into your auth.php configuration file, change the driver from eloquent to eloquent-webauthn, and add the password_fallback to true.
return [
// ...
'providers' => [
'users' => [
'driver' => 'eloquent-webauthn',
'model' => App\User::class,
'password_fallback' => true,
],
]
];
The password_fallback indicates the User Provider should fall back to validate the password when the request is not a WebAuthn Assertion. It's enabled to seamlessly use both classic (password) and WebAuthn authentication procedures.
2. Publish files and migrate
With the single webauthn:install command, you can install the configuration, routes, and migration files.
php artisan webauthn:install
This will also publish a migration file needed to create a table to hold the WebAuthn Credentials (Passkeys). Once ready, migrate your application to create the table.
php artisan migrate
[!TIP]
You can modify the migration if you need to, like changing the table name.
3. Implement the contract and trait
Add the WebAuthnAuthenticatable contract and the WebAuthnAuthentication trait to the User class, or any other that uses authentication.
<?php
namespace App;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Laragear\WebAuthn\Contracts\WebAuthnAuthenticatable;
use Laragear\WebAuthn\WebAuthnAuthentication;
class User extends Authenticatable implements WebAuthnAuthenticatable
{
use WebAuthnAuthentication;
// ...
}
From here you're ready to work with WebAuthn Authentication. The following steps will help you close the gap to a full implementation.
4. Register the routes and controllers
WebAuthn uses exclusive routes to register and authenticate users. Creating these routes and controller may be cumbersome, specially if it's your first time in the WebAuthn realm, so these are installed automatically at Http\Controllers\WebAuthn when using webauthn:install.
Go into your web.php routes file and register a default set of routes with the \Laragear\WebAuthn\Http\Routes::register() method. Since WebAuthn doesn't require protection for CSRF/XSRF tokens, you may disable it for these routes.
// web.php
use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken;
use Illuminate\Support\Facades\Route;
use Laragear\WebAuthn\Http\Routes as WebAuthnRoutes;
Route::view('welcome');
// WebAuthn Routes
WebAuthnRoutes::register()->withoutMiddleware(VerifyCsrfToken::class);
[!TIP]
The @laragear/webpass javascript helper supports adding CSRF/XSRF tokens manually.
The method allows to use different attestation and assertion paths, and even each of the controllers.
use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken;
use Laragear\WebAuthn\Http\Routes as WebAuthnRoutes;
WebAuthnRoutes::register(
attest: 'auth/register',
assert: 'auth/login'
)->withoutMiddleware(VerifyCsrfToken::class);
[!NOTE]
You can also delete the controllers and implement attestation and assertion manually.
5. Use the Javascript helper
This package original Javascript helper has been moved into its own package, called @laragear/webpass. You may use directly in your HTML application by just using JSDelivr CDN:
<head>
<script src="https://cdn.jsdelivr.net/npm/@laragear/webpass@2/dist/webpass.js" defer></script>
</head>
<body>
<script async>
if (Webpass.isUnsupported()) {
alert("Your browser doesn't support WebAuthn.")
}
const { success } = await Webpass.attest("/webauthn/register/options", "/webauthn/register")
if (success) {
window.location.replace("/dashboard")
}
</script>
</body>
Alternatively, you may want to include it in your project dependencies if you're using a frontend framework like Vue, React, Angular or Svelte, to name a few.
npm i @laragear/webpass@2
Once done, you may attest and assert the authenticator using the Webpass object:
import Webpass from "@laragear/webpass"
if (Webpass.isUnsupported()) {
return alert("Your browser doesn't support WebAuthn.")
}
// Create new credentials for a logged in user
const { credential, success, error } = await Webpass.attest("/webauthn/register/options", "/webauthn/register")
// Check the credentials for a guest user
const { user, success, error } = await Webpass.assert("/webauthn/login/options", "/webauthn/login")
The Webpass helper offers more flexibility than just adjusting the WebAuthn ceremony paths. For more information, check the documentation of @laragear/webpass.
Attestation
Attestation is the ceremony to create WebAuthn Credentials. To create an Attestable Response that the user device can understand, use the AttestationRequest::toCreate() form request.
For example, we can create our own WebAuthnRegisterController to create it.
// app\Http\Controllers\WebAuthn\WebAuthnRegisterController.php
use Laragear\WebAuthn\Http\Requests\AttestationRequest;
public function createChallenge(AttestationRequest $request)
{
return $request->toCreate();
}
The device will receive the "instructions" to make a key, and will respond with it. You can use the AttestedRequest form request and its save() method to persist the WebAuthn key if it is valid. The request will automatically return a Validation exception if something fails.
// app\Http\Controllers\WebAuthn\WebAuthnRegisterController.php
use Laragear\WebAuthn\Http\Requests\AttestedRequest;
public function register(AttestedRequest $attestation)
{
$attestation->save();
return 'Now you can login without passwords!';
}
You may pass an array, or a callback, to the save(), which will allow you to modify the underlying WebAuthn Eloquent Model before saving it. For example, we could add an alias for the key present in the Request data.
// app\Http\Controllers\WebAuthn\WebAuthnRegisterController.php
use Laragear\WebAuthn\Http\Requests\AttestedRequest;
public function register(AttestedRequest $request)
{
$request->validate(['alias' => 'nullable|string']);
$attestation->save($request->only('alias'));
// Same as:
// $attestation->save(function ($credentials) use ($request) {
// $credentials->alias = $request->input('alias');
// })
}
[!IMPORTANT]
Both AttestationRequest and AttestedRequest require the authenticated user. If the user is not authenticated, an HTTP 403 status code will be returned. You may want to temporarily log in the user, or attest manually.
Attestation User verification
By default, the authenticator decides how to verify user when creating a credential. Some may ask to press a "Continue" button to confirm presence, others will verify the User with biometrics, patterns or passwords.
You can override this using fastRegistration() to only check for user presence if possible, or secureRegistration() to actively verify the User.
// app\Http\Controllers\WebAuthn\WebAuthnRegisterController.php
use Laragear\WebAuthn\Http\Requests\AttestationRequest;
public function createChallenge(AttestationRequest $request)
{
return $request->fastRegistration()->toCreate();
}
Userless/One-touch/Typeless Login
When asking to create a credential, the server will tell the authenticator to prefer resident keys, which saves the "Username ID" of the credential inside itself. This is what enables one click/tap login, without the need to specify the user credentials (like the email) beforehand.
If you want this to be mandatory, use the userless() method of the AttestationRequest form request.
// app\Http\Controllers\WebAuthn\WebAuthnRegisterController.php
use Laragear\WebAuthn\Http\Requests\AttestationRequest;
public function registerDevice(AttestationRequest $request)
{
return $request->userless()->toCreate();
}
Once the Resident Key is created, the authenticator will be able to find the correct credential for your web application by finding which credentials match your Relaying Party ID (like my-app.com), and show the user these credentials. This effectively eliminates the step of the user sending its username or email so the server can return which credentials ID the authenticator should use.
[!IMPORTANT]
The Authenticator WILL require user verification on login when using userless(). It's highly probable the user will also be asked for user verification on login.
Multiple credentials per device
By default, during Attestation, the device will be informed about the existing enabled credentials already registered in the application. This way the device can avoid creating another one for the same purpose.
You can enable multiple credentials per device using allowDuplicates(), which in turn will always return an empty list of credentials to exclude. This way the authenticator will think there are no already stored credentials for your app, and create a new one.
// app\Http\Controllers\WebAuthn\WebAuthnRegisterController.php
use Laragear\WebAuthn\Http\Requests\AttestationRequest;
public function registerDevice(AttestationRequest $request)
{
return $request->allowDuplicates()->make();
}
Custom name and display name
The application will use the user email as "name" and his name as "display name". Regardless of how authenticators will show it to the user, you may change these at runtime by using a callback. The callback will receive the user instance and a boolean if the attestation uses unique credentials, and should return an instance of Laragear\WebAuthn\WebAuthnData.