diff --git a/src/Entity/AbstractToken.php b/src/Entity/AbstractTokenEntity.php similarity index 67% rename from src/Entity/AbstractToken.php rename to src/Entity/AbstractTokenEntity.php index 4a186e9f..2af5314c 100644 --- a/src/Entity/AbstractToken.php +++ b/src/Entity/AbstractTokenEntity.php @@ -20,7 +20,7 @@ use Symfony\Component\HttpFoundation\ParameterBag; /** * Abstract token class */ -abstract class AbstractToken +abstract class AbstractTokenEntity { /** * Access token ID @@ -30,7 +30,7 @@ abstract class AbstractToken /** * Associated session - * @var \League\OAuth2\Server\Session + * @var \League\OAuth2\Server\SessionEntity */ protected $session; @@ -48,7 +48,7 @@ abstract class AbstractToken /** * Authorization or resource server - * @var \League\OAuth2\Server\Authorization|\League\OAuth2\Server\Resource + * @var \League\OAuth2\Server\AbstractServer */ protected $server; @@ -65,29 +65,15 @@ abstract class AbstractToken /** * Set session - * @param \League\OAuth2\Server\Session $session + * @param \League\OAuth2\Server\SessionEntity $session * @return self */ - public function setSession(Session $session) + public function setSession(SessionEntity $session) { $this->session = $session; return $this; } - /** - * Get session - * @return \League\OAuth2\Server\Session - */ - public function getSession() - { - if ($this->session instanceof Session) { - return $this->session; - } - - $this->session = $this->server->getStorage('session')->getByAccessToken($this->token); - return $this->session; - } - /** * Set the expire time of the token * @param integer $expireTime Unix time stamp @@ -130,10 +116,10 @@ abstract class AbstractToken /** * Associate a scope - * @param \League\OAuth2\Server\Entity\Scope $scope + * @param \League\OAuth2\Server\Entity\ScopeEntity $scope * @return self */ - public function associateScope(Scope $scope) + public function associateScope(ScopeEntity $scope) { if (!isset($this->scopes[$scope->getId()])) { $this->scopes[$scope->getId()] = $scope; @@ -142,35 +128,6 @@ abstract class AbstractToken return $this; } - /** - * Check if access token has an associated scope - * @param string $scope Scope to check - * @return bool - */ - public function hasScope($scope) - { - if ($this->scopes === null) { - $this->getScopes(); - } - - return isset($this->scopes[$scope]); - } - - /** - * Return all scopes associated with the session - * @return array Array of \League\OAuth2\Server\Entity\Scope - */ - public function getScopes() - { - if ($this->scopes === null) { - $this->scopes = $this->formatScopes( - $this->server->getStorage('access_token')->getScopes($this) - ); - } - - return $this->scopes; - } - /** * Format the local scopes array * @param array $unformatted Array of \League\OAuth2\Server\Entity\Scope @@ -180,7 +137,7 @@ abstract class AbstractToken { $scopes = []; foreach ($unformatted as $scope) { - if ($scope instanceof Scope) { + if ($scope instanceof ScopeEntity) { $scopes[$scope->getId()] = $scope; } } diff --git a/src/Entity/AccessToken.php b/src/Entity/AccessTokenEntity.php similarity index 52% rename from src/Entity/AccessToken.php rename to src/Entity/AccessTokenEntity.php index 68c75cb3..163545d2 100644 --- a/src/Entity/AccessToken.php +++ b/src/Entity/AccessTokenEntity.php @@ -20,8 +20,51 @@ use Symfony\Component\HttpFoundation\ParameterBag; /** * Access token entity class */ -class AccessToken extends AbstractToken +class AccessTokenEntity extends AbstractTokenEntity { + /** + * Get session + * @return \League\OAuth2\Server\SessionEntity + */ + public function getSession() + { + if ($this->session instanceof SessionEntity) { + return $this->session; + } + + $this->session = $this->server->getStorage('session')->getByAccessToken($this); + return $this->session; + } + + /** + * Check if access token has an associated scope + * @param string $scope Scope to check + * @return bool + */ + public function hasScope($scope) + { + if ($this->scopes === null) { + $this->getScopes(); + } + + return isset($this->scopes[$scope]); + } + + /** + * Return all scopes associated with the session + * @return array Array of \League\OAuth2\Server\Entity\Scope + */ + public function getScopes() + { + if ($this->scopes === null) { + $this->scopes = $this->formatScopes( + $this->server->getStorage('access_token')->getScopes($this) + ); + } + + return $this->scopes; + } + /** * {@inheritdoc} */ diff --git a/src/Entity/AuthCode.php b/src/Entity/AuthCodeEntity.php similarity index 94% rename from src/Entity/AuthCode.php rename to src/Entity/AuthCodeEntity.php index ea0ec9de..514b87bc 100644 --- a/src/Entity/AuthCode.php +++ b/src/Entity/AuthCodeEntity.php @@ -20,7 +20,7 @@ use Symfony\Component\HttpFoundation\ParameterBag; /** * Access token entity class */ -class AuthCode extends AbstractToken +class AuthCodeEntity extends AbstractTokenEntity { /** * Redirect URI @@ -49,7 +49,7 @@ class AuthCode extends AbstractToken } /** - * [generateRedirectUri description] + * Generate a redirect URI * @param string $state The state parameter if set by the client * @param string $queryDelimeter The query delimiter ('?' for auth code grant, '#' for implicit grant) * @return string @@ -69,11 +69,11 @@ class AuthCode extends AbstractToken */ public function getSession() { - if ($this->session instanceof Session) { + if ($this->session instanceof SessionEntity) { return $this->session; } - $this->session = $this->server->getStorage('session')->getByAuthCode($this->token); + $this->session = $this->server->getStorage('session')->getByAuthCode($this); return $this->session; } diff --git a/src/Entity/Client.php b/src/Entity/ClientEntity.php similarity index 99% rename from src/Entity/Client.php rename to src/Entity/ClientEntity.php index d7589a44..40e0e542 100644 --- a/src/Entity/Client.php +++ b/src/Entity/ClientEntity.php @@ -17,7 +17,7 @@ use League\OAuth2\Server\AbstractServer; /** * Client entity class */ -class Client +class ClientEntity { /** * Client identifier diff --git a/src/Entity/RefreshToken.php b/src/Entity/RefreshTokenEntity.php similarity index 87% rename from src/Entity/RefreshToken.php rename to src/Entity/RefreshTokenEntity.php index a41c1991..ce230283 100644 --- a/src/Entity/RefreshToken.php +++ b/src/Entity/RefreshTokenEntity.php @@ -20,7 +20,7 @@ use Symfony\Component\HttpFoundation\ParameterBag; /** * Refresh token entity class */ -class RefreshToken extends AbstractToken +class RefreshTokenEntity extends AbstractTokenEntity { /** * Access token associated to refresh token @@ -30,10 +30,10 @@ class RefreshToken extends AbstractToken /** * Associate an access token - * @param \League\OAuth2\Server\Entity\AccessToken $accessToken + * @param \League\OAuth2\Server\Entity\AccessTokenEntity $accessToken * @return self */ - public function setAccessToken(AccessToken $accessToken) + public function setAccessToken(AccessTokenEntity $accessToken) { $this->accessToken = $accessToken; return $this; @@ -45,7 +45,7 @@ class RefreshToken extends AbstractToken */ public function getAccessToken() { - if (! $this->accessToken instanceof AccessToken) { + if (! $this->accessToken instanceof AccessTokenEntity) { $this->accessToken = $this->server->getStorage('access_token')->getByRefreshToken($this); } return $this->accessToken; diff --git a/src/Entity/Scope.php b/src/Entity/ScopeEntity.php similarity index 94% rename from src/Entity/Scope.php rename to src/Entity/ScopeEntity.php index b2ad9f4e..7e4019aa 100644 --- a/src/Entity/Scope.php +++ b/src/Entity/ScopeEntity.php @@ -17,7 +17,7 @@ use League\OAuth2\Server\AbstractServer; /** * Scope entity class */ -class Scope +class ScopeEntity { /** * Scope identifier @@ -33,7 +33,7 @@ class Scope /** * Authorization or resource server - * @var \League\OAuth2\Server\Authorization|\League\OAuth2\Server\Resource + * @var \League\OAuth2\Server\AbstractServer */ protected $server; diff --git a/src/Entity/Session.php b/src/Entity/SessionEntity.php similarity index 86% rename from src/Entity/Session.php rename to src/Entity/SessionEntity.php index ab166253..95721cf7 100644 --- a/src/Entity/Session.php +++ b/src/Entity/SessionEntity.php @@ -20,7 +20,7 @@ use Symfony\Component\HttpFoundation\ParameterBag; /** * Session entity grant */ -class Session +class SessionEntity { /** * Session identifier @@ -48,19 +48,19 @@ class Session /** * Auth code - * @var \League\OAuth2\Server\Entity\AuthCode + * @var \League\OAuth2\Server\Entity\AuthCodeEntity */ protected $authCode; /** * Access token - * @var \League\OAuth2\Server\Entity\AccessToken + * @var \League\OAuth2\Server\Entity\AccessTokenEntity */ protected $accessToken; /** * Refresh token - * @var \League\OAuth2\Server\Entity\RefreshToken + * @var \League\OAuth2\Server\Entity\RefreshTokenEntity */ protected $refreshToken; @@ -109,10 +109,10 @@ class Session /** * Associate a scope - * @param \League\OAuth2\Server\Entity\Scope $scope + * @param \League\OAuth2\Server\Entity\ScopeEntity $scope * @return self */ - public function associateScope(Scope $scope) + public function associateScope(ScopeEntity $scope) { if (!isset($this->scopes[$scope->getId()])) { $this->scopes[$scope->getId()] = $scope; @@ -158,7 +158,7 @@ class Session $scopes = []; if (is_array($unformated)) { foreach ($unformated as $scope) { - if ($scope instanceof Scope) { + if ($scope instanceof ScopeEntity) { $scopes[$scope->getId()] = $scope; } } @@ -168,10 +168,10 @@ class Session /** * Associate an access token with the session - * @param \League\OAuth2\Server\Entity\AccessToken $accessToken + * @param \League\OAuth2\Server\Entity\AccessTokenEntity $accessToken * @return self */ - public function associateAccessToken(AccessToken $accessToken) + public function associateAccessToken(AccessTokenEntity $accessToken) { $this->accessToken = $accessToken; return $this; @@ -179,10 +179,10 @@ class Session /** * Associate a refresh token with the session - * @param \League\OAuth2\Server\Entity\RefreshToken $refreshToken + * @param \League\OAuth2\Server\Entity\RefreshTokenEntity $refreshToken * @return self */ - public function associateRefreshToken(RefreshToken $refreshToken) + public function associateRefreshToken(RefreshTokenEntity $refreshToken) { $this->refreshToken = $refreshToken; return $this; @@ -190,10 +190,10 @@ class Session /** * Associate a client with the session - * @param League\OAuth2\Server\Entity\Client $client The client + * @param League\OAuth2\Server\Entity\ClientEntity $client The client * @return self */ - public function associateClient(Client $client) + public function associateClient(ClientEntity $client) { $this->client = $client; return $this; @@ -205,7 +205,7 @@ class Session */ public function getClient() { - if ($this->client instanceof Client) { + if ($this->client instanceof ClientEntity) { return $this->client; }