Laravel JWT Redis
Published on by Paul Redmond
Laravel JWT Redis allows JWT-authenticated users to be stored and managed in Redis with their roles, permissions, statuses, and other data. It works together with tymondesigns/jwt-auth and spatie/laravel-permission package under the hood.
At the core of the package is the model JWTRedisHasRoles
and works in the background—it functions almost identically to Laravel session authentication. Check out the readme for nuances in how this package handles auth.
You configure auth with the following guard and provider provided by the package:
'guards' => [ 'api' => [ 'driver' => 'jwt_redis_guard', 'provider' => 'users' ],], 'providers' => [ 'users' => [ 'driver' => 'jwt_redis_user_provider', 'model' => App\User::class, /* Your User Model */ ],],
Here’s a few examples of route usage:
Route::get("/example", "ExampleController@example")->middleware('role:admin|user');Route::get("/example", "ExampleController@example")->middleware('permissions:get-user|set-user');Route::get("/example", "ExampleController@example")->middleware('role_or_permission:admin|get-user');
At the time of writing, this package is new, so I’d encourage you to check out the source code and contribute if you see anything you’d like to help. Be sure to consider all the typical tradeoffs of using a package before verifying its usage, especially around something like authentication.
You can learn more about this package, get full installation instructions, and view the source code on GitHub at sametsahindogan/laravel-jwtredis.