From 4bb5b747c15285e5e7fb3cea3dea8f718f74b018 Mon Sep 17 00:00:00 2001 From: Marc Ypes Date: Tue, 13 Nov 2018 01:00:23 +0100 Subject: [PATCH] Replace fqn with unqualified name --- .styleci.yml | 1 + src/AuthorizationServer.php | 11 +++--- .../BearerTokenValidator.php | 13 ++++--- src/CryptKey.php | 13 ++++--- src/CryptTrait.php | 14 ++++--- src/Entities/RefreshTokenEntityInterface.php | 8 ++-- src/Entities/ScopeEntityInterface.php | 4 +- src/Entities/TokenInterface.php | 8 ++-- src/Entities/Traits/AccessTokenTrait.php | 3 +- src/Entities/Traits/RefreshTokenTrait.php | 9 +++-- src/Entities/Traits/TokenEntityTrait.php | 9 +++-- src/Exception/OAuthServerException.php | 3 +- src/Grant/AbstractGrant.php | 38 +++++++++++-------- src/Grant/AuthCodeGrant.php | 27 +++++++------ src/Grant/ClientCredentialsGrant.php | 3 +- src/Grant/GrantTypeInterface.php | 9 +++-- src/Grant/ImplicitGrant.php | 33 ++++++++-------- src/Grant/PasswordGrant.php | 5 ++- src/Grant/RefreshTokenGrant.php | 8 ++-- .../AuthorizationServerMiddleware.php | 3 +- src/Middleware/ResourceServerMiddleware.php | 5 ++- src/ResponseTypes/AbstractResponseType.php | 2 +- src/ResponseTypes/BearerTokenResponse.php | 3 +- 23 files changed, 137 insertions(+), 95 deletions(-) diff --git a/.styleci.yml b/.styleci.yml index d3498157..a77e823b 100644 --- a/.styleci.yml +++ b/.styleci.yml @@ -4,6 +4,7 @@ enabled: - binary_operator_spaces - blank_line_before_return - concat_with_spaces + - fully_qualified_strict_types - function_typehint_space - hash_to_slash_comment - include diff --git a/src/AuthorizationServer.php b/src/AuthorizationServer.php index df079b70..35597de1 100644 --- a/src/AuthorizationServer.php +++ b/src/AuthorizationServer.php @@ -9,6 +9,7 @@ namespace League\OAuth2\Server; +use DateInterval; use Defuse\Crypto\Key; use League\Event\EmitterAwareInterface; use League\Event\EmitterAwareTrait; @@ -34,7 +35,7 @@ class AuthorizationServer implements EmitterAwareInterface protected $enabledGrantTypes = []; /** - * @var \DateInterval[] + * @var DateInterval[] */ protected $grantTypeAccessTokenTTL = []; @@ -126,12 +127,12 @@ class AuthorizationServer implements EmitterAwareInterface * Enable a grant type on the server. * * @param GrantTypeInterface $grantType - * @param null|\DateInterval $accessTokenTTL + * @param null|DateInterval $accessTokenTTL */ - public function enableGrantType(GrantTypeInterface $grantType, \DateInterval $accessTokenTTL = null) + public function enableGrantType(GrantTypeInterface $grantType, DateInterval $accessTokenTTL = null) { - if ($accessTokenTTL instanceof \DateInterval === false) { - $accessTokenTTL = new \DateInterval('PT1H'); + if ($accessTokenTTL instanceof DateInterval === false) { + $accessTokenTTL = new DateInterval('PT1H'); } $grantType->setAccessTokenRepository($this->accessTokenRepository); diff --git a/src/AuthorizationValidators/BearerTokenValidator.php b/src/AuthorizationValidators/BearerTokenValidator.php index 2efa3c8e..924c2fb5 100644 --- a/src/AuthorizationValidators/BearerTokenValidator.php +++ b/src/AuthorizationValidators/BearerTokenValidator.php @@ -9,6 +9,8 @@ namespace League\OAuth2\Server\AuthorizationValidators; +use BadMethodCallException; +use InvalidArgumentException; use Lcobucci\JWT\Parser; use Lcobucci\JWT\Signer\Rsa\Sha256; use Lcobucci\JWT\ValidationData; @@ -17,6 +19,7 @@ use League\OAuth2\Server\CryptTrait; use League\OAuth2\Server\Exception\OAuthServerException; use League\OAuth2\Server\Repositories\AccessTokenRepositoryInterface; use Psr\Http\Message\ServerRequestInterface; +use RuntimeException; class BearerTokenValidator implements AuthorizationValidatorInterface { @@ -28,7 +31,7 @@ class BearerTokenValidator implements AuthorizationValidatorInterface private $accessTokenRepository; /** - * @var \League\OAuth2\Server\CryptKey + * @var CryptKey */ protected $publicKey; @@ -43,7 +46,7 @@ class BearerTokenValidator implements AuthorizationValidatorInterface /** * Set the public key * - * @param \League\OAuth2\Server\CryptKey $key + * @param CryptKey $key */ public function setPublicKey(CryptKey $key) { @@ -69,7 +72,7 @@ class BearerTokenValidator implements AuthorizationValidatorInterface if ($token->verify(new Sha256(), $this->publicKey->getKeyPath()) === false) { throw OAuthServerException::accessDenied('Access token could not be verified'); } - } catch (\BadMethodCallException $exception) { + } catch (BadMethodCallException $exception) { throw OAuthServerException::accessDenied('Access token is not signed'); } @@ -92,10 +95,10 @@ class BearerTokenValidator implements AuthorizationValidatorInterface ->withAttribute('oauth_client_id', $token->getClaim('aud')) ->withAttribute('oauth_user_id', $token->getClaim('sub')) ->withAttribute('oauth_scopes', $token->getClaim('scopes')); - } catch (\InvalidArgumentException $exception) { + } catch (InvalidArgumentException $exception) { // JWT couldn't be parsed so return the request as is throw OAuthServerException::accessDenied($exception->getMessage()); - } catch (\RuntimeException $exception) { + } catch (RuntimeException $exception) { //JWR couldn't be parsed so return the request as is throw OAuthServerException::accessDenied('Error while decoding to JSON'); } diff --git a/src/CryptKey.php b/src/CryptKey.php index 98b53222..6fc4dff0 100644 --- a/src/CryptKey.php +++ b/src/CryptKey.php @@ -11,6 +11,9 @@ namespace League\OAuth2\Server; +use LogicException; +use RuntimeException; + class CryptKey { const RSA_KEY_PATTERN = @@ -42,7 +45,7 @@ class CryptKey } if (!file_exists($keyPath) || !is_readable($keyPath)) { - throw new \LogicException(sprintf('Key path "%s" does not exist or is not readable', $keyPath)); + throw new LogicException(sprintf('Key path "%s" does not exist or is not readable', $keyPath)); } if ($keyPermissionsCheck === true) { @@ -64,7 +67,7 @@ class CryptKey /** * @param string $key * - * @throws \RuntimeException + * @throws RuntimeException * * @return string */ @@ -79,19 +82,19 @@ class CryptKey if (!touch($keyPath)) { // @codeCoverageIgnoreStart - throw new \RuntimeException(sprintf('"%s" key file could not be created', $keyPath)); + throw new RuntimeException(sprintf('"%s" key file could not be created', $keyPath)); // @codeCoverageIgnoreEnd } if (file_put_contents($keyPath, $key) === false) { // @codeCoverageIgnoreStart - throw new \RuntimeException(sprintf('Unable to write key file to temporary directory "%s"', $tmpDir)); + throw new RuntimeException(sprintf('Unable to write key file to temporary directory "%s"', $tmpDir)); // @codeCoverageIgnoreEnd } if (chmod($keyPath, 0600) === false) { // @codeCoverageIgnoreStart - throw new \RuntimeException(sprintf('The key file "%s" file mode could not be changed with chmod to 600', $keyPath)); + throw new RuntimeException(sprintf('The key file "%s" file mode could not be changed with chmod to 600', $keyPath)); // @codeCoverageIgnoreEnd } diff --git a/src/CryptTrait.php b/src/CryptTrait.php index 672c7e2e..79b8dc55 100644 --- a/src/CryptTrait.php +++ b/src/CryptTrait.php @@ -13,6 +13,8 @@ namespace League\OAuth2\Server; use Defuse\Crypto\Crypto; use Defuse\Crypto\Key; +use Exception; +use LogicException; trait CryptTrait { @@ -26,7 +28,7 @@ trait CryptTrait * * @param string $unencryptedData * - * @throws \LogicException + * @throws LogicException * * @return string */ @@ -38,8 +40,8 @@ trait CryptTrait } return Crypto::encryptWithPassword($unencryptedData, $this->encryptionKey); - } catch (\Exception $e) { - throw new \LogicException($e->getMessage()); + } catch (Exception $e) { + throw new LogicException($e->getMessage()); } } @@ -48,7 +50,7 @@ trait CryptTrait * * @param string $encryptedData * - * @throws \LogicException + * @throws LogicException * * @return string */ @@ -60,8 +62,8 @@ trait CryptTrait } return Crypto::decryptWithPassword($encryptedData, $this->encryptionKey); - } catch (\Exception $e) { - throw new \LogicException($e->getMessage()); + } catch (Exception $e) { + throw new LogicException($e->getMessage()); } } diff --git a/src/Entities/RefreshTokenEntityInterface.php b/src/Entities/RefreshTokenEntityInterface.php index e4f10400..c2898ae5 100644 --- a/src/Entities/RefreshTokenEntityInterface.php +++ b/src/Entities/RefreshTokenEntityInterface.php @@ -9,6 +9,8 @@ namespace League\OAuth2\Server\Entities; +use DateTime; + interface RefreshTokenEntityInterface { /** @@ -28,16 +30,16 @@ interface RefreshTokenEntityInterface /** * Get the token's expiry date time. * - * @return \DateTime + * @return DateTime */ public function getExpiryDateTime(); /** * Set the date time when the token expires. * - * @param \DateTime $dateTime + * @param DateTime $dateTime */ - public function setExpiryDateTime(\DateTime $dateTime); + public function setExpiryDateTime(DateTime $dateTime); /** * Set the access token that the refresh token was associated with. diff --git a/src/Entities/ScopeEntityInterface.php b/src/Entities/ScopeEntityInterface.php index 34ef75f0..26748e0c 100644 --- a/src/Entities/ScopeEntityInterface.php +++ b/src/Entities/ScopeEntityInterface.php @@ -9,7 +9,9 @@ namespace League\OAuth2\Server\Entities; -interface ScopeEntityInterface extends \JsonSerializable +use JsonSerializable; + +interface ScopeEntityInterface extends JsonSerializable { /** * Get the scope's identifier. diff --git a/src/Entities/TokenInterface.php b/src/Entities/TokenInterface.php index 378adbdc..d2ca77d3 100644 --- a/src/Entities/TokenInterface.php +++ b/src/Entities/TokenInterface.php @@ -9,6 +9,8 @@ namespace League\OAuth2\Server\Entities; +use DateTime; + interface TokenInterface { /** @@ -28,16 +30,16 @@ interface TokenInterface /** * Get the token's expiry date time. * - * @return \DateTime + * @return DateTime */ public function getExpiryDateTime(); /** * Set the date time when the token expires. * - * @param \DateTime $dateTime + * @param DateTime $dateTime */ - public function setExpiryDateTime(\DateTime $dateTime); + public function setExpiryDateTime(DateTime $dateTime); /** * Set the identifier of the user associated with the token. diff --git a/src/Entities/Traits/AccessTokenTrait.php b/src/Entities/Traits/AccessTokenTrait.php index 81fc1bfd..5fa4a9be 100644 --- a/src/Entities/Traits/AccessTokenTrait.php +++ b/src/Entities/Traits/AccessTokenTrait.php @@ -9,6 +9,7 @@ namespace League\OAuth2\Server\Entities\Traits; +use DateTime; use Lcobucci\JWT\Builder; use Lcobucci\JWT\Signer\Key; use Lcobucci\JWT\Signer\Rsa\Sha256; @@ -46,7 +47,7 @@ trait AccessTokenTrait abstract public function getClient(); /** - * @return \DateTime + * @return DateTime */ abstract public function getExpiryDateTime(); diff --git a/src/Entities/Traits/RefreshTokenTrait.php b/src/Entities/Traits/RefreshTokenTrait.php index fb9dbc68..0734daf1 100644 --- a/src/Entities/Traits/RefreshTokenTrait.php +++ b/src/Entities/Traits/RefreshTokenTrait.php @@ -9,6 +9,7 @@ namespace League\OAuth2\Server\Entities\Traits; +use DateTime; use League\OAuth2\Server\Entities\AccessTokenEntityInterface; trait RefreshTokenTrait @@ -19,7 +20,7 @@ trait RefreshTokenTrait protected $accessToken; /** - * @var \DateTime + * @var DateTime */ protected $expiryDateTime; @@ -42,7 +43,7 @@ trait RefreshTokenTrait /** * Get the token's expiry date time. * - * @return \DateTime + * @return DateTime */ public function getExpiryDateTime() { @@ -52,9 +53,9 @@ trait RefreshTokenTrait /** * Set the date time when the token expires. * - * @param \DateTime $dateTime + * @param DateTime $dateTime */ - public function setExpiryDateTime(\DateTime $dateTime) + public function setExpiryDateTime(DateTime $dateTime) { $this->expiryDateTime = $dateTime; } diff --git a/src/Entities/Traits/TokenEntityTrait.php b/src/Entities/Traits/TokenEntityTrait.php index c6653cce..34159149 100644 --- a/src/Entities/Traits/TokenEntityTrait.php +++ b/src/Entities/Traits/TokenEntityTrait.php @@ -9,6 +9,7 @@ namespace League\OAuth2\Server\Entities\Traits; +use DateTime; use League\OAuth2\Server\Entities\ClientEntityInterface; use League\OAuth2\Server\Entities\ScopeEntityInterface; @@ -20,7 +21,7 @@ trait TokenEntityTrait protected $scopes = []; /** - * @var \DateTime + * @var DateTime */ protected $expiryDateTime; @@ -57,7 +58,7 @@ trait TokenEntityTrait /** * Get the token's expiry date time. * - * @return \DateTime + * @return DateTime */ public function getExpiryDateTime() { @@ -67,9 +68,9 @@ trait TokenEntityTrait /** * Set the date time when the token expires. * - * @param \DateTime $dateTime + * @param DateTime $dateTime */ - public function setExpiryDateTime(\DateTime $dateTime) + public function setExpiryDateTime(DateTime $dateTime) { $this->expiryDateTime = $dateTime; } diff --git a/src/Exception/OAuthServerException.php b/src/Exception/OAuthServerException.php index 2c7bc28b..41bb8975 100644 --- a/src/Exception/OAuthServerException.php +++ b/src/Exception/OAuthServerException.php @@ -9,9 +9,10 @@ namespace League\OAuth2\Server\Exception; +use Exception; use Psr\Http\Message\ResponseInterface; -class OAuthServerException extends \Exception +class OAuthServerException extends Exception { /** * @var int diff --git a/src/Grant/AbstractGrant.php b/src/Grant/AbstractGrant.php index 9b5486c3..603c18d0 100644 --- a/src/Grant/AbstractGrant.php +++ b/src/Grant/AbstractGrant.php @@ -10,6 +10,10 @@ */ namespace League\OAuth2\Server\Grant; +use DateInterval; +use DateTime; +use Error; +use Exception; use League\Event\EmitterAwareTrait; use League\OAuth2\Server\CryptKey; use League\OAuth2\Server\CryptTrait; @@ -28,7 +32,9 @@ 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; +use TypeError; /** * Abstract grant class. @@ -72,12 +78,12 @@ abstract class AbstractGrant implements GrantTypeInterface protected $userRepository; /** - * @var \DateInterval + * @var DateInterval */ protected $refreshTokenTTL; /** - * @var \League\OAuth2\Server\CryptKey + * @var CryptKey */ protected $privateKey; @@ -137,7 +143,7 @@ abstract class AbstractGrant implements GrantTypeInterface /** * {@inheritdoc} */ - public function setRefreshTokenTTL(\DateInterval $refreshTokenTTL) + public function setRefreshTokenTTL(DateInterval $refreshTokenTTL) { $this->refreshTokenTTL = $refreshTokenTTL; } @@ -145,7 +151,7 @@ abstract class AbstractGrant implements GrantTypeInterface /** * Set the private key * - * @param \League\OAuth2\Server\CryptKey $key + * @param CryptKey $key */ public function setPrivateKey(CryptKey $key) { @@ -369,7 +375,7 @@ abstract class AbstractGrant implements GrantTypeInterface /** * Issue an access token. * - * @param \DateInterval $accessTokenTTL + * @param DateInterval $accessTokenTTL * @param ClientEntityInterface $client * @param string|null $userIdentifier * @param ScopeEntityInterface[] $scopes @@ -380,7 +386,7 @@ abstract class AbstractGrant implements GrantTypeInterface * @return AccessTokenEntityInterface */ protected function issueAccessToken( - \DateInterval $accessTokenTTL, + DateInterval $accessTokenTTL, ClientEntityInterface $client, $userIdentifier, array $scopes = [] @@ -390,7 +396,7 @@ abstract class AbstractGrant implements GrantTypeInterface $accessToken = $this->accessTokenRepository->getNewToken($client, $scopes, $userIdentifier); $accessToken->setClient($client); $accessToken->setUserIdentifier($userIdentifier); - $accessToken->setExpiryDateTime((new \DateTime())->add($accessTokenTTL)); + $accessToken->setExpiryDateTime((new DateTime())->add($accessTokenTTL)); foreach ($scopes as $scope) { $accessToken->addScope($scope); @@ -413,7 +419,7 @@ abstract class AbstractGrant implements GrantTypeInterface /** * Issue an auth code. * - * @param \DateInterval $authCodeTTL + * @param DateInterval $authCodeTTL * @param ClientEntityInterface $client * @param string $userIdentifier * @param string|null $redirectUri @@ -425,7 +431,7 @@ abstract class AbstractGrant implements GrantTypeInterface * @return AuthCodeEntityInterface */ protected function issueAuthCode( - \DateInterval $authCodeTTL, + DateInterval $authCodeTTL, ClientEntityInterface $client, $userIdentifier, $redirectUri, @@ -434,7 +440,7 @@ abstract class AbstractGrant implements GrantTypeInterface $maxGenerationAttempts = self::MAX_RANDOM_TOKEN_GENERATION_ATTEMPTS; $authCode = $this->authCodeRepository->getNewAuthCode(); - $authCode->setExpiryDateTime((new \DateTime())->add($authCodeTTL)); + $authCode->setExpiryDateTime((new DateTime())->add($authCodeTTL)); $authCode->setClient($client); $authCode->setUserIdentifier($userIdentifier); @@ -473,7 +479,7 @@ abstract class AbstractGrant implements GrantTypeInterface $maxGenerationAttempts = self::MAX_RANDOM_TOKEN_GENERATION_ATTEMPTS; $refreshToken = $this->refreshTokenRepository->getNewRefreshToken(); - $refreshToken->setExpiryDateTime((new \DateTime())->add($this->refreshTokenTTL)); + $refreshToken->setExpiryDateTime((new DateTime())->add($this->refreshTokenTTL)); $refreshToken->setAccessToken($accessToken); while ($maxGenerationAttempts-- > 0) { @@ -504,11 +510,11 @@ abstract class AbstractGrant implements GrantTypeInterface try { return bin2hex(random_bytes($length)); // @codeCoverageIgnoreStart - } catch (\TypeError $e) { + } catch (TypeError $e) { throw OAuthServerException::serverError('An unexpected error has occurred'); - } catch (\Error $e) { + } catch (Error $e) { throw OAuthServerException::serverError('An unexpected error has occurred'); - } catch (\Exception $e) { + } catch (Exception $e) { // If you get this message, the CSPRNG failed hard. throw OAuthServerException::serverError('Could not generate a random string'); } @@ -541,7 +547,7 @@ abstract class AbstractGrant implements GrantTypeInterface */ public function validateAuthorizationRequest(ServerRequestInterface $request) { - throw new \LogicException('This grant cannot validate an authorization request'); + throw new LogicException('This grant cannot validate an authorization request'); } /** @@ -549,6 +555,6 @@ abstract class AbstractGrant implements GrantTypeInterface */ public function completeAuthorizationRequest(AuthorizationRequest $authorizationRequest) { - throw new \LogicException('This grant cannot complete an authorization request'); + throw new LogicException('This grant cannot complete an authorization request'); } } diff --git a/src/Grant/AuthCodeGrant.php b/src/Grant/AuthCodeGrant.php index db2dee47..2dc3c6d7 100644 --- a/src/Grant/AuthCodeGrant.php +++ b/src/Grant/AuthCodeGrant.php @@ -9,6 +9,9 @@ namespace League\OAuth2\Server\Grant; +use DateInterval; +use DateTime; +use Exception; use League\OAuth2\Server\Entities\ClientEntityInterface; use League\OAuth2\Server\Entities\UserEntityInterface; use League\OAuth2\Server\Exception\OAuthServerException; @@ -18,12 +21,14 @@ use League\OAuth2\Server\RequestEvent; use League\OAuth2\Server\RequestTypes\AuthorizationRequest; use League\OAuth2\Server\ResponseTypes\RedirectResponse; use League\OAuth2\Server\ResponseTypes\ResponseTypeInterface; +use LogicException; use Psr\Http\Message\ServerRequestInterface; +use stdClass; class AuthCodeGrant extends AbstractAuthorizeGrant { /** - * @var \DateInterval + * @var DateInterval */ private $authCodeTTL; @@ -35,19 +40,19 @@ class AuthCodeGrant extends AbstractAuthorizeGrant /** * @param AuthCodeRepositoryInterface $authCodeRepository * @param RefreshTokenRepositoryInterface $refreshTokenRepository - * @param \DateInterval $authCodeTTL + * @param DateInterval $authCodeTTL * - * @throws \Exception + * @throws Exception */ public function __construct( AuthCodeRepositoryInterface $authCodeRepository, RefreshTokenRepositoryInterface $refreshTokenRepository, - \DateInterval $authCodeTTL + DateInterval $authCodeTTL ) { $this->setAuthCodeRepository($authCodeRepository); $this->setRefreshTokenRepository($refreshTokenRepository); $this->authCodeTTL = $authCodeTTL; - $this->refreshTokenTTL = new \DateInterval('P1M'); + $this->refreshTokenTTL = new DateInterval('P1M'); } public function enableCodeExchangeProof() @@ -60,7 +65,7 @@ class AuthCodeGrant extends AbstractAuthorizeGrant * * @param ServerRequestInterface $request * @param ResponseTypeInterface $responseType - * @param \DateInterval $accessTokenTTL + * @param DateInterval $accessTokenTTL * * @throws OAuthServerException * @@ -69,7 +74,7 @@ class AuthCodeGrant extends AbstractAuthorizeGrant public function respondToAccessTokenRequest( ServerRequestInterface $request, ResponseTypeInterface $responseType, - \DateInterval $accessTokenTTL + DateInterval $accessTokenTTL ) { // Validate request $client = $this->validateClient($request); @@ -90,7 +95,7 @@ class AuthCodeGrant extends AbstractAuthorizeGrant $client, $authCodePayload->user_id ); - } catch (\LogicException $e) { + } catch (LogicException $e) { throw OAuthServerException::invalidRequest('code', 'Cannot decrypt the authorization code'); } @@ -161,7 +166,7 @@ class AuthCodeGrant extends AbstractAuthorizeGrant /** * Validate the authorization code. * - * @param \stdClass $authCodePayload + * @param stdClass $authCodePayload * @param ClientEntityInterface $client * @param ServerRequestInterface $request */ @@ -311,7 +316,7 @@ class AuthCodeGrant extends AbstractAuthorizeGrant public function completeAuthorizationRequest(AuthorizationRequest $authorizationRequest) { if ($authorizationRequest->getUser() instanceof UserEntityInterface === false) { - throw new \LogicException('An instance of UserEntityInterface should be set on the AuthorizationRequest'); + throw new LogicException('An instance of UserEntityInterface should be set on the AuthorizationRequest'); } $finalRedirectUri = $authorizationRequest->getRedirectUri() @@ -333,7 +338,7 @@ class AuthCodeGrant extends AbstractAuthorizeGrant 'auth_code_id' => $authCode->getIdentifier(), 'scopes' => $authCode->getScopes(), 'user_id' => $authCode->getUserIdentifier(), - 'expire_time' => (new \DateTime())->add($this->authCodeTTL)->format('U'), + 'expire_time' => (new DateTime())->add($this->authCodeTTL)->format('U'), 'code_challenge' => $authorizationRequest->getCodeChallenge(), 'code_challenge_method' => $authorizationRequest->getCodeChallengeMethod(), ]; diff --git a/src/Grant/ClientCredentialsGrant.php b/src/Grant/ClientCredentialsGrant.php index 026ce5e5..9f647965 100644 --- a/src/Grant/ClientCredentialsGrant.php +++ b/src/Grant/ClientCredentialsGrant.php @@ -11,6 +11,7 @@ namespace League\OAuth2\Server\Grant; +use DateInterval; use League\OAuth2\Server\RequestEvent; use League\OAuth2\Server\ResponseTypes\ResponseTypeInterface; use Psr\Http\Message\ServerRequestInterface; @@ -26,7 +27,7 @@ class ClientCredentialsGrant extends AbstractGrant public function respondToAccessTokenRequest( ServerRequestInterface $request, ResponseTypeInterface $responseType, - \DateInterval $accessTokenTTL + DateInterval $accessTokenTTL ) { // Validate request $client = $this->validateClient($request); diff --git a/src/Grant/GrantTypeInterface.php b/src/Grant/GrantTypeInterface.php index 2aee367f..41ebeb5f 100644 --- a/src/Grant/GrantTypeInterface.php +++ b/src/Grant/GrantTypeInterface.php @@ -11,6 +11,7 @@ namespace League\OAuth2\Server\Grant; +use DateInterval; use Defuse\Crypto\Key; use League\Event\EmitterAwareInterface; use League\OAuth2\Server\CryptKey; @@ -29,9 +30,9 @@ interface GrantTypeInterface extends EmitterAwareInterface /** * Set refresh token TTL. * - * @param \DateInterval $refreshTokenTTL + * @param DateInterval $refreshTokenTTL */ - public function setRefreshTokenTTL(\DateInterval $refreshTokenTTL); + public function setRefreshTokenTTL(DateInterval $refreshTokenTTL); /** * Return the grant identifier that can be used in matching up requests. @@ -45,14 +46,14 @@ interface GrantTypeInterface extends EmitterAwareInterface * * @param ServerRequestInterface $request * @param ResponseTypeInterface $responseType - * @param \DateInterval $accessTokenTTL + * @param DateInterval $accessTokenTTL * * @return ResponseTypeInterface */ public function respondToAccessTokenRequest( ServerRequestInterface $request, ResponseTypeInterface $responseType, - \DateInterval $accessTokenTTL + DateInterval $accessTokenTTL ); /** diff --git a/src/Grant/ImplicitGrant.php b/src/Grant/ImplicitGrant.php index 1890a6ba..63a6c0b2 100644 --- a/src/Grant/ImplicitGrant.php +++ b/src/Grant/ImplicitGrant.php @@ -9,6 +9,8 @@ namespace League\OAuth2\Server\Grant; +use DateInterval; +use DateTime; use League\OAuth2\Server\Entities\ClientEntityInterface; use League\OAuth2\Server\Entities\UserEntityInterface; use League\OAuth2\Server\Exception\OAuthServerException; @@ -17,12 +19,13 @@ use League\OAuth2\Server\RequestEvent; use League\OAuth2\Server\RequestTypes\AuthorizationRequest; use League\OAuth2\Server\ResponseTypes\RedirectResponse; use League\OAuth2\Server\ResponseTypes\ResponseTypeInterface; +use LogicException; use Psr\Http\Message\ServerRequestInterface; class ImplicitGrant extends AbstractAuthorizeGrant { /** - * @var \DateInterval + * @var DateInterval */ private $accessTokenTTL; @@ -32,33 +35,33 @@ class ImplicitGrant extends AbstractAuthorizeGrant private $queryDelimiter; /** - * @param \DateInterval $accessTokenTTL - * @param string $queryDelimiter + * @param DateInterval $accessTokenTTL + * @param string $queryDelimiter */ - public function __construct(\DateInterval $accessTokenTTL, $queryDelimiter = '#') + public function __construct(DateInterval $accessTokenTTL, $queryDelimiter = '#') { $this->accessTokenTTL = $accessTokenTTL; $this->queryDelimiter = $queryDelimiter; } /** - * @param \DateInterval $refreshTokenTTL + * @param DateInterval $refreshTokenTTL * - * @throw \LogicException + * @throw LogicException */ - public function setRefreshTokenTTL(\DateInterval $refreshTokenTTL) + public function setRefreshTokenTTL(DateInterval $refreshTokenTTL) { - throw new \LogicException('The Implicit Grant does not return refresh tokens'); + throw new LogicException('The Implicit Grant does not return refresh tokens'); } /** * @param RefreshTokenRepositoryInterface $refreshTokenRepository * - * @throw \LogicException + * @throw LogicException */ public function setRefreshTokenRepository(RefreshTokenRepositoryInterface $refreshTokenRepository) { - throw new \LogicException('The Implicit Grant does not return refresh tokens'); + throw new LogicException('The Implicit Grant does not return refresh tokens'); } /** @@ -84,16 +87,16 @@ class ImplicitGrant extends AbstractAuthorizeGrant * * @param ServerRequestInterface $request * @param ResponseTypeInterface $responseType - * @param \DateInterval $accessTokenTTL + * @param DateInterval $accessTokenTTL * * @return ResponseTypeInterface */ public function respondToAccessTokenRequest( ServerRequestInterface $request, ResponseTypeInterface $responseType, - \DateInterval $accessTokenTTL + DateInterval $accessTokenTTL ) { - throw new \LogicException('This grant does not used this method'); + throw new LogicException('This grant does not used this method'); } /** @@ -176,7 +179,7 @@ class ImplicitGrant extends AbstractAuthorizeGrant public function completeAuthorizationRequest(AuthorizationRequest $authorizationRequest) { if ($authorizationRequest->getUser() instanceof UserEntityInterface === false) { - throw new \LogicException('An instance of UserEntityInterface should be set on the AuthorizationRequest'); + throw new LogicException('An instance of UserEntityInterface should be set on the AuthorizationRequest'); } $finalRedirectUri = ($authorizationRequest->getRedirectUri() === null) @@ -209,7 +212,7 @@ class ImplicitGrant extends AbstractAuthorizeGrant [ 'access_token' => (string) $accessToken->convertToJWT($this->privateKey), 'token_type' => 'Bearer', - 'expires_in' => $accessToken->getExpiryDateTime()->getTimestamp() - (new \DateTime())->getTimestamp(), + 'expires_in' => $accessToken->getExpiryDateTime()->getTimestamp() - (new DateTime())->getTimestamp(), 'state' => $authorizationRequest->getState(), ], $this->queryDelimiter diff --git a/src/Grant/PasswordGrant.php b/src/Grant/PasswordGrant.php index 1d00998b..4b68ad44 100644 --- a/src/Grant/PasswordGrant.php +++ b/src/Grant/PasswordGrant.php @@ -11,6 +11,7 @@ namespace League\OAuth2\Server\Grant; +use DateInterval; use League\OAuth2\Server\Entities\ClientEntityInterface; use League\OAuth2\Server\Entities\UserEntityInterface; use League\OAuth2\Server\Exception\OAuthServerException; @@ -36,7 +37,7 @@ class PasswordGrant extends AbstractGrant $this->setUserRepository($userRepository); $this->setRefreshTokenRepository($refreshTokenRepository); - $this->refreshTokenTTL = new \DateInterval('P1M'); + $this->refreshTokenTTL = new DateInterval('P1M'); } /** @@ -45,7 +46,7 @@ class PasswordGrant extends AbstractGrant public function respondToAccessTokenRequest( ServerRequestInterface $request, ResponseTypeInterface $responseType, - \DateInterval $accessTokenTTL + DateInterval $accessTokenTTL ) { // Validate request $client = $this->validateClient($request); diff --git a/src/Grant/RefreshTokenGrant.php b/src/Grant/RefreshTokenGrant.php index 519954be..2732e5b8 100644 --- a/src/Grant/RefreshTokenGrant.php +++ b/src/Grant/RefreshTokenGrant.php @@ -11,6 +11,8 @@ namespace League\OAuth2\Server\Grant; +use DateInterval; +use Exception; use League\OAuth2\Server\Exception\OAuthServerException; use League\OAuth2\Server\Repositories\RefreshTokenRepositoryInterface; use League\OAuth2\Server\RequestEvent; @@ -29,7 +31,7 @@ class RefreshTokenGrant extends AbstractGrant { $this->setRefreshTokenRepository($refreshTokenRepository); - $this->refreshTokenTTL = new \DateInterval('P1M'); + $this->refreshTokenTTL = new DateInterval('P1M'); } /** @@ -38,7 +40,7 @@ class RefreshTokenGrant extends AbstractGrant public function respondToAccessTokenRequest( ServerRequestInterface $request, ResponseTypeInterface $responseType, - \DateInterval $accessTokenTTL + DateInterval $accessTokenTTL ) { // Validate request $client = $this->validateClient($request); @@ -94,7 +96,7 @@ class RefreshTokenGrant extends AbstractGrant // Validate refresh token try { $refreshToken = $this->decrypt($encryptedRefreshToken); - } catch (\Exception $e) { + } catch (Exception $e) { throw OAuthServerException::invalidRefreshToken('Cannot decrypt the refresh token'); } diff --git a/src/Middleware/AuthorizationServerMiddleware.php b/src/Middleware/AuthorizationServerMiddleware.php index a5f102fc..9b78b458 100644 --- a/src/Middleware/AuthorizationServerMiddleware.php +++ b/src/Middleware/AuthorizationServerMiddleware.php @@ -9,6 +9,7 @@ namespace League\OAuth2\Server\Middleware; +use Exception; use League\OAuth2\Server\AuthorizationServer; use League\OAuth2\Server\Exception\OAuthServerException; use Psr\Http\Message\ResponseInterface; @@ -43,7 +44,7 @@ class AuthorizationServerMiddleware } catch (OAuthServerException $exception) { return $exception->generateHttpResponse($response); // @codeCoverageIgnoreStart - } catch (\Exception $exception) { + } catch (Exception $exception) { return (new OAuthServerException($exception->getMessage(), 0, 'unknown_error', 500)) ->generateHttpResponse($response); // @codeCoverageIgnoreEnd diff --git a/src/Middleware/ResourceServerMiddleware.php b/src/Middleware/ResourceServerMiddleware.php index 56d28aee..e152a999 100644 --- a/src/Middleware/ResourceServerMiddleware.php +++ b/src/Middleware/ResourceServerMiddleware.php @@ -9,6 +9,7 @@ namespace League\OAuth2\Server\Middleware; +use Exception; use League\OAuth2\Server\Exception\OAuthServerException; use League\OAuth2\Server\ResourceServer; use Psr\Http\Message\ResponseInterface; @@ -34,7 +35,7 @@ class ResourceServerMiddleware * @param ResponseInterface $response * @param callable $next * - * @return \Psr\Http\Message\ResponseInterface + * @return ResponseInterface */ public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next) { @@ -43,7 +44,7 @@ class ResourceServerMiddleware } catch (OAuthServerException $exception) { return $exception->generateHttpResponse($response); // @codeCoverageIgnoreStart - } catch (\Exception $exception) { + } catch (Exception $exception) { return (new OAuthServerException($exception->getMessage(), 0, 'unknown_error', 500)) ->generateHttpResponse($response); // @codeCoverageIgnoreEnd diff --git a/src/ResponseTypes/AbstractResponseType.php b/src/ResponseTypes/AbstractResponseType.php index d013bab0..192f52aa 100644 --- a/src/ResponseTypes/AbstractResponseType.php +++ b/src/ResponseTypes/AbstractResponseType.php @@ -54,7 +54,7 @@ abstract class AbstractResponseType implements ResponseTypeInterface /** * Set the private key * - * @param \League\OAuth2\Server\CryptKey $key + * @param CryptKey $key */ public function setPrivateKey(CryptKey $key) { diff --git a/src/ResponseTypes/BearerTokenResponse.php b/src/ResponseTypes/BearerTokenResponse.php index a57573a0..4f6e9b47 100644 --- a/src/ResponseTypes/BearerTokenResponse.php +++ b/src/ResponseTypes/BearerTokenResponse.php @@ -11,6 +11,7 @@ namespace League\OAuth2\Server\ResponseTypes; +use DateTime; use League\OAuth2\Server\Entities\AccessTokenEntityInterface; use League\OAuth2\Server\Entities\RefreshTokenEntityInterface; use Psr\Http\Message\ResponseInterface; @@ -28,7 +29,7 @@ class BearerTokenResponse extends AbstractResponseType $responseParams = [ 'token_type' => 'Bearer', - 'expires_in' => $expireDateTime - (new \DateTime())->getTimestamp(), + 'expires_in' => $expireDateTime - (new DateTime())->getTimestamp(), 'access_token' => (string) $jwtAccessToken, ];