yaroslawww / laravel-jwt-auth
This package is abandoned and no longer maintained.
The author suggests using the think.studio/laravel-jwt-auth package instead.
Another laravel jwt auth package.
3.3.0
2023-09-10 07:39 UTC
Requires
- php: ^8.1
- firebase/php-jwt: ^6.8
- illuminate/support: ^9.0|^10.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.25
- orchestra/testbench: ^8.10
- phpunit/phpunit: ^10.3
- psalm/plugin-laravel: ^2.8
- vimeo/psalm: ^5.12
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Another laravel jwt auth package.
This package has very slow support, you might be better off switching to an older and more used
package: tymon/jwt-auth
Installation
Install the package via composer:
composer require think.studio/laravel-jwt-auth
You can publish the config file with:
php artisan vendor:publish --provider="JWTAuth\ServiceProvider" --tag="config"
You can publish migrations:
php artisan vendor:publish --provider="JWTAuth\ServiceProvider" --tag="migrations"
If you don't have encryption / decryption keys, generate them using the command
php artisan jwt:keys:generate
Configuration
Update auth configuration
// config/auth.php 'guards' => [ // ... 'my_api_guard_name' => [ 'driver' => 'jwt', 'provider' => 'users', 'public_key' => env('JWT_PUBLIC_KEY', 'jwt-keys/jwtRS256.key.pub'), 'private_key' => env('JWT_PUBLIC_KEY', 'jwt-keys/jwtRS256.key'), 'blocklist' => 'filesystem', 'options' => [], ], ],
Update User model
use Illuminate\Foundation\Auth\User as Authenticatable; use JWTAuth\Contracts\WithJwtToken; class User extends Authenticatable implements WithJwtToken { use \JWTAuth\Eloquent\HasJwtToken; //... }
Usage
Login
/** @var \JWTAuth\JWTGuard $auth */ $auth = Auth::guard('my_api_guard_name'); $token = $auth->attempt($request->only( 'email', 'password')); if ($token) { $user = $auth->user(); echo "Access token: {$token}"; echo "User id: {$user->id}"; }
Logout
if(Auth::guard('my_api_guard_name')->check()) { Auth::guard('my_api_guard_name')->logout(); }