Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 25 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,33 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
You can find and compare releases at the [GitHub release page](https://github.com/PHP-Open-Source-Saver/jwt-auth/releases).

## [Unreleased]

### Added
- Trigger Authenticated event when loading user from token

## [2.9.0] 2026-03-06
Please see (https://github.com/PHP-Open-Source-Saver/jwt-auth/releases/tag/2.9.0)

### Added
- Updating composer and CI for Laravel 13

## [2.8.3] 2025-10-15
Please see (https://github.com/PHP-Open-Source-Saver/jwt-auth/releases/tag/2.8.3)

### Fixed
- Implement config variable to allow iat to remain unchanged claim when refreshing a token

## [2.8.2] 2025-03-19
Please see (https://github.com/PHP-Open-Source-Saver/jwt-auth/releases/tag/2.8.2)

### Fixed
- Fixed the return type of getMinutesUntilExpired in BlackList, which returned a float instead of an int when using Carbon v2.
- Fixed PHPStan issue in JWTGenerateSecretCommand by ensuring displayKey($key); is called before returning, avoiding returning a void method.
- Fixed missing return true; statements in validatePayload() and validateRefresh() methods of Expiration.php, IssuedAt.php, and NotBefore.php to resolve PHPStan errors.
- Fixed PHPStan error related to new static() by refactoring hasAllClaims method in Collection class.
- Fix PHPStan Issues

## [2.8.1] 2025-02-28
Please see (https://github.com/PHP-Open-Source-Saver/jwt-auth/releases/tag/2.8.1)

### Fixed
- Fixed the return type of getMinutesUntilExpired in BlackList, which returned a float instead of an int when using Carbon v2.

## [2.8.0] 2025-02-11
Please see (https://github.com/PHP-Open-Source-Saver/jwt-auth/releases/tag/2.8.0)
Expand Down
4 changes: 3 additions & 1 deletion src/JWTGuard.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,9 @@ public function user()
&& ($payload = $this->jwt->check(true))
&& $this->validateSubject()
) {
return $this->user = $this->provider->retrieveById($payload['sub']);
$this->setUser($this->provider->retrieveById($payload['sub']));

return $this->user;
}
}

Expand Down
22 changes: 15 additions & 7 deletions tests/JWTGuardTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,20 @@ public function testItShouldGetTheAuthenticatedUserIfAValidTokenIsProvided()
$this->provider->shouldReceive('retrieveById')
->once()
->with(1)
->andReturn((object) ['id' => 1]);
->andReturn(new LaravelUserStub());

$this->assertSame(1, $this->guard->user()->id);
$this->eventDispatcher->shouldReceive('dispatch')
->once()
->with(\Mockery::type(Authenticated::class));

$this->assertSame(1, $this->guard->user()->getAuthIdentifier());

// check that the user is stored on the object next time round
$this->assertSame(1, $this->guard->user()->id);
$this->assertSame(1, $this->guard->user()->getAuthIdentifier());
$this->assertTrue($this->guard->check());

// also make sure userOrFail does not fail
$this->assertSame(1, $this->guard->userOrFail()->id);
$this->assertSame(1, $this->guard->userOrFail()->getAuthIdentifier());
}

public function testItShouldGetTheAuthenticatedUserIfAValidTokenIsProvidedAndNotThrowAnException()
Expand All @@ -110,12 +114,16 @@ public function testItShouldGetTheAuthenticatedUserIfAValidTokenIsProvidedAndNot
$this->provider->shouldReceive('retrieveById')
->once()
->with(1)
->andReturn((object) ['id' => 1]);
->andReturn(new LaravelUserStub());

$this->eventDispatcher->shouldReceive('dispatch')
->once()
->with(\Mockery::type(Authenticated::class));

$this->assertSame(1, $this->guard->userOrFail()->id);
$this->assertSame(1, $this->guard->userOrFail()->getAuthIdentifier());

// check that the user is stored on the object next time round
$this->assertSame(1, $this->guard->userOrFail()->id);
$this->assertSame(1, $this->guard->userOrFail()->getAuthIdentifier());
$this->assertTrue($this->guard->check());
}

Expand Down
Loading