Skip to content

Commit 2f4d5ff

Browse files
committed
Merge branch '12.x' into 13.x
2 parents 8375604 + 3e96f8e commit 2f4d5ff

File tree

5 files changed

+55
-3
lines changed

5 files changed

+55
-3
lines changed

.github/SECURITY.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ If you discover a security vulnerability within Laravel, please send an email to
1515
```
1616
-----BEGIN PGP PUBLIC KEY BLOCK-----
1717
Version: OpenPGP v2.0.8
18-
Comment: https://sela.io/pgp/
18+
Comment: Report Security Vulnerabilities to [email protected]
1919
2020
xsFNBFugFSQBEACxEKhIY9IoJzcouVTIYKJfWFGvwFgbRjQWBiH3QdHId5vCrbWo
2121
s2l+4Rv03gMG+yHLJ3rWElnNdRaNdQv59+lShrZF7Bvu7Zvc0mMNmFOM/mQ/K2Lt

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# Release Notes
22

3-
## [Unreleased](https://github.com/laravel/passport/compare/v12.2.1...12.x)
3+
## [Unreleased](https://github.com/laravel/passport/compare/v12.3.0...12.x)
4+
5+
## [v12.3.0](https://github.com/laravel/passport/compare/v12.2.1...v12.3.0) - 2024-08-05
6+
7+
* [12.x] Add access token revoked event by [@axlon](https://github.com/axlon) in https://github.com/laravel/passport/pull/1776
48

59
## [v12.2.1](https://github.com/laravel/passport/compare/v12.2.0...v12.2.1) - 2024-07-10
610

src/Bridge/AccessTokenRepository.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use DateTime;
66
use Illuminate\Contracts\Events\Dispatcher;
77
use Laravel\Passport\Events\AccessTokenCreated;
8+
use Laravel\Passport\Events\AccessTokenRevoked;
89
use Laravel\Passport\Passport;
910
use Laravel\Passport\TokenRepository;
1011
use League\OAuth2\Server\Entities\AccessTokenEntityInterface;
@@ -69,7 +70,9 @@ public function persistNewAccessToken(AccessTokenEntityInterface $accessTokenEnt
6970
*/
7071
public function revokeAccessToken(string $tokenId): void
7172
{
72-
$this->tokenRepository->revokeAccessToken($tokenId);
73+
if ($this->tokenRepository->revokeAccessToken($tokenId)) {
74+
$this->events->dispatch(new AccessTokenRevoked($tokenId));
75+
}
7376
}
7477

7578
/**

src/Events/AccessTokenRevoked.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace Laravel\Passport\Events;
4+
5+
class AccessTokenRevoked
6+
{
7+
/**
8+
* Create a new event instance.
9+
*
10+
* @param string $tokenId
11+
* @return void
12+
*/
13+
public function __construct(
14+
public string $tokenId,
15+
) {
16+
}
17+
}

tests/Unit/BridgeAccessTokenRepositoryTest.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,34 @@ public function test_access_tokens_can_be_persisted()
4949
$repository->persistNewAccessToken($accessToken);
5050
}
5151

52+
public function test_access_tokens_can_be_revoked()
53+
{
54+
$tokenRepository = m::mock(TokenRepository::class);
55+
$events = m::mock(Dispatcher::class);
56+
57+
$tokenRepository->shouldReceive('revokeAccessToken')->with('token-id')->once()->andReturn(1);
58+
$events->shouldReceive('dispatch')->once();
59+
60+
$repository = new AccessTokenRepository($tokenRepository, $events);
61+
$repository->revokeAccessToken('token-id');
62+
63+
$this->expectNotToPerformAssertions();
64+
}
65+
66+
public function test_access_token_revoke_event_is_not_dispatched_when_nothing_happened()
67+
{
68+
$tokenRepository = m::mock(TokenRepository::class);
69+
$events = m::mock(Dispatcher::class);
70+
71+
$tokenRepository->shouldReceive('revokeAccessToken')->with('token-id')->once()->andReturn(0);
72+
$events->shouldNotReceive('dispatch');
73+
74+
$repository = new AccessTokenRepository($tokenRepository, $events);
75+
$repository->revokeAccessToken('token-id');
76+
77+
$this->expectNotToPerformAssertions();
78+
}
79+
5280
public function test_can_get_new_access_token()
5381
{
5482
$tokenRepository = m::mock(TokenRepository::class);

0 commit comments

Comments
 (0)