From 8b55917af646f52d04770ddb1f07d638bafbff91 Mon Sep 17 00:00:00 2001 From: Eugene Borovov Date: Sat, 16 Jan 2021 22:30:21 +0700 Subject: [PATCH 01/10] Install PSR-14 Event Dispatcher Signed-off-by: Eugene Borovov --- composer.json | 1 + 1 file changed, 1 insertion(+) diff --git a/composer.json b/composer.json index 6d01aecd7..61ff89158 100644 --- a/composer.json +++ b/composer.json @@ -8,6 +8,7 @@ "ext-openssl": "*", "league/event": "^2.2", "lcobucci/jwt": "^3.4 || ^4.0", + "psr/event-dispatcher": "^1.0", "psr/http-message": "^1.0.1", "defuse/php-encryption": "^2.2.1", "ext-json": "*" From 2fd0f82df21fc9ed1a1ab71b43b4e770d7e61801 Mon Sep 17 00:00:00 2001 From: Eugene Borovov Date: Sat, 16 Jan 2021 23:51:18 +0700 Subject: [PATCH 02/10] Declare domain events Signed-off-by: Eugene Borovov --- src/Events/AbstractEvent.php | 39 +++++++++++++++++++++++ src/Events/AccessTokenIssued.php | 26 +++++++++++++++ src/Events/ClientAuthenticationFailed.php | 25 +++++++++++++++ src/Events/RefreshTokenClientFailed.php | 35 ++++++++++++++++++++ src/Events/RefreshTokenIssued.php | 26 +++++++++++++++ src/Events/UserAuthenticationFailed.php | 25 +++++++++++++++ 6 files changed, 176 insertions(+) create mode 100644 src/Events/AbstractEvent.php create mode 100644 src/Events/AccessTokenIssued.php create mode 100644 src/Events/ClientAuthenticationFailed.php create mode 100644 src/Events/RefreshTokenClientFailed.php create mode 100644 src/Events/RefreshTokenIssued.php create mode 100644 src/Events/UserAuthenticationFailed.php diff --git a/src/Events/AbstractEvent.php b/src/Events/AbstractEvent.php new file mode 100644 index 000000000..3f669c465 --- /dev/null +++ b/src/Events/AbstractEvent.php @@ -0,0 +1,39 @@ +name = static::class; + $this->request = $request; + $this->occuredOn = new \DateTimeImmutable(); + } + + public function getName(): string + { + return $this->name; + } + + public function getRequest(): ServerRequestInterface + { + return $this->request; + } + + public function getOccuredOn(): \DateTimeImmutable + { + return $this->occuredOn; + } +} \ No newline at end of file diff --git a/src/Events/AccessTokenIssued.php b/src/Events/AccessTokenIssued.php new file mode 100644 index 000000000..8c5b21fc0 --- /dev/null +++ b/src/Events/AccessTokenIssued.php @@ -0,0 +1,26 @@ +name = 'access_token.issued'; + $this->accessToken = $accessToken; + } + + public function getAccessToken(): AccessTokenEntityInterface + { + return $this->accessToken; + } +} \ No newline at end of file diff --git a/src/Events/ClientAuthenticationFailed.php b/src/Events/ClientAuthenticationFailed.php new file mode 100644 index 000000000..a2d8423f8 --- /dev/null +++ b/src/Events/ClientAuthenticationFailed.php @@ -0,0 +1,25 @@ +name = 'client.authentication.failed'; + $this->clientId = $clientId; + } + + public function getClientId(): string + { + return $this->clientId; + } +} \ No newline at end of file diff --git a/src/Events/RefreshTokenClientFailed.php b/src/Events/RefreshTokenClientFailed.php new file mode 100644 index 000000000..c4dd5fec6 --- /dev/null +++ b/src/Events/RefreshTokenClientFailed.php @@ -0,0 +1,35 @@ +name = 'refresh_token.client.failed'; + $this->clientId = $clientId; + $this->refreshTokenData = $refreshTokenData; + } + + public function getClientId(): string + { + return $this->clientId; + } + + public function getRefreshTokenData(): array + { + return $this->refreshTokenData; + } +} \ No newline at end of file diff --git a/src/Events/RefreshTokenIssued.php b/src/Events/RefreshTokenIssued.php new file mode 100644 index 000000000..2b8074a0e --- /dev/null +++ b/src/Events/RefreshTokenIssued.php @@ -0,0 +1,26 @@ +name = 'refresh_token.issued'; + $this->refreshToken = $refreshToken; + } + + public function getRefreshToken(): RefreshTokenEntityInterface + { + return $this->refreshToken; + } +} \ No newline at end of file diff --git a/src/Events/UserAuthenticationFailed.php b/src/Events/UserAuthenticationFailed.php new file mode 100644 index 000000000..c2f4b42e3 --- /dev/null +++ b/src/Events/UserAuthenticationFailed.php @@ -0,0 +1,25 @@ +name = 'user.authentication.failed'; + $this->username = $username; + } + + public function getUsername(): string + { + return $this->username; + } +} \ No newline at end of file From cc7548d20ea500dfc496687220850b8ea5da3aa6 Mon Sep 17 00:00:00 2001 From: Eugene Borovov Date: Sun, 17 Jan 2021 00:06:07 +0700 Subject: [PATCH 03/10] Declare EventDispatchable interface Signed-off-by: Eugene Borovov --- src/Events/EventDispatchableInterface.php | 12 +++++++++++ src/Events/EventDispatchableTrait.php | 25 +++++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 src/Events/EventDispatchableInterface.php create mode 100644 src/Events/EventDispatchableTrait.php diff --git a/src/Events/EventDispatchableInterface.php b/src/Events/EventDispatchableInterface.php new file mode 100644 index 000000000..42db70ab6 --- /dev/null +++ b/src/Events/EventDispatchableInterface.php @@ -0,0 +1,12 @@ +eventDispatcher = $eventDispatcher; + } + + public function dispatchEvent(object $event): object + { + if ($this->eventDispatcher !== null) { + return $this->eventDispatcher->dispatch($event); + } + + return $event; + } +} \ No newline at end of file From 1065a8d859a9258b643d36aba310a7340d2387d9 Mon Sep 17 00:00:00 2001 From: Eugene Borovov Date: Sun, 17 Jan 2021 00:42:31 +0700 Subject: [PATCH 04/10] Using EventDispatchable instead of EmitterAwareInterface Signed-off-by: Eugene Borovov --- src/AuthorizationServer.php | 10 +++++----- src/Events/ClientAuthenticationFailed.php | 6 +++--- src/Events/RefreshTokenClientFailed.php | 6 +++--- src/Events/UserAuthenticationFailed.php | 6 +++--- src/Grant/AbstractGrant.php | 14 +++++++------- src/Grant/AuthCodeGrant.php | 12 ++++++------ src/Grant/ClientCredentialsGrant.php | 8 ++++---- src/Grant/GrantTypeInterface.php | 4 ++-- src/Grant/ImplicitGrant.php | 4 ++-- src/Grant/PasswordGrant.php | 12 ++++++------ src/Grant/RefreshTokenGrant.php | 17 ++++++++--------- 11 files changed, 49 insertions(+), 50 deletions(-) diff --git a/src/AuthorizationServer.php b/src/AuthorizationServer.php index a719656c6..1700a8170 100644 --- a/src/AuthorizationServer.php +++ b/src/AuthorizationServer.php @@ -11,8 +11,8 @@ use DateInterval; use Defuse\Crypto\Key; -use League\Event\EmitterAwareInterface; -use League\Event\EmitterAwareTrait; +use League\OAuth2\Server\Events\EventDispatchableInterface; +use League\OAuth2\Server\Events\EventDispatchableTrait; use League\OAuth2\Server\Exception\OAuthServerException; use League\OAuth2\Server\Grant\GrantTypeInterface; use League\OAuth2\Server\Repositories\AccessTokenRepositoryInterface; @@ -25,9 +25,9 @@ use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; -class AuthorizationServer implements EmitterAwareInterface +class AuthorizationServer implements EventDispatchableInterface { - use EmitterAwareTrait; + use EventDispatchableTrait; /** * @var GrantTypeInterface[] @@ -139,7 +139,7 @@ public function enableGrantType(GrantTypeInterface $grantType, DateInterval $acc $grantType->setScopeRepository($this->scopeRepository); $grantType->setDefaultScope($this->defaultScope); $grantType->setPrivateKey($this->privateKey); - $grantType->setEmitter($this->getEmitter()); + $grantType->useEventDispatcher($this->eventDispatcher); $grantType->setEncryptionKey($this->encryptionKey); $grantType->revokeRefreshTokens($this->revokeRefreshTokens); diff --git a/src/Events/ClientAuthenticationFailed.php b/src/Events/ClientAuthenticationFailed.php index a2d8423f8..f8c5f4a2b 100644 --- a/src/Events/ClientAuthenticationFailed.php +++ b/src/Events/ClientAuthenticationFailed.php @@ -6,11 +6,11 @@ final class ClientAuthenticationFailed extends AbstractEvent { - /** @var string */ + /** @var string|null */ private $clientId; public function __construct( - string $clientId, + ?string $clientId, ServerRequestInterface $request ) { parent::__construct($request); @@ -18,7 +18,7 @@ public function __construct( $this->clientId = $clientId; } - public function getClientId(): string + public function getClientId(): ?string { return $this->clientId; } diff --git a/src/Events/RefreshTokenClientFailed.php b/src/Events/RefreshTokenClientFailed.php index c4dd5fec6..b1b961109 100644 --- a/src/Events/RefreshTokenClientFailed.php +++ b/src/Events/RefreshTokenClientFailed.php @@ -6,14 +6,14 @@ final class RefreshTokenClientFailed extends AbstractEvent { - /** @var string */ + /** @var string|null */ private $clientId; /** @var array */ private $refreshTokenData; public function __construct( - string $clientId, + ?string $clientId, array $refreshTokenData, ServerRequestInterface $request ) { @@ -23,7 +23,7 @@ public function __construct( $this->refreshTokenData = $refreshTokenData; } - public function getClientId(): string + public function getClientId(): ?string { return $this->clientId; } diff --git a/src/Events/UserAuthenticationFailed.php b/src/Events/UserAuthenticationFailed.php index c2f4b42e3..20e9d151a 100644 --- a/src/Events/UserAuthenticationFailed.php +++ b/src/Events/UserAuthenticationFailed.php @@ -6,11 +6,11 @@ final class UserAuthenticationFailed extends AbstractEvent { - /** @var string */ + /** @var string|null */ private $username; public function __construct( - string $username, + ?string $username, ServerRequestInterface $request ) { parent::__construct($request); @@ -18,7 +18,7 @@ public function __construct( $this->username = $username; } - public function getUsername(): string + public function getUsername(): ?string { return $this->username; } diff --git a/src/Grant/AbstractGrant.php b/src/Grant/AbstractGrant.php index 0a5b514fc..e365e7213 100644 --- a/src/Grant/AbstractGrant.php +++ b/src/Grant/AbstractGrant.php @@ -14,7 +14,6 @@ use DateTimeImmutable; use Error; use Exception; -use League\Event\EmitterAwareTrait; use League\OAuth2\Server\CryptKey; use League\OAuth2\Server\CryptTrait; use League\OAuth2\Server\Entities\AccessTokenEntityInterface; @@ -22,6 +21,8 @@ use League\OAuth2\Server\Entities\ClientEntityInterface; use League\OAuth2\Server\Entities\RefreshTokenEntityInterface; use League\OAuth2\Server\Entities\ScopeEntityInterface; +use League\OAuth2\Server\Events\ClientAuthenticationFailed; +use League\OAuth2\Server\Events\EventDispatchableTrait; use League\OAuth2\Server\Exception\OAuthServerException; use League\OAuth2\Server\Exception\UniqueTokenIdentifierConstraintViolationException; use League\OAuth2\Server\RedirectUriValidators\RedirectUriValidator; @@ -31,7 +32,6 @@ use League\OAuth2\Server\Repositories\RefreshTokenRepositoryInterface; use League\OAuth2\Server\Repositories\ScopeRepositoryInterface; use League\OAuth2\Server\Repositories\UserRepositoryInterface; -use League\OAuth2\Server\RequestEvent; use League\OAuth2\Server\RequestTypes\AuthorizationRequest; use LogicException; use Psr\Http\Message\ServerRequestInterface; @@ -42,7 +42,7 @@ */ abstract class AbstractGrant implements GrantTypeInterface { - use EmitterAwareTrait, CryptTrait; + use EventDispatchableTrait, CryptTrait; const SCOPE_DELIMITER_STRING = ' '; @@ -194,7 +194,7 @@ protected function validateClient(ServerRequestInterface $request) [$clientId, $clientSecret] = $this->getClientCredentials($request); if ($this->clientRepository->validateClient($clientId, $clientSecret, $this->getIdentifier()) === false) { - $this->getEmitter()->emit(new RequestEvent(RequestEvent::CLIENT_AUTHENTICATION_FAILED, $request)); + $this->dispatchEvent(new ClientAuthenticationFailed($clientId, $request)); throw OAuthServerException::invalidClient($request); } @@ -225,7 +225,7 @@ protected function validateClient(ServerRequestInterface $request) * getClientEntity might return null. By contrast, this method will * always either return a ClientEntityInterface or throw. * - * @param string $clientId + * @param string $clientId * @param ServerRequestInterface $request * * @return ClientEntityInterface @@ -235,7 +235,7 @@ protected function getClientEntityOrFail($clientId, ServerRequestInterface $requ $client = $this->clientRepository->getClientEntity($clientId); if ($client instanceof ClientEntityInterface === false) { - $this->getEmitter()->emit(new RequestEvent(RequestEvent::CLIENT_AUTHENTICATION_FAILED, $request)); + $this->dispatchEvent(new ClientAuthenticationFailed($clientId, $request)); throw OAuthServerException::invalidClient($request); } @@ -286,7 +286,7 @@ protected function validateRedirectUri( ) { $validator = new RedirectUriValidator($client->getRedirectUri()); if (!$validator->validateRedirectUri($redirectUri)) { - $this->getEmitter()->emit(new RequestEvent(RequestEvent::CLIENT_AUTHENTICATION_FAILED, $request)); + $this->dispatchEvent(new ClientAuthenticationFailed($client->getIdentifier(), $request)); throw OAuthServerException::invalidClient($request); } } diff --git a/src/Grant/AuthCodeGrant.php b/src/Grant/AuthCodeGrant.php index 3fac0344e..b7e59cfcc 100644 --- a/src/Grant/AuthCodeGrant.php +++ b/src/Grant/AuthCodeGrant.php @@ -17,12 +17,12 @@ use League\OAuth2\Server\CodeChallengeVerifiers\S256Verifier; use League\OAuth2\Server\Entities\ClientEntityInterface; use League\OAuth2\Server\Entities\UserEntityInterface; +use League\OAuth2\Server\Events\AccessTokenIssued; +use League\OAuth2\Server\Events\ClientAuthenticationFailed; +use League\OAuth2\Server\Events\RefreshTokenIssued; use League\OAuth2\Server\Exception\OAuthServerException; use League\OAuth2\Server\Repositories\AuthCodeRepositoryInterface; use League\OAuth2\Server\Repositories\RefreshTokenRepositoryInterface; -use League\OAuth2\Server\RequestAccessTokenEvent; -use League\OAuth2\Server\RequestEvent; -use League\OAuth2\Server\RequestRefreshTokenEvent; use League\OAuth2\Server\RequestTypes\AuthorizationRequest; use League\OAuth2\Server\ResponseTypes\RedirectResponse; use League\OAuth2\Server\ResponseTypes\ResponseTypeInterface; @@ -164,14 +164,14 @@ public function respondToAccessTokenRequest( // Issue and persist new access token $accessToken = $this->issueAccessToken($accessTokenTTL, $client, $authCodePayload->user_id, $scopes); - $this->getEmitter()->emit(new RequestAccessTokenEvent(RequestEvent::ACCESS_TOKEN_ISSUED, $request, $accessToken)); + $this->dispatchEvent(new AccessTokenIssued($accessToken, $request)); $responseType->setAccessToken($accessToken); // Issue and persist new refresh token if given $refreshToken = $this->issueRefreshToken($accessToken); if ($refreshToken !== null) { - $this->getEmitter()->emit(new RequestRefreshTokenEvent(RequestEvent::REFRESH_TOKEN_ISSUED, $request, $refreshToken)); + $this->dispatchEvent(new RefreshTokenIssued($refreshToken, $request)); $responseType->setRefreshToken($refreshToken); } @@ -269,7 +269,7 @@ public function validateAuthorizationRequest(ServerRequestInterface $request) $this->validateRedirectUri($redirectUri, $client, $request); } elseif (empty($client->getRedirectUri()) || (\is_array($client->getRedirectUri()) && \count($client->getRedirectUri()) !== 1)) { - $this->getEmitter()->emit(new RequestEvent(RequestEvent::CLIENT_AUTHENTICATION_FAILED, $request)); + $this->dispatchEvent(new ClientAuthenticationFailed($clientId, $request)); throw OAuthServerException::invalidClient($request); } diff --git a/src/Grant/ClientCredentialsGrant.php b/src/Grant/ClientCredentialsGrant.php index d342b269f..9148b0b45 100644 --- a/src/Grant/ClientCredentialsGrant.php +++ b/src/Grant/ClientCredentialsGrant.php @@ -12,9 +12,9 @@ namespace League\OAuth2\Server\Grant; use DateInterval; +use League\OAuth2\Server\Events\AccessTokenIssued; +use League\OAuth2\Server\Events\ClientAuthenticationFailed; use League\OAuth2\Server\Exception\OAuthServerException; -use League\OAuth2\Server\RequestAccessTokenEvent; -use League\OAuth2\Server\RequestEvent; use League\OAuth2\Server\ResponseTypes\ResponseTypeInterface; use Psr\Http\Message\ServerRequestInterface; @@ -36,7 +36,7 @@ public function respondToAccessTokenRequest( $client = $this->getClientEntityOrFail($clientId, $request); if (!$client->isConfidential()) { - $this->getEmitter()->emit(new RequestEvent(RequestEvent::CLIENT_AUTHENTICATION_FAILED, $request)); + $this->dispatchEvent(new ClientAuthenticationFailed($clientId, $request)); throw OAuthServerException::invalidClient($request); } @@ -53,7 +53,7 @@ public function respondToAccessTokenRequest( $accessToken = $this->issueAccessToken($accessTokenTTL, $client, null, $finalizedScopes); // Send event to emitter - $this->getEmitter()->emit(new RequestAccessTokenEvent(RequestEvent::ACCESS_TOKEN_ISSUED, $request, $accessToken)); + $this->dispatchEvent(new AccessTokenIssued($accessToken, $request)); // Inject access token into response type $responseType->setAccessToken($accessToken); diff --git a/src/Grant/GrantTypeInterface.php b/src/Grant/GrantTypeInterface.php index 41ebeb5ff..e9004c95d 100644 --- a/src/Grant/GrantTypeInterface.php +++ b/src/Grant/GrantTypeInterface.php @@ -13,8 +13,8 @@ use DateInterval; use Defuse\Crypto\Key; -use League\Event\EmitterAwareInterface; use League\OAuth2\Server\CryptKey; +use League\OAuth2\Server\Events\EventDispatchableInterface; use League\OAuth2\Server\Repositories\AccessTokenRepositoryInterface; use League\OAuth2\Server\Repositories\ClientRepositoryInterface; use League\OAuth2\Server\Repositories\ScopeRepositoryInterface; @@ -25,7 +25,7 @@ /** * Grant type interface. */ -interface GrantTypeInterface extends EmitterAwareInterface +interface GrantTypeInterface extends EventDispatchableInterface { /** * Set refresh token TTL. diff --git a/src/Grant/ImplicitGrant.php b/src/Grant/ImplicitGrant.php index 0bd91d5ac..226a67000 100644 --- a/src/Grant/ImplicitGrant.php +++ b/src/Grant/ImplicitGrant.php @@ -11,9 +11,9 @@ use DateInterval; use League\OAuth2\Server\Entities\UserEntityInterface; +use League\OAuth2\Server\Events\ClientAuthenticationFailed; use League\OAuth2\Server\Exception\OAuthServerException; use League\OAuth2\Server\Repositories\RefreshTokenRepositoryInterface; -use League\OAuth2\Server\RequestEvent; use League\OAuth2\Server\RequestTypes\AuthorizationRequest; use League\OAuth2\Server\ResponseTypes\RedirectResponse; use League\OAuth2\Server\ResponseTypes\ResponseTypeInterface; @@ -136,7 +136,7 @@ public function validateAuthorizationRequest(ServerRequestInterface $request) $this->validateRedirectUri($redirectUri, $client, $request); } elseif (\is_array($client->getRedirectUri()) && \count($client->getRedirectUri()) !== 1 || empty($client->getRedirectUri())) { - $this->getEmitter()->emit(new RequestEvent(RequestEvent::CLIENT_AUTHENTICATION_FAILED, $request)); + $this->dispatchEvent(new ClientAuthenticationFailed($client->getIdentifier(), $request)); throw OAuthServerException::invalidClient($request); } else { $redirectUri = \is_array($client->getRedirectUri()) diff --git a/src/Grant/PasswordGrant.php b/src/Grant/PasswordGrant.php index fd32d2688..272776302 100644 --- a/src/Grant/PasswordGrant.php +++ b/src/Grant/PasswordGrant.php @@ -14,12 +14,12 @@ use DateInterval; use League\OAuth2\Server\Entities\ClientEntityInterface; use League\OAuth2\Server\Entities\UserEntityInterface; +use League\OAuth2\Server\Events\AccessTokenIssued; +use League\OAuth2\Server\Events\RefreshTokenIssued; +use League\OAuth2\Server\Events\UserAuthenticationFailed; use League\OAuth2\Server\Exception\OAuthServerException; use League\OAuth2\Server\Repositories\RefreshTokenRepositoryInterface; use League\OAuth2\Server\Repositories\UserRepositoryInterface; -use League\OAuth2\Server\RequestAccessTokenEvent; -use League\OAuth2\Server\RequestEvent; -use League\OAuth2\Server\RequestRefreshTokenEvent; use League\OAuth2\Server\ResponseTypes\ResponseTypeInterface; use Psr\Http\Message\ServerRequestInterface; @@ -60,14 +60,14 @@ public function respondToAccessTokenRequest( // Issue and persist new access token $accessToken = $this->issueAccessToken($accessTokenTTL, $client, $user->getIdentifier(), $finalizedScopes); - $this->getEmitter()->emit(new RequestAccessTokenEvent(RequestEvent::ACCESS_TOKEN_ISSUED, $request, $accessToken)); + $this->dispatchEvent(new AccessTokenIssued($accessToken, $request)); $responseType->setAccessToken($accessToken); // Issue and persist new refresh token if given $refreshToken = $this->issueRefreshToken($accessToken); if ($refreshToken !== null) { - $this->getEmitter()->emit(new RequestRefreshTokenEvent(RequestEvent::REFRESH_TOKEN_ISSUED, $request, $refreshToken)); + $this->dispatchEvent(new RefreshTokenIssued($refreshToken, $request)); $responseType->setRefreshToken($refreshToken); } @@ -104,7 +104,7 @@ protected function validateUser(ServerRequestInterface $request, ClientEntityInt ); if ($user instanceof UserEntityInterface === false) { - $this->getEmitter()->emit(new RequestEvent(RequestEvent::USER_AUTHENTICATION_FAILED, $request)); + $this->dispatchEvent(new UserAuthenticationFailed($username, $request)); throw OAuthServerException::invalidCredentials(); } diff --git a/src/Grant/RefreshTokenGrant.php b/src/Grant/RefreshTokenGrant.php index 2dedf15c3..257a382cf 100644 --- a/src/Grant/RefreshTokenGrant.php +++ b/src/Grant/RefreshTokenGrant.php @@ -13,11 +13,11 @@ use DateInterval; use Exception; +use League\OAuth2\Server\Events\AccessTokenIssued; +use League\OAuth2\Server\Events\RefreshTokenClientFailed; +use League\OAuth2\Server\Events\RefreshTokenIssued; use League\OAuth2\Server\Exception\OAuthServerException; use League\OAuth2\Server\Repositories\RefreshTokenRepositoryInterface; -use League\OAuth2\Server\RequestAccessTokenEvent; -use League\OAuth2\Server\RequestEvent; -use League\OAuth2\Server\RequestRefreshTokenEvent; use League\OAuth2\Server\ResponseTypes\ResponseTypeInterface; use Psr\Http\Message\ServerRequestInterface; @@ -71,17 +71,16 @@ public function respondToAccessTokenRequest( // Issue and persist new access token $accessToken = $this->issueAccessToken($accessTokenTTL, $client, $oldRefreshToken['user_id'], $scopes); - $this->getEmitter()->emit(new RequestAccessTokenEvent(RequestEvent::ACCESS_TOKEN_ISSUED, $request, $accessToken)); + $this->dispatchEvent(new AccessTokenIssued($accessToken, $request)); $responseType->setAccessToken($accessToken); // Issue and persist new refresh token if given if ($this->revokeRefreshTokens) { $refreshToken = $this->issueRefreshToken($accessToken); - if ($refreshToken !== null) { - $this->getEmitter()->emit(new RequestRefreshTokenEvent(RequestEvent::REFRESH_TOKEN_ISSUED, $request, $refreshToken)); - $responseType->setRefreshToken($refreshToken); - } + if ($refreshToken !== null) { + $this->dispatchEvent(new RefreshTokenIssued($refreshToken, $request)); + $responseType->setRefreshToken($refreshToken); } return $responseType; @@ -111,7 +110,7 @@ protected function validateOldRefreshToken(ServerRequestInterface $request, $cli $refreshTokenData = \json_decode($refreshToken, true); if ($refreshTokenData['client_id'] !== $clientId) { - $this->getEmitter()->emit(new RequestEvent(RequestEvent::REFRESH_TOKEN_CLIENT_FAILED, $request)); + $this->dispatchEvent(new RefreshTokenClientFailed($clientId, $refreshTokenData, $request)); throw OAuthServerException::invalidRefreshToken('Token is not linked to client'); } From fb905d38f2ae946f43dca336201f2b02719076e1 Mon Sep 17 00:00:00 2001 From: Eugene Borovov Date: Sun, 17 Jan 2021 02:08:39 +0700 Subject: [PATCH 05/10] Remove league/event dependency Signed-off-by: Eugene Borovov --- composer.json | 4 +++- src/RequestEvent.php | 49 -------------------------------------------- 2 files changed, 3 insertions(+), 50 deletions(-) delete mode 100644 src/RequestEvent.php diff --git a/composer.json b/composer.json index 61ff89158..2064a0e5f 100644 --- a/composer.json +++ b/composer.json @@ -6,7 +6,6 @@ "require": { "php": "^7.2 || ^8.0", "ext-openssl": "*", - "league/event": "^2.2", "lcobucci/jwt": "^3.4 || ^4.0", "psr/event-dispatcher": "^1.0", "psr/http-message": "^1.0.1", @@ -20,6 +19,9 @@ "phpstan/phpstan-phpunit": "^0.12.16", "roave/security-advisories": "dev-master" }, + "suggest": { + "league/event": "Required to use the EventDispatcher (^3.0)." + }, "repositories": [ { "type": "git", diff --git a/src/RequestEvent.php b/src/RequestEvent.php deleted file mode 100644 index b1ca3f6b8..000000000 --- a/src/RequestEvent.php +++ /dev/null @@ -1,49 +0,0 @@ - - * @copyright Copyright (c) Alex Bilbie - * @license http://mit-license.org/ - * - * @link https://github.com/thephpleague/oauth2-server - */ - -namespace League\OAuth2\Server; - -use League\Event\Event; -use Psr\Http\Message\ServerRequestInterface; - -class RequestEvent extends Event -{ - const CLIENT_AUTHENTICATION_FAILED = 'client.authentication.failed'; - const USER_AUTHENTICATION_FAILED = 'user.authentication.failed'; - const REFRESH_TOKEN_CLIENT_FAILED = 'refresh_token.client.failed'; - - const REFRESH_TOKEN_ISSUED = 'refresh_token.issued'; - const ACCESS_TOKEN_ISSUED = 'access_token.issued'; - - /** - * @var ServerRequestInterface - */ - private $request; - - /** - * RequestEvent constructor. - * - * @param string $name - * @param ServerRequestInterface $request - */ - public function __construct($name, ServerRequestInterface $request) - { - parent::__construct($name); - $this->request = $request; - } - - /** - * @return ServerRequestInterface - * @codeCoverageIgnore - */ - public function getRequest() - { - return $this->request; - } -} From caa2e007c5926c44bc4f8b04412aa254be3f5c28 Mon Sep 17 00:00:00 2001 From: Eugene Borovov Date: Sun, 17 Jan 2021 03:03:17 +0700 Subject: [PATCH 06/10] Added examples of using events Signed-off-by: Eugene Borovov --- .gitignore | 2 +- examples/composer.json | 11 +- examples/composer.lock | 740 ------------------------- examples/public/auth_code.php | 17 + examples/public/client_credentials.php | 9 + examples/public/implicit.php | 9 + examples/public/middleware_use.php | 22 + examples/public/password.php | 19 +- examples/public/refresh_token.php | 17 + 9 files changed, 100 insertions(+), 746 deletions(-) delete mode 100644 examples/composer.lock diff --git a/.gitignore b/.gitignore index a859c02f9..1969ee4d4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ /vendor -/composer.lock +**/composer.lock phpunit.xml .phpunit.result.cache .idea diff --git a/examples/composer.json b/examples/composer.json index d265472e6..469fa9265 100644 --- a/examples/composer.json +++ b/examples/composer.json @@ -1,13 +1,16 @@ { "require": { - "slim/slim": "^3.12.3" + "slim/slim": "^3.12.3", + "league/event": "^3.0" }, "require-dev": { - "league/event": "^2.2", + "php": "^7.2 || ^8.0", + "ext-openssl": "*", + "ext-json": "*", "lcobucci/jwt": "^3.4 || ^4.0", + "psr/event-dispatcher": "^1.0", "psr/http-message": "^1.0.1", - "defuse/php-encryption": "^2.2.1", - "laminas/laminas-diactoros": "^2.5.0" + "defuse/php-encryption": "^2.2.1" }, "autoload": { "psr-4": { diff --git a/examples/composer.lock b/examples/composer.lock deleted file mode 100644 index f7affe0e9..000000000 --- a/examples/composer.lock +++ /dev/null @@ -1,740 +0,0 @@ -{ - "_readme": [ - "This file locks the dependencies of your project to a known state", - "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", - "This file is @generated automatically" - ], - "content-hash": "1f38bc4bb33ddc5527b3097d1118b227", - "packages": [ - { - "name": "nikic/fast-route", - "version": "v1.3.0", - "source": { - "type": "git", - "url": "https://github.com/nikic/FastRoute.git", - "reference": "181d480e08d9476e61381e04a71b34dc0432e812" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/nikic/FastRoute/zipball/181d480e08d9476e61381e04a71b34dc0432e812", - "reference": "181d480e08d9476e61381e04a71b34dc0432e812", - "shasum": "" - }, - "require": { - "php": ">=5.4.0" - }, - "require-dev": { - "phpunit/phpunit": "^4.8.35|~5.7" - }, - "type": "library", - "autoload": { - "psr-4": { - "FastRoute\\": "src/" - }, - "files": [ - "src/functions.php" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Nikita Popov", - "email": "nikic@php.net" - } - ], - "description": "Fast request router for PHP", - "keywords": [ - "router", - "routing" - ], - "time": "2018-02-13T20:26:39+00:00" - }, - { - "name": "pimple/pimple", - "version": "v3.3.1", - "source": { - "type": "git", - "url": "https://github.com/silexphp/Pimple.git", - "reference": "21e45061c3429b1e06233475cc0e1f6fc774d5b0" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/silexphp/Pimple/zipball/21e45061c3429b1e06233475cc0e1f6fc774d5b0", - "reference": "21e45061c3429b1e06233475cc0e1f6fc774d5b0", - "shasum": "" - }, - "require": { - "php": ">=7.2.5", - "psr/container": "^1.0" - }, - "require-dev": { - "symfony/phpunit-bridge": "^5.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "3.3.x-dev" - } - }, - "autoload": { - "psr-0": { - "Pimple": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Fabien Potencier", - "email": "fabien@symfony.com" - } - ], - "description": "Pimple, a simple Dependency Injection Container", - "homepage": "https://pimple.symfony.com", - "keywords": [ - "container", - "dependency injection" - ], - "time": "2020-11-24T20:35:42+00:00" - }, - { - "name": "psr/container", - "version": "1.0.0", - "source": { - "type": "git", - "url": "https://github.com/php-fig/container.git", - "reference": "b7ce3b176482dbbc1245ebf52b181af44c2cf55f" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/php-fig/container/zipball/b7ce3b176482dbbc1245ebf52b181af44c2cf55f", - "reference": "b7ce3b176482dbbc1245ebf52b181af44c2cf55f", - "shasum": "" - }, - "require": { - "php": ">=5.3.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.0.x-dev" - } - }, - "autoload": { - "psr-4": { - "Psr\\Container\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "PHP-FIG", - "homepage": "http://www.php-fig.org/" - } - ], - "description": "Common Container Interface (PHP FIG PSR-11)", - "homepage": "https://github.com/php-fig/container", - "keywords": [ - "PSR-11", - "container", - "container-interface", - "container-interop", - "psr" - ], - "time": "2017-02-14T16:28:37+00:00" - }, - { - "name": "psr/http-message", - "version": "1.0.1", - "source": { - "type": "git", - "url": "https://github.com/php-fig/http-message.git", - "reference": "f6561bf28d520154e4b0ec72be95418abe6d9363" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/php-fig/http-message/zipball/f6561bf28d520154e4b0ec72be95418abe6d9363", - "reference": "f6561bf28d520154e4b0ec72be95418abe6d9363", - "shasum": "" - }, - "require": { - "php": ">=5.3.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.0.x-dev" - } - }, - "autoload": { - "psr-4": { - "Psr\\Http\\Message\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "PHP-FIG", - "homepage": "http://www.php-fig.org/" - } - ], - "description": "Common interface for HTTP messages", - "homepage": "https://github.com/php-fig/http-message", - "keywords": [ - "http", - "http-message", - "psr", - "psr-7", - "request", - "response" - ], - "time": "2016-08-06T14:39:51+00:00" - }, - { - "name": "slim/slim", - "version": "3.12.3", - "source": { - "type": "git", - "url": "https://github.com/slimphp/Slim.git", - "reference": "1c9318a84ffb890900901136d620b4f03a59da38" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/slimphp/Slim/zipball/1c9318a84ffb890900901136d620b4f03a59da38", - "reference": "1c9318a84ffb890900901136d620b4f03a59da38", - "shasum": "" - }, - "require": { - "ext-json": "*", - "ext-libxml": "*", - "ext-simplexml": "*", - "nikic/fast-route": "^1.0", - "php": ">=5.5.0", - "pimple/pimple": "^3.0", - "psr/container": "^1.0", - "psr/http-message": "^1.0" - }, - "provide": { - "psr/http-message-implementation": "1.0" - }, - "require-dev": { - "phpunit/phpunit": "^4.0", - "squizlabs/php_codesniffer": "^2.5" - }, - "type": "library", - "autoload": { - "psr-4": { - "Slim\\": "Slim" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Josh Lockhart", - "email": "hello@joshlockhart.com", - "homepage": "https://joshlockhart.com" - }, - { - "name": "Andrew Smith", - "email": "a.smith@silentworks.co.uk", - "homepage": "http://silentworks.co.uk" - }, - { - "name": "Rob Allen", - "email": "rob@akrabat.com", - "homepage": "http://akrabat.com" - }, - { - "name": "Gabriel Manricks", - "email": "gmanricks@me.com", - "homepage": "http://gabrielmanricks.com" - } - ], - "description": "Slim is a PHP micro framework that helps you quickly write simple yet powerful web applications and APIs", - "homepage": "https://slimframework.com", - "keywords": [ - "api", - "framework", - "micro", - "router" - ], - "time": "2019-11-28T17:40:33+00:00" - } - ], - "packages-dev": [ - { - "name": "defuse/php-encryption", - "version": "v2.2.1", - "source": { - "type": "git", - "url": "https://github.com/defuse/php-encryption.git", - "reference": "0f407c43b953d571421e0020ba92082ed5fb7620" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/defuse/php-encryption/zipball/0f407c43b953d571421e0020ba92082ed5fb7620", - "reference": "0f407c43b953d571421e0020ba92082ed5fb7620", - "shasum": "" - }, - "require": { - "ext-openssl": "*", - "paragonie/random_compat": ">= 2", - "php": ">=5.4.0" - }, - "require-dev": { - "nikic/php-parser": "^2.0|^3.0|^4.0", - "phpunit/phpunit": "^4|^5" - }, - "bin": [ - "bin/generate-defuse-key" - ], - "type": "library", - "autoload": { - "psr-4": { - "Defuse\\Crypto\\": "src" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Taylor Hornby", - "email": "taylor@defuse.ca", - "homepage": "https://defuse.ca/" - }, - { - "name": "Scott Arciszewski", - "email": "info@paragonie.com", - "homepage": "https://paragonie.com" - } - ], - "description": "Secure PHP Encryption Library", - "keywords": [ - "aes", - "authenticated encryption", - "cipher", - "crypto", - "cryptography", - "encrypt", - "encryption", - "openssl", - "security", - "symmetric key cryptography" - ], - "time": "2018-07-24T23:27:56+00:00" - }, - { - "name": "laminas/laminas-diactoros", - "version": "2.5.0", - "source": { - "type": "git", - "url": "https://github.com/laminas/laminas-diactoros.git", - "reference": "4ff7400c1c12e404144992ef43c8b733fd9ad516" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/laminas/laminas-diactoros/zipball/4ff7400c1c12e404144992ef43c8b733fd9ad516", - "reference": "4ff7400c1c12e404144992ef43c8b733fd9ad516", - "shasum": "" - }, - "require": { - "laminas/laminas-zendframework-bridge": "^1.0", - "php": "^7.3 || ~8.0.0", - "psr/http-factory": "^1.0", - "psr/http-message": "^1.0" - }, - "conflict": { - "phpspec/prophecy": "<1.9.0" - }, - "provide": { - "psr/http-factory-implementation": "1.0", - "psr/http-message-implementation": "1.0" - }, - "replace": { - "zendframework/zend-diactoros": "^2.2.1" - }, - "require-dev": { - "ext-curl": "*", - "ext-dom": "*", - "ext-gd": "*", - "ext-libxml": "*", - "http-interop/http-factory-tests": "^0.8.0", - "laminas/laminas-coding-standard": "~1.0.0", - "php-http/psr7-integration-tests": "^1.1", - "phpspec/prophecy-phpunit": "^2.0", - "phpunit/phpunit": "^9.1" - }, - "type": "library", - "extra": { - "laminas": { - "config-provider": "Laminas\\Diactoros\\ConfigProvider", - "module": "Laminas\\Diactoros" - } - }, - "autoload": { - "files": [ - "src/functions/create_uploaded_file.php", - "src/functions/marshal_headers_from_sapi.php", - "src/functions/marshal_method_from_sapi.php", - "src/functions/marshal_protocol_version_from_sapi.php", - "src/functions/marshal_uri_from_sapi.php", - "src/functions/normalize_server.php", - "src/functions/normalize_uploaded_files.php", - "src/functions/parse_cookie_header.php", - "src/functions/create_uploaded_file.legacy.php", - "src/functions/marshal_headers_from_sapi.legacy.php", - "src/functions/marshal_method_from_sapi.legacy.php", - "src/functions/marshal_protocol_version_from_sapi.legacy.php", - "src/functions/marshal_uri_from_sapi.legacy.php", - "src/functions/normalize_server.legacy.php", - "src/functions/normalize_uploaded_files.legacy.php", - "src/functions/parse_cookie_header.legacy.php" - ], - "psr-4": { - "Laminas\\Diactoros\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "description": "PSR HTTP Message implementations", - "homepage": "https://laminas.dev", - "keywords": [ - "http", - "laminas", - "psr", - "psr-17", - "psr-7" - ], - "time": "2020-11-18T18:39:28+00:00" - }, - { - "name": "laminas/laminas-zendframework-bridge", - "version": "1.1.1", - "source": { - "type": "git", - "url": "https://github.com/laminas/laminas-zendframework-bridge.git", - "reference": "6ede70583e101030bcace4dcddd648f760ddf642" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/laminas/laminas-zendframework-bridge/zipball/6ede70583e101030bcace4dcddd648f760ddf642", - "reference": "6ede70583e101030bcace4dcddd648f760ddf642", - "shasum": "" - }, - "require": { - "php": "^5.6 || ^7.0 || ^8.0" - }, - "require-dev": { - "phpunit/phpunit": "^5.7 || ^6.5 || ^7.5 || ^8.1 || ^9.3", - "squizlabs/php_codesniffer": "^3.5" - }, - "type": "library", - "extra": { - "laminas": { - "module": "Laminas\\ZendFrameworkBridge" - } - }, - "autoload": { - "files": [ - "src/autoload.php" - ], - "psr-4": { - "Laminas\\ZendFrameworkBridge\\": "src//" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "description": "Alias legacy ZF class names to Laminas Project equivalents.", - "keywords": [ - "ZendFramework", - "autoloading", - "laminas", - "zf" - ], - "time": "2020-09-14T14:23:00+00:00" - }, - { - "name": "lcobucci/clock", - "version": "2.0.0", - "source": { - "type": "git", - "url": "https://github.com/lcobucci/clock.git", - "reference": "353d83fe2e6ae95745b16b3d911813df6a05bfb3" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/lcobucci/clock/zipball/353d83fe2e6ae95745b16b3d911813df6a05bfb3", - "reference": "353d83fe2e6ae95745b16b3d911813df6a05bfb3", - "shasum": "" - }, - "require": { - "php": "^7.4 || ^8.0" - }, - "require-dev": { - "infection/infection": "^0.17", - "lcobucci/coding-standard": "^6.0", - "phpstan/extension-installer": "^1.0", - "phpstan/phpstan": "^0.12", - "phpstan/phpstan-deprecation-rules": "^0.12", - "phpstan/phpstan-phpunit": "^0.12", - "phpstan/phpstan-strict-rules": "^0.12", - "phpunit/php-code-coverage": "9.1.4", - "phpunit/phpunit": "9.3.7" - }, - "type": "library", - "autoload": { - "psr-4": { - "Lcobucci\\Clock\\": "src" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Luís Cobucci", - "email": "lcobucci@gmail.com" - } - ], - "description": "Yet another clock abstraction", - "time": "2020-08-27T18:56:02+00:00" - }, - { - "name": "lcobucci/jwt", - "version": "4.0.0", - "source": { - "type": "git", - "url": "https://github.com/lcobucci/jwt.git", - "reference": "6d8665ccd924dc076a9b65d1ea8abe21d68f6958" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/lcobucci/jwt/zipball/6d8665ccd924dc076a9b65d1ea8abe21d68f6958", - "reference": "6d8665ccd924dc076a9b65d1ea8abe21d68f6958", - "shasum": "" - }, - "require": { - "ext-mbstring": "*", - "ext-openssl": "*", - "lcobucci/clock": "^2.0", - "php": "^7.4 || ^8.0" - }, - "require-dev": { - "infection/infection": "^0.20", - "lcobucci/coding-standard": "^6.0", - "mikey179/vfsstream": "^1.6", - "phpbench/phpbench": "^0.17", - "phpstan/extension-installer": "^1.0", - "phpstan/phpstan": "^0.12", - "phpstan/phpstan-deprecation-rules": "^0.12", - "phpstan/phpstan-phpunit": "^0.12", - "phpstan/phpstan-strict-rules": "^0.12", - "phpunit/php-invoker": "^3.1", - "phpunit/phpunit": "^9.4" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "4.0-dev" - } - }, - "autoload": { - "psr-4": { - "Lcobucci\\JWT\\": "src" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Luís Cobucci", - "email": "lcobucci@gmail.com", - "role": "Developer" - } - ], - "description": "A simple library to work with JSON Web Token and JSON Web Signature", - "keywords": [ - "JWS", - "jwt" - ], - "time": "2020-11-25T02:06:12+00:00" - }, - { - "name": "league/event", - "version": "2.2.0", - "source": { - "type": "git", - "url": "https://github.com/thephpleague/event.git", - "reference": "d2cc124cf9a3fab2bb4ff963307f60361ce4d119" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/thephpleague/event/zipball/d2cc124cf9a3fab2bb4ff963307f60361ce4d119", - "reference": "d2cc124cf9a3fab2bb4ff963307f60361ce4d119", - "shasum": "" - }, - "require": { - "php": ">=5.4.0" - }, - "require-dev": { - "henrikbjorn/phpspec-code-coverage": "~1.0.1", - "phpspec/phpspec": "^2.2" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "2.2-dev" - } - }, - "autoload": { - "psr-4": { - "League\\Event\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Frank de Jonge", - "email": "info@frenky.net" - } - ], - "description": "Event package", - "keywords": [ - "emitter", - "event", - "listener" - ], - "time": "2018-11-26T11:52:41+00:00" - }, - { - "name": "paragonie/random_compat", - "version": "v9.99.100", - "source": { - "type": "git", - "url": "https://github.com/paragonie/random_compat.git", - "reference": "996434e5492cb4c3edcb9168db6fbb1359ef965a" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/paragonie/random_compat/zipball/996434e5492cb4c3edcb9168db6fbb1359ef965a", - "reference": "996434e5492cb4c3edcb9168db6fbb1359ef965a", - "shasum": "" - }, - "require": { - "php": ">= 7" - }, - "require-dev": { - "phpunit/phpunit": "4.*|5.*", - "vimeo/psalm": "^1" - }, - "suggest": { - "ext-libsodium": "Provides a modern crypto API that can be used to generate random bytes." - }, - "type": "library", - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Paragon Initiative Enterprises", - "email": "security@paragonie.com", - "homepage": "https://paragonie.com" - } - ], - "description": "PHP 5.x polyfill for random_bytes() and random_int() from PHP 7", - "keywords": [ - "csprng", - "polyfill", - "pseudorandom", - "random" - ], - "time": "2020-10-15T08:29:30+00:00" - }, - { - "name": "psr/http-factory", - "version": "1.0.1", - "source": { - "type": "git", - "url": "https://github.com/php-fig/http-factory.git", - "reference": "12ac7fcd07e5b077433f5f2bee95b3a771bf61be" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/php-fig/http-factory/zipball/12ac7fcd07e5b077433f5f2bee95b3a771bf61be", - "reference": "12ac7fcd07e5b077433f5f2bee95b3a771bf61be", - "shasum": "" - }, - "require": { - "php": ">=7.0.0", - "psr/http-message": "^1.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.0.x-dev" - } - }, - "autoload": { - "psr-4": { - "Psr\\Http\\Message\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "PHP-FIG", - "homepage": "http://www.php-fig.org/" - } - ], - "description": "Common interfaces for PSR-7 HTTP message factories", - "keywords": [ - "factory", - "http", - "message", - "psr", - "psr-17", - "psr-7", - "request", - "response" - ], - "time": "2019-04-30T12:38:16+00:00" - } - ], - "aliases": [], - "minimum-stability": "stable", - "stability-flags": [], - "prefer-stable": false, - "prefer-lowest": false, - "platform": [], - "platform-dev": [] -} diff --git a/examples/public/auth_code.php b/examples/public/auth_code.php index c082e3b3f..ebb6dd85f 100644 --- a/examples/public/auth_code.php +++ b/examples/public/auth_code.php @@ -8,7 +8,11 @@ */ use Laminas\Diactoros\Stream; +use League\Event\EventDispatcher; use League\OAuth2\Server\AuthorizationServer; +use League\OAuth2\Server\Events\AccessTokenIssued; +use League\OAuth2\Server\Events\ClientAuthenticationFailed; +use League\OAuth2\Server\Events\RefreshTokenIssued; use League\OAuth2\Server\Exception\OAuthServerException; use League\OAuth2\Server\Grant\AuthCodeGrant; use OAuth2ServerExamples\Entities\UserEntity; @@ -46,6 +50,19 @@ 'lxZFUEsBCJ2Yb14IF2ygAHI5N4+ZAUXXaSeeJm6+twsUmIen' ); + // Setup EventDispatcher + $dispatcher = new EventDispatcher(); + $dispatcher->subscribeTo(ClientAuthenticationFailed::class, function(ClientAuthenticationFailed $event){ + // Handle client authentication failure + }); + $dispatcher->subscribeTo(AccessTokenIssued::class, function(AccessTokenIssued $event){ + // Handle access token issue + }); + $dispatcher->subscribeTo(RefreshTokenIssued::class, function(RefreshTokenIssued $event){ + // Handle refresh token issue + }); + $server->useEventDispatcher($dispatcher); + // Enable the authentication code grant on the server with a token TTL of 1 hour $server->enableGrantType( new AuthCodeGrant( diff --git a/examples/public/client_credentials.php b/examples/public/client_credentials.php index 51a1ca0b7..9ea04078e 100644 --- a/examples/public/client_credentials.php +++ b/examples/public/client_credentials.php @@ -8,7 +8,9 @@ */ use Laminas\Diactoros\Stream; +use League\Event\EventDispatcher; use League\OAuth2\Server\AuthorizationServer; +use League\OAuth2\Server\Events\ClientAuthenticationFailed; use League\OAuth2\Server\Exception\OAuthServerException; use OAuth2ServerExamples\Repositories\AccessTokenRepository; use OAuth2ServerExamples\Repositories\ClientRepository; @@ -42,6 +44,13 @@ 'lxZFUEsBCJ2Yb14IF2ygAHI5N4+ZAUXXaSeeJm6+twsUmIen' ); + // Setup EventDispatcher + $dispatcher = new EventDispatcher(); + $dispatcher->subscribeTo(ClientAuthenticationFailed::class, function(ClientAuthenticationFailed $event){ + // Handle client authentication failure + }); + $server->useEventDispatcher($dispatcher); + // Enable the client credentials grant on the server $server->enableGrantType( new \League\OAuth2\Server\Grant\ClientCredentialsGrant(), diff --git a/examples/public/implicit.php b/examples/public/implicit.php index ac43f5dd1..9d32aee78 100644 --- a/examples/public/implicit.php +++ b/examples/public/implicit.php @@ -8,7 +8,9 @@ */ use Laminas\Diactoros\Stream; +use League\Event\EventDispatcher; use League\OAuth2\Server\AuthorizationServer; +use League\OAuth2\Server\Events\ClientAuthenticationFailed; use League\OAuth2\Server\Exception\OAuthServerException; use League\OAuth2\Server\Grant\ImplicitGrant; use OAuth2ServerExamples\Entities\UserEntity; @@ -42,6 +44,13 @@ 'lxZFUEsBCJ2Yb14IF2ygAHI5N4+ZAUXXaSeeJm6+twsUmIen' ); + // Setup EventDispatcher + $dispatcher = new EventDispatcher(); + $dispatcher->subscribeTo(ClientAuthenticationFailed::class, function(ClientAuthenticationFailed $event){ + // Handle client authentication failure + }); + $server->useEventDispatcher($dispatcher); + // Enable the implicit grant on the server with a token TTL of 1 hour $server->enableGrantType(new ImplicitGrant(new \DateInterval('PT1H'))); diff --git a/examples/public/middleware_use.php b/examples/public/middleware_use.php index 9f958ed26..ef9ba5e0a 100644 --- a/examples/public/middleware_use.php +++ b/examples/public/middleware_use.php @@ -8,7 +8,12 @@ */ use Laminas\Diactoros\Stream; +use League\Event\EventDispatcher; use League\OAuth2\Server\AuthorizationServer; +use League\OAuth2\Server\Events\AccessTokenIssued; +use League\OAuth2\Server\Events\ClientAuthenticationFailed; +use League\OAuth2\Server\Events\RefreshTokenClientFailed; +use League\OAuth2\Server\Events\RefreshTokenIssued; use League\OAuth2\Server\Grant\AuthCodeGrant; use League\OAuth2\Server\Grant\RefreshTokenGrant; use League\OAuth2\Server\Middleware\AuthorizationServerMiddleware; @@ -48,6 +53,23 @@ 'lxZFUEsBCJ2Yb14IF2ygAHI5N4+ZAUXXaSeeJm6+twsUmIen' ); + // Setup EventDispatcher + $dispatcher = new EventDispatcher(); + $dispatcher->subscribeTo(ClientAuthenticationFailed::class, function(ClientAuthenticationFailed $event){ + // Handle client authentication failure + }); + $dispatcher->subscribeTo(RefreshTokenClientFailed::class, function(RefreshTokenClientFailed $event){ + // Handle refresh token client failure + }); + $dispatcher->subscribeTo(AccessTokenIssued::class, function(AccessTokenIssued $event){ + // Handle access token issue + }); + $dispatcher->subscribeTo(RefreshTokenIssued::class, function(RefreshTokenIssued $event){ + // Handle refresh token issue + }); + $server->useEventDispatcher($dispatcher); + + // Enable the authentication code grant on the server with a token TTL of 1 hour $server->enableGrantType( new AuthCodeGrant( diff --git a/examples/public/password.php b/examples/public/password.php index 6857e988a..9986b349c 100644 --- a/examples/public/password.php +++ b/examples/public/password.php @@ -1,6 +1,10 @@ subscribeTo(UserAuthenticationFailed::class, function(UserAuthenticationFailed $event){ + // Handle user authentication failure + }); + $dispatcher->subscribeTo(AccessTokenIssued::class, function(AccessTokenIssued $event){ + // Handle access token issue + }); + $dispatcher->subscribeTo(RefreshTokenIssued::class, function(RefreshTokenIssued $event){ + // Handle refresh token issue + }); + $server->useEventDispatcher($dispatcher); + + // Enable the password grant on the server with a token TTL of 1 hour $grant = new PasswordGrant( new UserRepository(), // instance of UserRepositoryInterface new RefreshTokenRepository() // instance of RefreshTokenRepositoryInterface ); $grant->setRefreshTokenTTL(new \DateInterval('P1M')); // refresh tokens will expire after 1 month - // Enable the password grant on the server with a token TTL of 1 hour $server->enableGrantType( $grant, new \DateInterval('PT1H') // access tokens will expire after 1 hour diff --git a/examples/public/refresh_token.php b/examples/public/refresh_token.php index 39be08262..a8f311a4e 100644 --- a/examples/public/refresh_token.php +++ b/examples/public/refresh_token.php @@ -7,7 +7,11 @@ * @link https://github.com/thephpleague/oauth2-server */ +use League\Event\EventDispatcher; use League\OAuth2\Server\AuthorizationServer; +use League\OAuth2\Server\Events\AccessTokenIssued; +use League\OAuth2\Server\Events\RefreshTokenClientFailed; +use League\OAuth2\Server\Events\RefreshTokenIssued; use League\OAuth2\Server\Exception\OAuthServerException; use League\OAuth2\Server\Grant\RefreshTokenGrant; use OAuth2ServerExamples\Repositories\AccessTokenRepository; @@ -42,6 +46,19 @@ 'lxZFUEsBCJ2Yb14IF2ygAHI5N4+ZAUXXaSeeJm6+twsUmIen' ); + // Setup EventDispatcher + $dispatcher = new EventDispatcher(); + $dispatcher->subscribeTo(RefreshTokenClientFailed::class, function(RefreshTokenClientFailed $event){ + // Handle refresh token client failure + }); + $dispatcher->subscribeTo(AccessTokenIssued::class, function(AccessTokenIssued $event){ + // Handle access token issue + }); + $dispatcher->subscribeTo(RefreshTokenIssued::class, function(RefreshTokenIssued $event){ + // Handle refresh token issue + }); + $server->useEventDispatcher($dispatcher); + // Enable the refresh token grant on the server $grant = new RefreshTokenGrant($refreshTokenRepository); $grant->setRefreshTokenTTL(new \DateInterval('P1M')); // The refresh token will expire in 1 month From 6eecb6def2e2c67ab60c17cf62a2febf681ec87c Mon Sep 17 00:00:00 2001 From: Eugene Borovov Date: Wed, 3 Mar 2021 21:40:31 +0700 Subject: [PATCH 07/10] Rename EventDispatchable to EventDispatcherAware Signed-off-by: Eugene Borovov --- src/AuthorizationServer.php | 8 ++++---- ...bleInterface.php => EventDispatcherAwareInterface.php} | 2 +- ...ispatchableTrait.php => EventDispatcherAwareTrait.php} | 2 +- src/Grant/AbstractGrant.php | 4 ++-- src/Grant/GrantTypeInterface.php | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) rename src/Events/{EventDispatchableInterface.php => EventDispatcherAwareInterface.php} (85%) rename src/Events/{EventDispatchableTrait.php => EventDispatcherAwareTrait.php} (94%) diff --git a/src/AuthorizationServer.php b/src/AuthorizationServer.php index 1700a8170..8be7a7b0d 100644 --- a/src/AuthorizationServer.php +++ b/src/AuthorizationServer.php @@ -11,8 +11,8 @@ use DateInterval; use Defuse\Crypto\Key; -use League\OAuth2\Server\Events\EventDispatchableInterface; -use League\OAuth2\Server\Events\EventDispatchableTrait; +use League\OAuth2\Server\Events\EventDispatcherAwareInterface; +use League\OAuth2\Server\Events\EventDispatcherAwareTrait; use League\OAuth2\Server\Exception\OAuthServerException; use League\OAuth2\Server\Grant\GrantTypeInterface; use League\OAuth2\Server\Repositories\AccessTokenRepositoryInterface; @@ -25,9 +25,9 @@ use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; -class AuthorizationServer implements EventDispatchableInterface +class AuthorizationServer implements EventDispatcherAwareInterface { - use EventDispatchableTrait; + use EventDispatcherAwareTrait; /** * @var GrantTypeInterface[] diff --git a/src/Events/EventDispatchableInterface.php b/src/Events/EventDispatcherAwareInterface.php similarity index 85% rename from src/Events/EventDispatchableInterface.php rename to src/Events/EventDispatcherAwareInterface.php index 42db70ab6..5226eea17 100644 --- a/src/Events/EventDispatchableInterface.php +++ b/src/Events/EventDispatcherAwareInterface.php @@ -4,7 +4,7 @@ use Psr\EventDispatcher\EventDispatcherInterface; -interface EventDispatchableInterface +interface EventDispatcherAwareInterface { public function useEventDispatcher(?EventDispatcherInterface $dispatcher): void; diff --git a/src/Events/EventDispatchableTrait.php b/src/Events/EventDispatcherAwareTrait.php similarity index 94% rename from src/Events/EventDispatchableTrait.php rename to src/Events/EventDispatcherAwareTrait.php index d89e2f0ba..494092229 100644 --- a/src/Events/EventDispatchableTrait.php +++ b/src/Events/EventDispatcherAwareTrait.php @@ -4,7 +4,7 @@ use Psr\EventDispatcher\EventDispatcherInterface; -trait EventDispatchableTrait +trait EventDispatcherAwareTrait { /** @var EventDispatcherInterface|null */ protected $eventDispatcher; diff --git a/src/Grant/AbstractGrant.php b/src/Grant/AbstractGrant.php index e365e7213..b1ff0e1d6 100644 --- a/src/Grant/AbstractGrant.php +++ b/src/Grant/AbstractGrant.php @@ -22,7 +22,7 @@ use League\OAuth2\Server\Entities\RefreshTokenEntityInterface; use League\OAuth2\Server\Entities\ScopeEntityInterface; use League\OAuth2\Server\Events\ClientAuthenticationFailed; -use League\OAuth2\Server\Events\EventDispatchableTrait; +use League\OAuth2\Server\Events\EventDispatcherAwareTrait; use League\OAuth2\Server\Exception\OAuthServerException; use League\OAuth2\Server\Exception\UniqueTokenIdentifierConstraintViolationException; use League\OAuth2\Server\RedirectUriValidators\RedirectUriValidator; @@ -42,7 +42,7 @@ */ abstract class AbstractGrant implements GrantTypeInterface { - use EventDispatchableTrait, CryptTrait; + use EventDispatcherAwareTrait, CryptTrait; const SCOPE_DELIMITER_STRING = ' '; diff --git a/src/Grant/GrantTypeInterface.php b/src/Grant/GrantTypeInterface.php index e9004c95d..10261d1f6 100644 --- a/src/Grant/GrantTypeInterface.php +++ b/src/Grant/GrantTypeInterface.php @@ -14,7 +14,7 @@ use DateInterval; use Defuse\Crypto\Key; use League\OAuth2\Server\CryptKey; -use League\OAuth2\Server\Events\EventDispatchableInterface; +use League\OAuth2\Server\Events\EventDispatcherAwareInterface; use League\OAuth2\Server\Repositories\AccessTokenRepositoryInterface; use League\OAuth2\Server\Repositories\ClientRepositoryInterface; use League\OAuth2\Server\Repositories\ScopeRepositoryInterface; @@ -25,7 +25,7 @@ /** * Grant type interface. */ -interface GrantTypeInterface extends EventDispatchableInterface +interface GrantTypeInterface extends EventDispatcherAwareInterface { /** * Set refresh token TTL. From 21accbc3b99e1813a33f1140b37b95c006c91ec5 Mon Sep 17 00:00:00 2001 From: Eugene Borovov Date: Wed, 3 Mar 2021 22:02:28 +0700 Subject: [PATCH 08/10] The dispatchEvent method removed from EventDispatcherAwareInterface Signed-off-by: Eugene Borovov --- src/Events/EventDispatcherAwareInterface.php | 2 -- src/Events/EventDispatcherAwareTrait.php | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Events/EventDispatcherAwareInterface.php b/src/Events/EventDispatcherAwareInterface.php index 5226eea17..b9bdfb685 100644 --- a/src/Events/EventDispatcherAwareInterface.php +++ b/src/Events/EventDispatcherAwareInterface.php @@ -7,6 +7,4 @@ interface EventDispatcherAwareInterface { public function useEventDispatcher(?EventDispatcherInterface $dispatcher): void; - - public function dispatchEvent(object $event): object; } \ No newline at end of file diff --git a/src/Events/EventDispatcherAwareTrait.php b/src/Events/EventDispatcherAwareTrait.php index 494092229..818ab3bbb 100644 --- a/src/Events/EventDispatcherAwareTrait.php +++ b/src/Events/EventDispatcherAwareTrait.php @@ -14,7 +14,7 @@ public function useEventDispatcher(?EventDispatcherInterface $eventDispatcher): $this->eventDispatcher = $eventDispatcher; } - public function dispatchEvent(object $event): object + protected function dispatchEvent(object $event): object { if ($this->eventDispatcher !== null) { return $this->eventDispatcher->dispatch($event); From 3de6f68f6a1c88584dee830fcdd58a570ac8ac30 Mon Sep 17 00:00:00 2001 From: Eugene Borovov Date: Sun, 7 Mar 2021 20:51:44 +0700 Subject: [PATCH 09/10] Fix code style Signed-off-by: Eugene Borovov --- examples/public/auth_code.php | 6 +++--- examples/public/client_credentials.php | 2 +- examples/public/implicit.php | 2 +- examples/public/middleware_use.php | 8 ++++---- examples/public/password.php | 6 +++--- examples/public/refresh_token.php | 6 +++--- src/Events/AbstractEvent.php | 2 +- src/Events/AccessTokenIssued.php | 2 +- src/Events/ClientAuthenticationFailed.php | 2 +- src/Events/EventDispatcherAwareInterface.php | 2 +- src/Events/EventDispatcherAwareTrait.php | 2 +- src/Events/RefreshTokenClientFailed.php | 2 +- src/Events/RefreshTokenIssued.php | 2 +- src/Events/UserAuthenticationFailed.php | 2 +- src/Grant/AbstractGrant.php | 2 +- 15 files changed, 24 insertions(+), 24 deletions(-) diff --git a/examples/public/auth_code.php b/examples/public/auth_code.php index ebb6dd85f..0b6161011 100644 --- a/examples/public/auth_code.php +++ b/examples/public/auth_code.php @@ -52,13 +52,13 @@ // Setup EventDispatcher $dispatcher = new EventDispatcher(); - $dispatcher->subscribeTo(ClientAuthenticationFailed::class, function(ClientAuthenticationFailed $event){ + $dispatcher->subscribeTo(ClientAuthenticationFailed::class, function (ClientAuthenticationFailed $event) { // Handle client authentication failure }); - $dispatcher->subscribeTo(AccessTokenIssued::class, function(AccessTokenIssued $event){ + $dispatcher->subscribeTo(AccessTokenIssued::class, function (AccessTokenIssued $event) { // Handle access token issue }); - $dispatcher->subscribeTo(RefreshTokenIssued::class, function(RefreshTokenIssued $event){ + $dispatcher->subscribeTo(RefreshTokenIssued::class, function (RefreshTokenIssued $event) { // Handle refresh token issue }); $server->useEventDispatcher($dispatcher); diff --git a/examples/public/client_credentials.php b/examples/public/client_credentials.php index 9ea04078e..a59e37687 100644 --- a/examples/public/client_credentials.php +++ b/examples/public/client_credentials.php @@ -46,7 +46,7 @@ // Setup EventDispatcher $dispatcher = new EventDispatcher(); - $dispatcher->subscribeTo(ClientAuthenticationFailed::class, function(ClientAuthenticationFailed $event){ + $dispatcher->subscribeTo(ClientAuthenticationFailed::class, function (ClientAuthenticationFailed $event) { // Handle client authentication failure }); $server->useEventDispatcher($dispatcher); diff --git a/examples/public/implicit.php b/examples/public/implicit.php index 9d32aee78..cd8a5794d 100644 --- a/examples/public/implicit.php +++ b/examples/public/implicit.php @@ -46,7 +46,7 @@ // Setup EventDispatcher $dispatcher = new EventDispatcher(); - $dispatcher->subscribeTo(ClientAuthenticationFailed::class, function(ClientAuthenticationFailed $event){ + $dispatcher->subscribeTo(ClientAuthenticationFailed::class, function (ClientAuthenticationFailed $event) { // Handle client authentication failure }); $server->useEventDispatcher($dispatcher); diff --git a/examples/public/middleware_use.php b/examples/public/middleware_use.php index ef9ba5e0a..7c4f3a8a7 100644 --- a/examples/public/middleware_use.php +++ b/examples/public/middleware_use.php @@ -55,16 +55,16 @@ // Setup EventDispatcher $dispatcher = new EventDispatcher(); - $dispatcher->subscribeTo(ClientAuthenticationFailed::class, function(ClientAuthenticationFailed $event){ + $dispatcher->subscribeTo(ClientAuthenticationFailed::class, function (ClientAuthenticationFailed $event) { // Handle client authentication failure }); - $dispatcher->subscribeTo(RefreshTokenClientFailed::class, function(RefreshTokenClientFailed $event){ + $dispatcher->subscribeTo(RefreshTokenClientFailed::class, function (RefreshTokenClientFailed $event) { // Handle refresh token client failure }); - $dispatcher->subscribeTo(AccessTokenIssued::class, function(AccessTokenIssued $event){ + $dispatcher->subscribeTo(AccessTokenIssued::class, function (AccessTokenIssued $event) { // Handle access token issue }); - $dispatcher->subscribeTo(RefreshTokenIssued::class, function(RefreshTokenIssued $event){ + $dispatcher->subscribeTo(RefreshTokenIssued::class, function (RefreshTokenIssued $event) { // Handle refresh token issue }); $server->useEventDispatcher($dispatcher); diff --git a/examples/public/password.php b/examples/public/password.php index 9986b349c..e9441f55f 100644 --- a/examples/public/password.php +++ b/examples/public/password.php @@ -33,13 +33,13 @@ // Setup EventDispatcher $dispatcher = new EventDispatcher(); - $dispatcher->subscribeTo(UserAuthenticationFailed::class, function(UserAuthenticationFailed $event){ + $dispatcher->subscribeTo(UserAuthenticationFailed::class, function (UserAuthenticationFailed $event) { // Handle user authentication failure }); - $dispatcher->subscribeTo(AccessTokenIssued::class, function(AccessTokenIssued $event){ + $dispatcher->subscribeTo(AccessTokenIssued::class, function (AccessTokenIssued $event) { // Handle access token issue }); - $dispatcher->subscribeTo(RefreshTokenIssued::class, function(RefreshTokenIssued $event){ + $dispatcher->subscribeTo(RefreshTokenIssued::class, function (RefreshTokenIssued $event) { // Handle refresh token issue }); $server->useEventDispatcher($dispatcher); diff --git a/examples/public/refresh_token.php b/examples/public/refresh_token.php index a8f311a4e..421349d75 100644 --- a/examples/public/refresh_token.php +++ b/examples/public/refresh_token.php @@ -48,13 +48,13 @@ // Setup EventDispatcher $dispatcher = new EventDispatcher(); - $dispatcher->subscribeTo(RefreshTokenClientFailed::class, function(RefreshTokenClientFailed $event){ + $dispatcher->subscribeTo(RefreshTokenClientFailed::class, function (RefreshTokenClientFailed $event) { // Handle refresh token client failure }); - $dispatcher->subscribeTo(AccessTokenIssued::class, function(AccessTokenIssued $event){ + $dispatcher->subscribeTo(AccessTokenIssued::class, function (AccessTokenIssued $event) { // Handle access token issue }); - $dispatcher->subscribeTo(RefreshTokenIssued::class, function(RefreshTokenIssued $event){ + $dispatcher->subscribeTo(RefreshTokenIssued::class, function (RefreshTokenIssued $event) { // Handle refresh token issue }); $server->useEventDispatcher($dispatcher); diff --git a/src/Events/AbstractEvent.php b/src/Events/AbstractEvent.php index 3f669c465..f926c4a63 100644 --- a/src/Events/AbstractEvent.php +++ b/src/Events/AbstractEvent.php @@ -36,4 +36,4 @@ public function getOccuredOn(): \DateTimeImmutable { return $this->occuredOn; } -} \ No newline at end of file +} diff --git a/src/Events/AccessTokenIssued.php b/src/Events/AccessTokenIssued.php index 8c5b21fc0..951985144 100644 --- a/src/Events/AccessTokenIssued.php +++ b/src/Events/AccessTokenIssued.php @@ -23,4 +23,4 @@ public function getAccessToken(): AccessTokenEntityInterface { return $this->accessToken; } -} \ No newline at end of file +} diff --git a/src/Events/ClientAuthenticationFailed.php b/src/Events/ClientAuthenticationFailed.php index f8c5f4a2b..f6cb73955 100644 --- a/src/Events/ClientAuthenticationFailed.php +++ b/src/Events/ClientAuthenticationFailed.php @@ -22,4 +22,4 @@ public function getClientId(): ?string { return $this->clientId; } -} \ No newline at end of file +} diff --git a/src/Events/EventDispatcherAwareInterface.php b/src/Events/EventDispatcherAwareInterface.php index b9bdfb685..93efa03fd 100644 --- a/src/Events/EventDispatcherAwareInterface.php +++ b/src/Events/EventDispatcherAwareInterface.php @@ -7,4 +7,4 @@ interface EventDispatcherAwareInterface { public function useEventDispatcher(?EventDispatcherInterface $dispatcher): void; -} \ No newline at end of file +} diff --git a/src/Events/EventDispatcherAwareTrait.php b/src/Events/EventDispatcherAwareTrait.php index 818ab3bbb..5739ee29a 100644 --- a/src/Events/EventDispatcherAwareTrait.php +++ b/src/Events/EventDispatcherAwareTrait.php @@ -22,4 +22,4 @@ protected function dispatchEvent(object $event): object return $event; } -} \ No newline at end of file +} diff --git a/src/Events/RefreshTokenClientFailed.php b/src/Events/RefreshTokenClientFailed.php index b1b961109..0276c860c 100644 --- a/src/Events/RefreshTokenClientFailed.php +++ b/src/Events/RefreshTokenClientFailed.php @@ -32,4 +32,4 @@ public function getRefreshTokenData(): array { return $this->refreshTokenData; } -} \ No newline at end of file +} diff --git a/src/Events/RefreshTokenIssued.php b/src/Events/RefreshTokenIssued.php index 2b8074a0e..97a27c09b 100644 --- a/src/Events/RefreshTokenIssued.php +++ b/src/Events/RefreshTokenIssued.php @@ -23,4 +23,4 @@ public function getRefreshToken(): RefreshTokenEntityInterface { return $this->refreshToken; } -} \ No newline at end of file +} diff --git a/src/Events/UserAuthenticationFailed.php b/src/Events/UserAuthenticationFailed.php index 20e9d151a..65f50bd01 100644 --- a/src/Events/UserAuthenticationFailed.php +++ b/src/Events/UserAuthenticationFailed.php @@ -22,4 +22,4 @@ public function getUsername(): ?string { return $this->username; } -} \ No newline at end of file +} diff --git a/src/Grant/AbstractGrant.php b/src/Grant/AbstractGrant.php index b1ff0e1d6..9936e003a 100644 --- a/src/Grant/AbstractGrant.php +++ b/src/Grant/AbstractGrant.php @@ -225,7 +225,7 @@ protected function validateClient(ServerRequestInterface $request) * getClientEntity might return null. By contrast, this method will * always either return a ClientEntityInterface or throw. * - * @param string $clientId + * @param string $clientId * @param ServerRequestInterface $request * * @return ClientEntityInterface From 27ff32f13a122c4f64414a3de7f6bdc8748c3934 Mon Sep 17 00:00:00 2001 From: Eugene Borovov Date: Tue, 13 Jul 2021 00:43:37 +0700 Subject: [PATCH 10/10] Resolve conflict --- src/Grant/RefreshTokenGrant.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Grant/RefreshTokenGrant.php b/src/Grant/RefreshTokenGrant.php index 257a382cf..324169175 100644 --- a/src/Grant/RefreshTokenGrant.php +++ b/src/Grant/RefreshTokenGrant.php @@ -78,9 +78,10 @@ public function respondToAccessTokenRequest( if ($this->revokeRefreshTokens) { $refreshToken = $this->issueRefreshToken($accessToken); - if ($refreshToken !== null) { - $this->dispatchEvent(new RefreshTokenIssued($refreshToken, $request)); - $responseType->setRefreshToken($refreshToken); + if ($refreshToken !== null) { + $this->dispatchEvent(new RefreshTokenIssued($refreshToken, $request)); + $responseType->setRefreshToken($refreshToken); + } } return $responseType;