|
17 | 17 | use League\OAuth2\Server\Repositories\ClientRepositoryInterface; |
18 | 18 | use League\OAuth2\Server\Repositories\RefreshTokenRepositoryInterface; |
19 | 19 | use League\OAuth2\Server\Repositories\ScopeRepositoryInterface; |
| 20 | +use League\OAuth2\Server\RequestAccessTokenEvent; |
| 21 | +use League\OAuth2\Server\RequestEvent; |
| 22 | +use League\OAuth2\Server\RequestRefreshTokenEvent; |
20 | 23 | use League\OAuth2\Server\RequestTypes\AuthorizationRequest; |
21 | 24 | use League\OAuth2\Server\ResponseTypes\RedirectResponse; |
22 | 25 | use LeagueTests\Stubs\AccessTokenEntity; |
@@ -732,6 +735,27 @@ public function testRespondToAccessTokenRequest(): void |
732 | 735 | $grant->setEncryptionKey($this->cryptStub->getKey()); |
733 | 736 | $grant->setPrivateKey(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key')); |
734 | 737 |
|
| 738 | + $accessTokenEventEmitted = false; |
| 739 | + $refreshTokenEventEmitted = false; |
| 740 | + |
| 741 | + $grant->getListenerRegistry()->subscribeTo( |
| 742 | + RequestEvent::ACCESS_TOKEN_ISSUED, |
| 743 | + function ($event) use (&$accessTokenEventEmitted): void { |
| 744 | + self::assertInstanceOf(RequestAccessTokenEvent::class, $event); |
| 745 | + |
| 746 | + $accessTokenEventEmitted = true; |
| 747 | + } |
| 748 | + ); |
| 749 | + |
| 750 | + $grant->getListenerRegistry()->subscribeTo( |
| 751 | + RequestEvent::REFRESH_TOKEN_ISSUED, |
| 752 | + function ($event) use (&$refreshTokenEventEmitted): void { |
| 753 | + self::assertInstanceOf(RequestRefreshTokenEvent::class, $event); |
| 754 | + |
| 755 | + $refreshTokenEventEmitted = true; |
| 756 | + } |
| 757 | + ); |
| 758 | + |
735 | 759 | $request = new ServerRequest( |
736 | 760 | [], |
737 | 761 | [], |
@@ -763,6 +787,14 @@ public function testRespondToAccessTokenRequest(): void |
763 | 787 | $response = $grant->respondToAccessTokenRequest($request, new StubResponseType(), new DateInterval('PT10M')); |
764 | 788 |
|
765 | 789 | self::assertInstanceOf(RefreshTokenEntityInterface::class, $response->getRefreshToken()); |
| 790 | + |
| 791 | + if (!$accessTokenEventEmitted) { |
| 792 | + self::fail('Access token issued event is not emitted.'); |
| 793 | + } |
| 794 | + |
| 795 | + if (!$refreshTokenEventEmitted) { |
| 796 | + self::fail('Refresh token issued event is not emitted.'); |
| 797 | + } |
766 | 798 | } |
767 | 799 |
|
768 | 800 | public function testRespondToAccessTokenRequestWithDefaultRedirectUri(): void |
|
0 commit comments