bayareawebpro / laravel-simple-jwt
This package is abandoned and no longer maintained.
No replacement package was suggested.
Simple JsonWebToken for Laravel
v1.0.6
2021-01-23 01:13 UTC
Requires
- php: ^7.4|^8.0
- laravel/framework: ^6.0|^7.30.3|^8.22.1
Requires (Dev)
- laravel/legacy-factories: ^1.1
- nunomaduro/larastan: ^0.6
- orchestra/testbench: ^4.0|^5.0|^6.0
- phpunit/phpunit: ^8.0|^9.0
README
composer require bayareawebpro/laravel-simple-jwt
Create Encryption Secret
artisan jwt:secret
Add Secret to Environment File
JWT_SECRET=XXX
Configure Auth.php
'guards' => [
...
'api' => [
'driver' => 'simple-jwt',
'provider' => 'users',
'hash' => false,
],
],
Register in Auth Service Provider.
JsonWebToken::register(User::class, 'token');
Create New Token, Expiration, and Claims
$token = JsonWebToken::createForUser(User::first(), now()->addHours(3), [ 'my_key' => true ]);
Authenticate
Query String
http://laravel.test/api/user?token=xxx
Or Header
Authorization: Bearer XXX
Get Claims From Token
$request->jwt()->get('my_key'); $request->jwt('my_key');
Extend Token Lifetime & Claims
$newToken = JsonWebToken::extendToken(request()->jwt(), now()->addHours(3), ['key' => true]);
Blacklist Handler
$bannedUUID = request()->jwt('jti');
JsonWebToken::rejectionHandler(fn($parsed)=>in_array($parsed->get('jti'),[ $bannedUUID ]));
Testing
composer test
composer lint