imanrjb/jwt-auth

JWT authentication for Lumen and Laravel

v1.1.5 2023-04-26 13:29 UTC

This package is auto-updated.

Last update: 2024-10-26 16:54:19 UTC


README

Latest Version on Packagist GitHub issues GitHub stars GitHub forks Total Downloads GitHub license

⬇️ 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');