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

This package is auto-updated.

Last update: 2022-05-23 04:11:47 UTC


README

CI Coverage Downloads Version License

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