tymondesigns / jwt-auth

🔐 JSON Web Token Authentication for Laravel & Lumen
https://jwt-auth.com
MIT License
11.23k stars 1.55k forks source link

Redis connection to store blacklisted jwts #2254

Open quevlu opened 2 months ago

quevlu commented 2 months ago

This is an example to store blacklisted jwts on Redis.

1- Create a new class with this content

`<?php

namespace Infrastructure\Redis\Jwt;

use Illuminate\Support\Facades\Cache; use Tymon\JWTAuth\Providers\Storage\Illuminate;

class Storage extends Illuminate { public function __construct() { $this->cache = Cache::store('jwt'); } }`

2- Go to app/jwt.php

3- Replace 'storage' with the previous namespace class

4- Go to app/cache.php

5- Create a new connection in 'stores'

'jwt' => [ 'driver' => 'redis', 'connection' => 'jwt', 'lock_connection' => 'default', ],

6- Go to app/database.php

7- Save a new connection in 'redis'

'jwt' => [ 'url' => env('REDIS_URL'), 'host' => env('REDIS_HOST'), 'username' => env('REDIS_USERNAME'), 'password' => env('REDIS_PASSWORD'), 'port' => env('REDIS_PORT'), 'database' => '2', // You can select a specific database ],

8- You should call auth()->logout(true);

WendellAdriel commented 2 months ago

This should be implemented out-of-the-box or at least in the documentation! 💪 🔥