imanrjb / jwt-auth
JWT authentication for Lumen and Laravel
v1.1.5
2023-04-26 13:29 UTC
Requires
- firebase/php-jwt: ^6.3
- stevebauman/location: ^6.5
README
⬇️ How to install and config imanrjb/jwt-auth package?
Install package
composer require imanrjb/jwt-auth
Config package
// Add this lines in "App\Providers\AuthServiceProvider" public function boot(): void { $this->app['auth']->viaRequest('api', function ($request) { $token = $request->bearerToken(); if($token) { return AccessToken::checkToken($token); } return; }); }
// Change the "config/auth.php" file 'defaults' => [ 'guard' => 'api', 'passwords' => 'users', ], 'guards' => [ 'web' => [ 'driver' => 'session', 'provider' => 'users', ], 'api' => [ 'driver' => 'api', 'provider' => 'users', ], ],
# Add this items to .env file JWT_SECRET=GKPMVOCKpMHHJQ3GprVA0EfTKGJi7227mjeKN009Vndls70226raawkRzDoB97AI ACCESS_TOKEN_LIFETIME=120 REFRESH_TOKEN_LIFETIME=1200
📖 How to use in routes as middleware
Route::get('user', function () { return auth()->user(); })->middleware('auth:api');