Skip to content

Commit 3e5eaa2

Browse files
authored
docs: update README with Laravel 11 style (#483)
1 parent 053e391 commit 3e5eaa2

File tree

1 file changed

+46
-46
lines changed

1 file changed

+46
-46
lines changed

README.md

Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,11 @@ Webauthn adapter for Laravel <!-- omit in toc -->
1010

1111
- [Features](#features)
1212
- [Installation](#installation)
13-
- [psr/http-factory-implementation](#psrhttp-factory-implementation)
1413
- [Configuration](#configuration)
1514
- [Set Up](#set-up)
16-
- [Add LaravelWebauthn middleware](#add-laravelwebauthn-middleware)
17-
- [Login via remember](#login-via-remember)
18-
- [Passwordless authentication](#passwordless-authentication)
15+
- [Option 1: add LaravelWebauthn middleware](#option-1-add-laravelwebauthn-middleware)
16+
- [Login via remember](#login-via-remember)
17+
- [Option 2: Passwordless authentication](#option-2-passwordless-authentication)
1918
- [Disabling Views](#disabling-views)
2019
- [Cache](#cache)
2120
- [Usage](#usage)
@@ -54,14 +53,6 @@ Install this package with:
5453
composer require asbiin/laravel-webauthn
5554
```
5655

57-
## psr/http-factory-implementation
58-
59-
You'll need a [`psr/http-factory-implementation` implementation](https://packagist.org/providers/psr/http-factory-implementation):
60-
61-
We recommend using `guzzlehttp/psr7`, which is installed by `guzzlehttp/guzzle`, so you probably already have it.
62-
63-
You can use any other [`psr/http-factory-implementation` implementation](https://packagist.org/providers/psr/http-factory-implementation), like `nyholm/psr7` (this one also requires `symfony/psr-http-message-bridge` and `php-http/discovery`)
64-
6556
## Configuration
6657

6758
You can publish LaravelWebauthn configuration in a file named `config/webauthn.php`, and resources using the `vendor:publish` command:
@@ -79,48 +70,48 @@ php artisan migrate
7970

8071
# Set Up
8172

82-
## Add LaravelWebauthn middleware
73+
## Option 1: add LaravelWebauthn middleware
8374

8475
The Webauthn middleware will force the user to authenticate their webauthn key for certain routes.
8576

86-
Add this in the `$routeMiddleware` array of your `app/Http/Kernel.php` file:
77+
Assign the middleware to a route or a group of routes:
8778

8879
```php
89-
'webauthn' => \LaravelWebauthn\Http\Middleware\WebauthnMiddleware::class,
90-
```
80+
use LaravelWebauthn\Http\Middleware\WebauthnMiddleware;
9181

92-
You can use this middleware in your `routes.php` file:
93-
```php
94-
Route::middleware(['auth', 'webauthn'])->group(function () {
95-
Route::get('/home', 'HomeController@index')->name('home');
82+
Route::get('/home', function () {
9683
// ...
97-
}
84+
})->middleware(WebauthnMiddleware::class);
9885
```
9986

10087
The Webauthn middleware will redirect the user to the webauthn login page when required.
10188

10289

103-
## Login via remember
90+
### Login via remember
10491

105-
When session expires, but the user have set the `remember` cookie, you can revalidate webauthn session by adding this in your `App\Providers\EventServiceProvider` file:
92+
When session expires, but the user have set the `remember` cookie, you can revalidate webauthn session by subscribing to the `LaravelWebauthn\Listeners\LoginViaRemember` listener:
10693

10794
```php
108-
use Illuminate\Auth\Events\Login;
109-
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
110-
use LaravelWebauthn\Listeners\LoginViaRemember;
95+
use Illuminate\Support\Facades\Event;
96+
use Illuminate\Support\ServiceProvider;
11197

112-
class EventServiceProvider extends ServiceProvider
98+
class AppServiceProvider extends ServiceProvider
11399
{
114-
protected $listen = [
115-
Login::class => [
116-
LoginViaRemember::class,
117-
],
118-
];
100+
/**
101+
* Bootstrap any application services.
102+
*/
103+
public function boot(): void
104+
{
105+
Event::listen(
106+
\Illuminate\Auth\Events\Login::class,
107+
\LaravelWebauthn\Listeners\LoginViaRemember::class
108+
);
109+
}
119110
}
120111
```
121112

122113

123-
## Passwordless authentication
114+
## Option 2: Passwordless authentication
124115

125116
You can use Webauthn to authenticate a user without a password, using only a webauthn key authentication.
126117

@@ -302,7 +293,10 @@ use Illuminate\Support\ServiceProvider;
302293
303294
class AppServiceProvider extends ServiceProvider
304295
{
305-
public function register()
296+
/**
297+
* Register any application services.
298+
*/
299+
public function register(): void
306300
{
307301
Webauthn::ignoreRoutes();
308302
}
@@ -337,22 +331,25 @@ Webauthn::authenticateThrough(fn (Request $request) => array_filter([
337331

338332
By default, Laravel Webauthn will throttle logins to five requests per minute for every email and IP address combination. You may specify a custom rate limiter with other specifications.
339333

340-
First define a custom rate limiter. Follow [Laravel rate limiter documentation](https://laravel.com/docs/9.x/routing#defining-rate-limiters) to create a new RateLimiter within the `configureRateLimiting` method of your application's `App\Providers\RouteServiceProvider` class.
334+
First define a custom rate limiter. Follow [Laravel rate limiter documentation](https://laravel.com/docs/11.x/routing#defining-rate-limiters) to create a new RateLimiter within the `boot` method of your application's `App\Providers\AppServiceProvider` class.
341335

342336
```php
343337
use Illuminate\Cache\RateLimiting\Limit;
338+
use Illuminate\Http\Request;
344339
use Illuminate\Support\Facades\RateLimiter;
340+
use Illuminate\Support\ServiceProvider;
345341
346-
/**
347-
* Configure the rate limiters for the application.
348-
*
349-
* @return void
350-
*/
351-
protected function configureRateLimiting()
342+
class AppServiceProvider extends ServiceProvider
352343
{
353-
RateLimiter::for('webauthn-login', function (Request $request) {
354-
return Limit::perMinute(1000);
355-
});
344+
/**
345+
* Bootstrap any application services.
346+
*/
347+
protected function boot(): void
348+
{
349+
RateLimiter::for('webauthn-login', function (Request $request) {
350+
return Limit::perMinute(1000);
351+
});
352+
}
356353
}
357354
```
358355

@@ -379,14 +376,17 @@ Events are dispatched by LaravelWebauthn:
379376

380377
You can easily change the view responses with the Webauthn service.
381378

382-
For instance, call `Webauthn::loginViewResponseUsing` in your `AppServiceProvider`:
379+
For instance, call `Webauthn::loginViewResponseUsing` in your `App\Providers\AppServiceProvider` class:
383380

384381
```php
385382
use LaravelWebauthn\Services\Webauthn;
386383
387384
class AppServiceProvider extends ServiceProvider
388385
{
389-
public function register()
386+
/**
387+
* Register any application services.
388+
*/
389+
public function register(): void
390390
{
391391
Webauthn::loginViewResponseUsing(LoginViewResponse::class);
392392
}

0 commit comments

Comments
 (0)