diff --git a/src/Grant/AbstractGrant.php b/src/Grant/AbstractGrant.php index 6a9390f3..37dc9aca 100644 --- a/src/Grant/AbstractGrant.php +++ b/src/Grant/AbstractGrant.php @@ -24,6 +24,7 @@ use League\OAuth2\Server\Repositories\AuthCodeRepositoryInterface; use League\OAuth2\Server\Repositories\ClientRepositoryInterface; use League\OAuth2\Server\Repositories\RefreshTokenRepositoryInterface; use League\OAuth2\Server\Repositories\ScopeRepositoryInterface; +use League\OAuth2\Server\Repositories\UserRepositoryInterface; use Psr\Http\Message\ServerRequestInterface; /** @@ -58,12 +59,17 @@ abstract class AbstractGrant implements GrantTypeInterface /** * @var \League\OAuth2\Server\Repositories\AuthCodeRepositoryInterface */ - private $authCodeRepository; + protected $authCodeRepository; /** * @var \League\OAuth2\Server\Repositories\RefreshTokenRepositoryInterface */ - private $refreshTokenRepository; + protected $refreshTokenRepository; + + /** + * @var \League\OAuth2\Server\Repositories\UserRepositoryInterface + */ + protected $userRepository; /** * @var string @@ -120,6 +126,14 @@ abstract class AbstractGrant implements GrantTypeInterface $this->authCodeRepository = $authCodeRepository; } + /** + * @param \League\OAuth2\Server\Repositories\UserRepositoryInterface $userRepository + */ + public function setUserRepository(UserRepositoryInterface $userRepository) + { + $this->userRepository = $userRepository; + } + /** * @param string $pathToPrivateKey */ @@ -136,14 +150,6 @@ abstract class AbstractGrant implements GrantTypeInterface $this->pathToPublicKey = $pathToPublicKey; } - /** - * {@inheritdoc} - */ - public function setEmitter(EmitterInterface $emitter = null) - { - $this->emitter = $emitter; - } - /** * {@inheritdoc} */ @@ -152,22 +158,6 @@ abstract class AbstractGrant implements GrantTypeInterface $this->refreshTokenTTL = $refreshTokenTTL; } - /** - * @return AuthCodeRepositoryInterface - */ - protected function getAuthCodeRepository() - { - return $this->authCodeRepository; - } - - /** - * @return RefreshTokenRepositoryInterface - */ - protected function getRefreshTokenRepository() - { - return $this->refreshTokenRepository; - } - /** * Validate the client. * diff --git a/src/Grant/AuthCodeGrant.php b/src/Grant/AuthCodeGrant.php index bc65dc9a..f1db4921 100644 --- a/src/Grant/AuthCodeGrant.php +++ b/src/Grant/AuthCodeGrant.php @@ -24,11 +24,6 @@ class AuthCodeGrant extends AbstractAuthorizeGrant */ private $authCodeTTL; - /** - * @var \League\OAuth2\Server\Repositories\UserRepositoryInterface - */ - private $userRepository; - /** * @param \League\OAuth2\Server\Repositories\AuthCodeRepositoryInterface $authCodeRepository * @param \League\OAuth2\Server\Repositories\RefreshTokenRepositoryInterface $refreshTokenRepository @@ -49,7 +44,7 @@ class AuthCodeGrant extends AbstractAuthorizeGrant ) { $this->setAuthCodeRepository($authCodeRepository); $this->setRefreshTokenRepository($refreshTokenRepository); - $this->userRepository = $userRepository; + $this->setUserRepository($userRepository); $this->authCodeTTL = $authCodeTTL; $this->refreshTokenTTL = new \DateInterval('P1M'); $this->loginTemplate = $loginTemplate; @@ -262,7 +257,7 @@ class AuthCodeGrant extends AbstractAuthorizeGrant throw OAuthServerException::invalidRequest('code', 'Authorization code has expired'); } - if ($this->getAuthCodeRepository()->isAuthCodeRevoked($authCodePayload->auth_code_id) === true) { + if ($this->authCodeRepository->isAuthCodeRevoked($authCodePayload->auth_code_id) === true) { throw OAuthServerException::invalidRequest('code', 'Authorization code has been revoked'); } diff --git a/src/Grant/ImplicitGrant.php b/src/Grant/ImplicitGrant.php index 7f846f90..4e306d76 100644 --- a/src/Grant/ImplicitGrant.php +++ b/src/Grant/ImplicitGrant.php @@ -16,11 +16,6 @@ use Zend\Diactoros\Uri; class ImplicitGrant extends AbstractAuthorizeGrant { - /** - * @var \League\OAuth2\Server\Repositories\UserRepositoryInterface - */ - private $userRepository; - /** * @param \League\OAuth2\Server\Repositories\UserRepositoryInterface $userRepository * @param string|null $loginTemplate @@ -33,7 +28,7 @@ class ImplicitGrant extends AbstractAuthorizeGrant $authorizeTemplate = null, RendererInterface $templateRenderer = null ) { - $this->userRepository = $userRepository; + $this->setUserRepository($userRepository); $this->refreshTokenTTL = new \DateInterval('P1M'); $this->loginTemplate = $loginTemplate; $this->authorizeTemplate = $authorizeTemplate; diff --git a/src/Grant/PasswordGrant.php b/src/Grant/PasswordGrant.php index d7328f71..f9298722 100644 --- a/src/Grant/PasswordGrant.php +++ b/src/Grant/PasswordGrant.php @@ -23,11 +23,6 @@ use Psr\Http\Message\ServerRequestInterface; */ class PasswordGrant extends AbstractGrant { - /** - * @var \League\OAuth2\Server\Repositories\UserRepositoryInterface - */ - private $userRepository; - /** * @param \League\OAuth2\Server\Repositories\UserRepositoryInterface $userRepository * @param \League\OAuth2\Server\Repositories\RefreshTokenRepositoryInterface $refreshTokenRepository @@ -36,7 +31,7 @@ class PasswordGrant extends AbstractGrant UserRepositoryInterface $userRepository, RefreshTokenRepositoryInterface $refreshTokenRepository ) { - $this->userRepository = $userRepository; + $this->setUserRepository($userRepository); $this->setRefreshTokenRepository($refreshTokenRepository); $this->refreshTokenTTL = new \DateInterval('P1M'); diff --git a/src/Grant/RefreshTokenGrant.php b/src/Grant/RefreshTokenGrant.php index f1aebd3d..04d078e4 100644 --- a/src/Grant/RefreshTokenGrant.php +++ b/src/Grant/RefreshTokenGrant.php @@ -74,13 +74,13 @@ class RefreshTokenGrant extends AbstractGrant // Expire old tokens $this->accessTokenRepository->revokeAccessToken($oldRefreshToken['access_token_id']); - $this->getRefreshTokenRepository()->revokeRefreshToken($oldRefreshToken['refresh_token_id']); + $this->refreshTokenRepository->revokeRefreshToken($oldRefreshToken['refresh_token_id']); // Issue and persist new tokens $accessToken = $this->issueAccessToken($accessTokenTTL, $client, $oldRefreshToken['user_id'], $scopes); $refreshToken = $this->issueRefreshToken($accessToken); $this->accessTokenRepository->persistNewAccessToken($accessToken); - $this->getRefreshTokenRepository()->persistNewRefreshToken($refreshToken); + $this->refreshTokenRepository->persistNewRefreshToken($refreshToken); // Inject tokens into response $responseType->setAccessToken($accessToken); @@ -126,7 +126,7 @@ class RefreshTokenGrant extends AbstractGrant throw OAuthServerException::invalidRefreshToken('Token has expired'); } - if ($this->getRefreshTokenRepository()->isRefreshTokenRevoked($refreshTokenData['refresh_token_id']) === true) { + if ($this->refreshTokenRepository->isRefreshTokenRevoked($refreshTokenData['refresh_token_id']) === true) { throw OAuthServerException::invalidRefreshToken('Token has been revoked'); }