File tree Expand file tree Collapse file tree 3 files changed +42
-3
lines changed
Expand file tree Collapse file tree 3 files changed +42
-3
lines changed Original file line number Diff line number Diff line change @@ -7,12 +7,27 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77You can find and compare releases at the GitHub release page.
88
99## [ Unreleased]
10- - SetSecret regenerates config with new secret in the Lcobucci provider
10+
11+ ### Added
12+ - Fixes #259 - Can't logout with an expired token
13+
14+ ### Removed
15+
16+ ## [ 2.6.0] 2024-07-11
17+
18+ ### Added
19+ - New ` getUserId ` method
20+
21+ ## [ 2.5.0] 2024-07-03
22+
23+ ### Added
1124- Refresh iat claim when refreshing a token
1225
26+ ## [ 2.4.0] 2024-05-27
27+
1328### Added
1429- Support for lcobucci/jwt^5.0 (and dropped support for ^4.0)
15- - New ` getUserId ` method
30+ - SetSecret regenerates config with new secret in the Lcobucci provider
1631
1732## [ 2.3.0] 2024-05-09
1833
Original file line number Diff line number Diff line change @@ -200,7 +200,11 @@ public function login(JWTSubject $user)
200200 */
201201 public function logout ($ forceForever = false )
202202 {
203- $ this ->requireToken ()->invalidate ($ forceForever );
203+ try {
204+ $ this ->requireToken ()->invalidate ($ forceForever );
205+ } catch (JWTException $ e ) {
206+ // Proceed with the logout as normal if we can't invalidate the token
207+ }
204208
205209 $ this ->fireLogoutEvent ($ this ->user );
206210
Original file line number Diff line number Diff line change 2222use Illuminate \Http \Request ;
2323use Mockery \LegacyMockInterface ;
2424use PHPOpenSourceSaver \JWTAuth \Exceptions \JWTException ;
25+ use PHPOpenSourceSaver \JWTAuth \Exceptions \TokenExpiredException ;
2526use PHPOpenSourceSaver \JWTAuth \Exceptions \UserNotDefinedException ;
2627use PHPOpenSourceSaver \JWTAuth \Factory ;
2728use PHPOpenSourceSaver \JWTAuth \JWT ;
@@ -353,6 +354,25 @@ public function testItShouldLogoutTheUserByInvalidatingTheToken()
353354 $ this ->assertNull ($ this ->guard ->getUser ());
354355 }
355356
357+ public function testItShouldLogoutTheUserEvenWithExpiredToken ()
358+ {
359+ $ this ->jwt ->shouldReceive ('setRequest ' )->andReturn ($ this ->jwt );
360+ $ this ->jwt ->shouldReceive ('getToken ' )->once ()->andReturn (true );
361+ $ this ->jwt ->shouldReceive ('invalidate ' )->andThrow (TokenExpiredException::class);
362+ $ this ->jwt ->shouldReceive ('unsetToken ' )->once ();
363+
364+ $ this ->eventDispatcher ->shouldReceive ('dispatch ' )
365+ ->never ()
366+ ->with (\Mockery::type (Authenticated::class));
367+
368+ $ this ->eventDispatcher ->shouldReceive ('dispatch ' )
369+ ->once ()
370+ ->with (\Mockery::type (Logout::class));
371+
372+ $ this ->guard ->logout ();
373+ $ this ->assertNull ($ this ->guard ->getUser ());
374+ }
375+
356376 public function testItShouldRefreshTheToken ()
357377 {
358378 $ this ->jwt ->shouldReceive ('setRequest ' )->andReturn ($ this ->jwt );
You can’t perform that action at this time.
0 commit comments