From a2460886f63ed3c0d5961bf06bbbbff1be4adca3 Mon Sep 17 00:00:00 2001 From: Alex Bilbie Date: Fri, 19 Feb 2016 18:09:39 -0500 Subject: [PATCH] Applied fixes from StyleCI --- examples/public/auth_code.php | 8 ++-- examples/public/client_credentials.php | 10 ++--- examples/public/middleware_authentication.php | 10 ++--- examples/public/password.php | 10 ++--- examples/public/protected_api.php | 12 +++--- examples/public/refresh_token.php | 10 ++--- examples/src/Entities/UserEntity.php | 5 ++- .../Repositories/AccessTokenRepository.php | 7 ++-- .../src/Repositories/AuthCodeRepository.php | 9 ++-- .../src/Repositories/ClientRepository.php | 13 +++--- .../Repositories/RefreshTokenRepository.php | 7 ++-- examples/src/Repositories/ScopeRepository.php | 11 ++--- examples/src/Repositories/UserRepository.php | 5 ++- src/Entities/AccessTokenEntity.php | 1 + src/Entities/AuthCodeEntity.php | 4 +- src/Entities/ClientEntity.php | 4 +- .../Interfaces/AccessTokenEntityInterface.php | 2 +- .../Interfaces/ClientEntityInterface.php | 24 ++++++----- .../RefreshTokenEntityInterface.php | 19 ++++++--- .../Interfaces/ScopeEntityInterface.php | 7 +++- src/Entities/Interfaces/TokenInterface.php | 37 ++++++++++------ .../Interfaces/UserEntityInterface.php | 3 +- src/Entities/RefreshTokenEntity.php | 4 +- src/Entities/ScopeEntity.php | 6 +-- src/Entities/Traits/ClientEntityTrait.php | 15 +++---- src/Entities/Traits/EntityTrait.php | 1 + src/Entities/Traits/RefreshTokenTrait.php | 11 +++-- src/Entities/Traits/TokenEntityTrait.php | 26 +++++++----- src/Exception/OAuthServerException.php | 41 +++++++++--------- src/Grant/AbstractGrant.php | 42 +++++++++---------- src/Grant/AuthCodeGrant.php | 31 +++++++------- src/Grant/ClientCredentialsGrant.php | 11 +++-- src/Grant/GrantTypeInterface.php | 25 ++++++----- src/Grant/PasswordGrant.php | 17 ++++---- src/Grant/RefreshTokenGrant.php | 24 +++++------ .../AccessTokenRepositoryInterface.php | 13 +++--- .../AuthCodeRepositoryInterface.php | 13 +++--- .../ClientRepositoryInterface.php | 13 +++--- src/Repositories/MacTokenInterface.php | 13 +++--- .../RefreshTokenRepositoryInterface.php | 13 +++--- src/Repositories/RepositoryInterface.php | 7 ++-- src/Repositories/ScopeRepositoryInterface.php | 9 ++-- src/Repositories/UserRepositoryInterface.php | 2 +- src/ResponseTypes/AbstractResponseType.php | 5 +-- src/ResponseTypes/BearerTokenResponse.php | 7 ++-- src/ResponseTypes/MAC.php | 25 +++++------ src/ResponseTypes/ResponseTypeInterface.php | 7 ++-- src/Server.php | 17 ++++---- src/Utils/KeyCrypt.php | 9 ++-- src/Utils/SecureKey.php | 21 +++++----- tests/Bootstrap.php | 2 +- tests/Grant/AbstractGrantTest.php | 10 ++--- tests/Grant/ClientCredentialsGrantTest.php | 2 +- tests/Grant/RefreshTokenGrantTest.php | 2 - tests/ServerTest.php | 6 +-- tests/Stubs/StubResponseType.php | 6 ++- tests/Stubs/UserEntity.php | 2 +- 57 files changed, 346 insertions(+), 330 deletions(-) diff --git a/examples/public/auth_code.php b/examples/public/auth_code.php index 761f7ae3..d15a1561 100644 --- a/examples/public/auth_code.php +++ b/examples/public/auth_code.php @@ -3,19 +3,17 @@ use League\OAuth2\Server\Exception\OAuthServerException; use League\OAuth2\Server\Grant\AuthCodeGrant; use League\OAuth2\Server\Server; - use OAuth2ServerExamples\Repositories\AccessTokenRepository; use OAuth2ServerExamples\Repositories\AuthCodeRepository; use OAuth2ServerExamples\Repositories\ClientRepository; use OAuth2ServerExamples\Repositories\RefreshTokenRepository; use OAuth2ServerExamples\Repositories\ScopeRepository; use OAuth2ServerExamples\Repositories\UserRepository; - use Slim\App; use Slim\Http\Request; use Slim\Http\Response; -include(__DIR__ . '/../vendor/autoload.php'); +include __DIR__.'/../vendor/autoload.php'; // App $app = new App([ @@ -29,8 +27,8 @@ $app = new App([ $refreshTokenRepository = new RefreshTokenRepository(); $authCodeRepository = new AuthCodeRepository(); - $privateKeyPath = 'file://' . __DIR__ . '/../private.key'; - $publicKeyPath = 'file://' . __DIR__ . '/../public.key'; + $privateKeyPath = 'file://'.__DIR__.'/../private.key'; + $publicKeyPath = 'file://'.__DIR__.'/../public.key'; // Setup the authorization server $server = new Server( diff --git a/examples/public/client_credentials.php b/examples/public/client_credentials.php index 684e3003..48ee0b6f 100644 --- a/examples/public/client_credentials.php +++ b/examples/public/client_credentials.php @@ -3,16 +3,14 @@ use League\OAuth2\Server\Exception\OAuthServerException; use League\OAuth2\Server\Grant\ClientCredentialsGrant; use League\OAuth2\Server\Server; - use OAuth2ServerExamples\Repositories\AccessTokenRepository; use OAuth2ServerExamples\Repositories\ClientRepository; use OAuth2ServerExamples\Repositories\ScopeRepository; - use Slim\App; use Slim\Http\Request; use Slim\Http\Response; -include(__DIR__ . '/../vendor/autoload.php'); +include __DIR__.'/../vendor/autoload.php'; // App $app = new App([ @@ -23,8 +21,8 @@ $app = new App([ $scopeRepository = new ScopeRepository(); $accessTokenRepository = new AccessTokenRepository(); - $privateKeyPath = 'file://' . __DIR__ . '/../private.key'; - $publicKeyPath = 'file://' . __DIR__ . '/../public.key'; + $privateKeyPath = 'file://'.__DIR__.'/../private.key'; + $publicKeyPath = 'file://'.__DIR__.'/../public.key'; // Setup the authorization server $server = new Server( @@ -39,7 +37,7 @@ $app = new App([ $server->enableGrantType(new ClientCredentialsGrant(), new \DateInterval('PT1H')); return $server; - } + }, ]); $app->post('/access_token', function (Request $request, Response $response) { diff --git a/examples/public/middleware_authentication.php b/examples/public/middleware_authentication.php index d928e19d..27f03c5a 100644 --- a/examples/public/middleware_authentication.php +++ b/examples/public/middleware_authentication.php @@ -4,16 +4,14 @@ use League\OAuth2\Server\Grant\PasswordGrant; use League\OAuth2\Server\Grant\RefreshTokenGrant; use League\OAuth2\Server\Middleware\AuthenticationServerMiddleware; use League\OAuth2\Server\Server; - use OAuth2ServerExamples\Repositories\AccessTokenRepository; use OAuth2ServerExamples\Repositories\ClientRepository; use OAuth2ServerExamples\Repositories\RefreshTokenRepository; use OAuth2ServerExamples\Repositories\ScopeRepository; use OAuth2ServerExamples\Repositories\UserRepository; - use Slim\App; -include(__DIR__ . '/../vendor/autoload.php'); +include __DIR__.'/../vendor/autoload.php'; // App $app = new App([ @@ -29,8 +27,8 @@ $app = new App([ $userRepository = new UserRepository(); $refreshTokenRepository = new RefreshTokenRepository(); - $privateKeyPath = 'file://' . __DIR__ . '/../private.key'; - $publicKeyPath = 'file://' . __DIR__ . '/../public.key'; + $privateKeyPath = 'file://'.__DIR__.'/../private.key'; + $publicKeyPath = 'file://'.__DIR__.'/../public.key'; // Setup the authorization server $server = new Server( @@ -52,7 +50,7 @@ $app = new App([ ); return $server; - } + }, ]); $app->post('/access_token', function () { diff --git a/examples/public/password.php b/examples/public/password.php index 036d1b4f..4c0548b4 100644 --- a/examples/public/password.php +++ b/examples/public/password.php @@ -3,18 +3,16 @@ use League\OAuth2\Server\Exception\OAuthServerException; use League\OAuth2\Server\Grant\PasswordGrant; use League\OAuth2\Server\Server; - use OAuth2ServerExamples\Repositories\AccessTokenRepository; use OAuth2ServerExamples\Repositories\ClientRepository; use OAuth2ServerExamples\Repositories\RefreshTokenRepository; use OAuth2ServerExamples\Repositories\ScopeRepository; use OAuth2ServerExamples\Repositories\UserRepository; - use Slim\App; use Slim\Http\Request; use Slim\Http\Response; -include(__DIR__ . '/../vendor/autoload.php'); +include __DIR__.'/../vendor/autoload.php'; // App $app = new App([ @@ -27,8 +25,8 @@ $app = new App([ $userRepository = new UserRepository(); $refreshTokenRepository = new RefreshTokenRepository(); - $privateKeyPath = 'file://' . __DIR__ . '/../private.key'; - $publicKeyPath = 'file://' . __DIR__ . '/../public.key'; + $privateKeyPath = 'file://'.__DIR__.'/../private.key'; + $publicKeyPath = 'file://'.__DIR__.'/../public.key'; // Setup the authorization server $server = new Server( @@ -46,7 +44,7 @@ $app = new App([ ); return $server; - } + }, ]); $app->post('/access_token', function (Request $request, Response $response) { diff --git a/examples/public/protected_api.php b/examples/public/protected_api.php index f7362d63..35b829ae 100644 --- a/examples/public/protected_api.php +++ b/examples/public/protected_api.php @@ -2,16 +2,14 @@ use League\OAuth2\Server\Middleware\ResourceServerMiddleware; use League\OAuth2\Server\Server; - use OAuth2ServerExamples\Repositories\AccessTokenRepository; use OAuth2ServerExamples\Repositories\ClientRepository; use OAuth2ServerExamples\Repositories\ScopeRepository; - use Slim\App; use Slim\Http\Request; use Slim\Http\Response; -include(__DIR__ . '/../vendor/autoload.php'); +include __DIR__.'/../vendor/autoload.php'; // App $app = new App([ @@ -25,8 +23,8 @@ $app = new App([ $scopeRepository = new ScopeRepository(); $accessTokenRepository = new AccessTokenRepository(); - $privateKeyPath = 'file://' . __DIR__ . '/../private.key'; - $publicKeyPath = 'file://' . __DIR__ . '/../public.key'; + $privateKeyPath = 'file://'.__DIR__.'/../private.key'; + $publicKeyPath = 'file://'.__DIR__.'/../public.key'; // Setup the authorization server $server = new Server( @@ -38,7 +36,7 @@ $app = new App([ ); return $server; - } + }, ]); $app->add(new ResourceServerMiddleware($app->getContainer()->get(Server::class))); @@ -50,7 +48,7 @@ $app->post('/api/example', function (Request $request, Response $response) { $params = [ 'id' => 1, 'name' => 'Alex', - 'city' => 'London' + 'city' => 'London', ]; } diff --git a/examples/public/refresh_token.php b/examples/public/refresh_token.php index ad9bf0cb..6ecf5122 100644 --- a/examples/public/refresh_token.php +++ b/examples/public/refresh_token.php @@ -3,19 +3,15 @@ use League\OAuth2\Server\Exception\OAuthServerException; use League\OAuth2\Server\Grant\RefreshTokenGrant; use League\OAuth2\Server\Server; - use OAuth2ServerExamples\Repositories\AccessTokenRepository; use OAuth2ServerExamples\Repositories\ClientRepository; use OAuth2ServerExamples\Repositories\RefreshTokenRepository; use OAuth2ServerExamples\Repositories\ScopeRepository; - use Slim\App; use Slim\Http\Request; use Slim\Http\Response; -include(__DIR__ . '/../vendor/autoload.php'); - - +include __DIR__.'/../vendor/autoload.php'; // App $app = new App([Server::class => function () { @@ -25,8 +21,8 @@ $app = new App([Server::class => function () { $accessTokenRepository = new AccessTokenRepository(); $refreshTokenRepository = new RefreshTokenRepository(); - $privateKeyPath = 'file://' . __DIR__ . '/../private.key'; - $publicKeyPath = 'file://' . __DIR__ . '/../public.key'; + $privateKeyPath = 'file://'.__DIR__.'/../private.key'; + $publicKeyPath = 'file://'.__DIR__.'/../public.key'; // Setup the authorization server $server = new Server( diff --git a/examples/src/Entities/UserEntity.php b/examples/src/Entities/UserEntity.php index 8feb8c73..9efe6611 100644 --- a/examples/src/Entities/UserEntity.php +++ b/examples/src/Entities/UserEntity.php @@ -7,11 +7,12 @@ use League\OAuth2\Server\Entities\Interfaces\UserEntityInterface; class UserEntity implements UserEntityInterface { /** - * Return the user's identifier + * Return the user's identifier. + * * @return mixed */ public function getIdentifier() { return 1; } -} \ No newline at end of file +} diff --git a/examples/src/Repositories/AccessTokenRepository.php b/examples/src/Repositories/AccessTokenRepository.php index bc8ada68..5a58c915 100644 --- a/examples/src/Repositories/AccessTokenRepository.php +++ b/examples/src/Repositories/AccessTokenRepository.php @@ -1,4 +1,5 @@ [ 'secret' => password_hash('abc123', PASSWORD_BCRYPT), 'name' => 'My Awesome App', - 'redirect_uri' => 'http://foo/bar' - ] + 'redirect_uri' => 'http://foo/bar', + ], ]; // Check if client is registered if (array_key_exists($clientIdentifier, $clients) === false) { - return null; + return; } // Check if client secret is valid if ($clientSecret !== null && password_verify($clientSecret, $clients[$clientIdentifier]['secret']) === false) { - return null; + return; } // Check if redirect URI is valid if ($redirectUri !== null && $redirectUri !== $clients[$clientIdentifier]['redirect_uri']) { - return null; + return; } $client = new ClientEntity(); diff --git a/examples/src/Repositories/RefreshTokenRepository.php b/examples/src/Repositories/RefreshTokenRepository.php index a7a4e079..15f19ddf 100644 --- a/examples/src/Repositories/RefreshTokenRepository.php +++ b/examples/src/Repositories/RefreshTokenRepository.php @@ -7,9 +7,8 @@ use League\OAuth2\Server\Repositories\RefreshTokenRepositoryInterface; class RefreshTokenRepository implements RefreshTokenRepositoryInterface { - /** - * Create a new refresh token_name + * Create a new refresh token_name. * * @param \League\OAuth2\Server\Entities\Interfaces\RefreshTokenEntityInterface $refreshTokenEntityInterface */ @@ -19,7 +18,7 @@ class RefreshTokenRepository implements RefreshTokenRepositoryInterface } /** - * Revoke the refresh token + * Revoke the refresh token. * * @param string $tokenId */ @@ -29,7 +28,7 @@ class RefreshTokenRepository implements RefreshTokenRepositoryInterface } /** - * Check if the refresh token has been revoked + * Check if the refresh token has been revoked. * * @param string $tokenId * diff --git a/examples/src/Repositories/ScopeRepository.php b/examples/src/Repositories/ScopeRepository.php index ecfadd11..f48aac5b 100644 --- a/examples/src/Repositories/ScopeRepository.php +++ b/examples/src/Repositories/ScopeRepository.php @@ -1,4 +1,5 @@ [ - 'description' => 'Basic details about you' + 'description' => 'Basic details about you', ], 'email' => [ - 'description' => 'Your email address' - ] + 'description' => 'Your email address', + ], ]; if (array_key_exists($scopeIdentifier, $scopes) === false) { - return null; + return; } $scope = new ScopeEntity(); diff --git a/examples/src/Repositories/UserRepository.php b/examples/src/Repositories/UserRepository.php index 1ad9914d..ec930500 100644 --- a/examples/src/Repositories/UserRepository.php +++ b/examples/src/Repositories/UserRepository.php @@ -1,4 +1,5 @@ $this->errorType, - 'message' => $this->getMessage() + 'message' => $this->getMessage(), ]; if ($this->hint !== null) { @@ -264,14 +265,14 @@ class OAuthServerException extends \Exception } /** - * Get all headers that have to be send with the error response + * Get all headers that have to be send with the error response. * * @return array Array with header values */ public function getHttpHeaders() { $headers = [ - 'Content-type' => 'application/json' + 'Content-type' => 'application/json', ]; // Add "WWW-Authenticate" header @@ -303,7 +304,7 @@ class OAuthServerException extends \Exception } } if ($authScheme !== null) { - $headers[] = 'WWW-Authenticate: ' . $authScheme . ' realm="OAuth"'; + $headers[] = 'WWW-Authenticate: '.$authScheme.' realm="OAuth"'; } } @@ -312,7 +313,7 @@ class OAuthServerException extends \Exception } /** - * Returns the HTTP status code to send when the exceptions is output + * Returns the HTTP status code to send when the exceptions is output. * * @return int */ diff --git a/src/Grant/AbstractGrant.php b/src/Grant/AbstractGrant.php index b2d06179..ee4ab684 100644 --- a/src/Grant/AbstractGrant.php +++ b/src/Grant/AbstractGrant.php @@ -1,14 +1,13 @@ * @copyright Copyright (c) Alex Bilbie * @license http://mit-license.org/ + * * @link https://github.com/thephpleague/oauth2-server */ - namespace League\OAuth2\Server\Grant; use League\Event\EmitterAwareTrait; @@ -29,7 +28,7 @@ use OAuth2ServerExamples\Repositories\AuthCodeRepository; use Psr\Http\Message\ServerRequestInterface; /** - * Abstract grant class + * Abstract grant class. */ abstract class AbstractGrant implements GrantTypeInterface { @@ -139,7 +138,7 @@ abstract class AbstractGrant implements GrantTypeInterface } /** - * @inheritdoc + * {@inheritdoc} */ public function setEmitter(EmitterInterface $emitter = null) { @@ -147,7 +146,7 @@ abstract class AbstractGrant implements GrantTypeInterface } /** - * @inheritdoc + * {@inheritdoc} */ public function setRefreshTokenTTL(\DateInterval $refreshTokenTTL) { @@ -171,12 +170,13 @@ abstract class AbstractGrant implements GrantTypeInterface } /** - * Validate the client + * Validate the client. * * @param \Psr\Http\Message\ServerRequestInterface $request * - * @return \League\OAuth2\Server\Entities\Interfaces\ClientEntityInterface * @throws \League\OAuth2\Server\Exception\OAuthServerException + * + * @return \League\OAuth2\Server\Entities\Interfaces\ClientEntityInterface */ protected function validateClient(ServerRequestInterface $request) { @@ -224,15 +224,15 @@ abstract class AbstractGrant implements GrantTypeInterface } /** - * Validate scopes in the request + * Validate scopes in the request. * * @param \Psr\Http\Message\ServerRequestInterface $request * @param \League\OAuth2\Server\Entities\Interfaces\ClientEntityInterface $client * @param string $redirectUri * - * @return \League\OAuth2\Server\Entities\ScopeEntity[] - * * @throws \League\OAuth2\Server\Exception\OAuthServerException + * + * @return \League\OAuth2\Server\Entities\ScopeEntity[] */ public function validateScopes( ServerRequestInterface $request, @@ -322,7 +322,7 @@ abstract class AbstractGrant implements GrantTypeInterface } /** - * Issue an access token + * Issue an access token. * * @param \DateInterval $tokenTTL * @param \League\OAuth2\Server\Entities\Interfaces\ClientEntityInterface $client @@ -353,7 +353,7 @@ abstract class AbstractGrant implements GrantTypeInterface } /** - * Issue an auth code + * Issue an auth code. * * @param \DateInterval $tokenTTL * @param \League\OAuth2\Server\Entities\Interfaces\ClientEntityInterface $client @@ -361,8 +361,9 @@ abstract class AbstractGrant implements GrantTypeInterface * @param string $redirectUri * @param array $scopes * - * @return \League\OAuth2\Server\Entities\AuthCodeEntity * @throws \League\OAuth2\Server\Exception\OAuthServerException + * + * @return \League\OAuth2\Server\Entities\AuthCodeEntity */ protected function issueAuthCode( \DateInterval $tokenTTL, @@ -405,13 +406,13 @@ abstract class AbstractGrant implements GrantTypeInterface } /** - * Generate a new unique identifier + * Generate a new unique identifier. * * @param int $length * - * @return string - * * @throws \League\OAuth2\Server\Exception\OAuthServerException + * + * @return string */ protected function generateUniqueIdentifier($length = 40) { @@ -430,13 +431,12 @@ abstract class AbstractGrant implements GrantTypeInterface } /** - * @inheritdoc + * {@inheritdoc} */ public function canRespondToRequest(ServerRequestInterface $request) { - return ( + return isset($request->getParsedBody()['grant_type']) - && $request->getParsedBody()['grant_type'] === $this->getIdentifier() - ); + && $request->getParsedBody()['grant_type'] === $this->getIdentifier(); } } diff --git a/src/Grant/AuthCodeGrant.php b/src/Grant/AuthCodeGrant.php index 13b8a984..e134b59f 100644 --- a/src/Grant/AuthCodeGrant.php +++ b/src/Grant/AuthCodeGrant.php @@ -3,6 +3,7 @@ namespace League\OAuth2\Server\Grant; use DateInterval; +use League\Event\Event; use League\OAuth2\Server\Entities\Interfaces\ClientEntityInterface; use League\OAuth2\Server\Entities\Interfaces\UserEntityInterface; use League\OAuth2\Server\Exception\OAuthServerException; @@ -12,7 +13,6 @@ use League\OAuth2\Server\Repositories\UserRepositoryInterface; use League\OAuth2\Server\ResponseTypes\ResponseTypeInterface; use League\OAuth2\Server\Utils\KeyCrypt; use League\Plates\Engine; -use League\Event\Event; use Psr\Http\Message\ServerRequestInterface; use Zend\Diactoros\Response; use Zend\Diactoros\Uri; @@ -39,7 +39,6 @@ class AuthCodeGrant extends AbstractGrant */ private $pathToAuthorizeTemplate; - /** * @param \League\OAuth2\Server\Repositories\AuthCodeRepositoryInterface $authCodeRepository * @param \League\OAuth2\Server\Repositories\RefreshTokenRepositoryInterface $refreshTokenRepository @@ -61,22 +60,22 @@ class AuthCodeGrant extends AbstractGrant $this->userRepository = $userRepository; $this->authCodeTTL = $authCodeTTL; $this->pathToLoginTemplate = ($pathToLoginTemplate === null) - ? __DIR__ . '/../ResponseTypes/DefaultTemplates/login_user.php' + ? __DIR__.'/../ResponseTypes/DefaultTemplates/login_user.php' : $this->pathToLoginTemplate; $this->pathToAuthorizeTemplate = ($pathToLoginTemplate === null) - ? __DIR__ . '/../ResponseTypes/DefaultTemplates/authorize_client.php' + ? __DIR__.'/../ResponseTypes/DefaultTemplates/authorize_client.php' : $this->pathToAuthorizeTemplate; $this->refreshTokenTTL = new \DateInterval('P1M'); } - /** - * Respond to an authorization request + * Respond to an authorization request. * * @param \Psr\Http\Message\ServerRequestInterface $request * - * @return \Psr\Http\Message\ResponseInterface * @throws \League\OAuth2\Server\Exception\OAuthServerException + * + * @return \Psr\Http\Message\ResponseInterface */ protected function respondToAuthorizationRequest( ServerRequestInterface $request @@ -153,7 +152,6 @@ class AuthCodeGrant extends AbstractGrant return new Response\HtmlResponse($html); } - // The user hasn't approved the client yet so show an authorize form if ($userId !== null && $userHasApprovedClient === null) { $engine = new Engine(dirname($this->pathToAuthorizeTemplate)); @@ -219,18 +217,20 @@ class AuthCodeGrant extends AbstractGrant } $exception = OAuthServerException::accessDenied('The user denied the request', (string) $redirectUri); + return $exception->generateHttpResponse(); } /** - * Respond to an access token request + * Respond to an access token request. * * @param \Psr\Http\Message\ServerRequestInterface $request * @param \League\OAuth2\Server\ResponseTypes\ResponseTypeInterface $responseType * @param \DateInterval $accessTokenTTL * - * @return \League\OAuth2\Server\ResponseTypes\ResponseTypeInterface * @throws \League\OAuth2\Server\Exception\OAuthServerException + * + * @return \League\OAuth2\Server\ResponseTypes\ResponseTypeInterface */ protected function respondToAccessTokenRequest( ServerRequestInterface $request, @@ -286,21 +286,20 @@ class AuthCodeGrant extends AbstractGrant } /** - * @inheritdoc + * {@inheritdoc} */ public function canRespondToRequest(ServerRequestInterface $request) { - return ( + return ( isset($request->getQueryParams()['response_type']) && $request->getQueryParams()['response_type'] === 'code' && isset($request->getQueryParams()['client_id']) - ) || (parent::canRespondToRequest($request)) - ); + ) || (parent::canRespondToRequest($request)); } /** - * Return the grant identifier that can be used in matching up requests + * Return the grant identifier that can be used in matching up requests. * * @return string */ @@ -310,7 +309,7 @@ class AuthCodeGrant extends AbstractGrant } /** - * @inheritdoc + * {@inheritdoc} */ public function respondToRequest( ServerRequestInterface $request, diff --git a/src/Grant/ClientCredentialsGrant.php b/src/Grant/ClientCredentialsGrant.php index f5881e12..6da17f21 100644 --- a/src/Grant/ClientCredentialsGrant.php +++ b/src/Grant/ClientCredentialsGrant.php @@ -1,26 +1,25 @@ * @copyright Copyright (c) Alex Bilbie * @license http://mit-license.org/ + * * @link https://github.com/thephpleague/oauth2-server */ - namespace League\OAuth2\Server\Grant; use League\OAuth2\Server\ResponseTypes\ResponseTypeInterface; use Psr\Http\Message\ServerRequestInterface; /** - * Client credentials grant class + * Client credentials grant class. */ class ClientCredentialsGrant extends AbstractGrant { /** - * @inheritdoc + * {@inheritdoc} */ public function respondToRequest( ServerRequestInterface $request, @@ -41,7 +40,7 @@ class ClientCredentialsGrant extends AbstractGrant } /** - * @inheritdoc + * {@inheritdoc} */ public function getIdentifier() { diff --git a/src/Grant/GrantTypeInterface.php b/src/Grant/GrantTypeInterface.php index 1341c1fa..5ddd81b8 100644 --- a/src/Grant/GrantTypeInterface.php +++ b/src/Grant/GrantTypeInterface.php @@ -1,14 +1,13 @@ * @copyright Copyright (c) Alex Bilbie * @license http://mit-license.org/ + * * @link https://github.com/thephpleague/oauth2-server */ - namespace League\OAuth2\Server\Grant; use League\Event\EmitterAwareInterface; @@ -19,26 +18,26 @@ use League\OAuth2\Server\ResponseTypes\ResponseTypeInterface; use Psr\Http\Message\ServerRequestInterface; /** - * Grant type interface + * Grant type interface. */ interface GrantTypeInterface extends EmitterAwareInterface { /** - * Set refresh token TTL + * Set refresh token TTL. * * @param \DateInterval $refreshTokenTTL */ public function setRefreshTokenTTL(\DateInterval $refreshTokenTTL); /** - * Return the grant identifier that can be used in matching up requests + * Return the grant identifier that can be used in matching up requests. * * @return string */ public function getIdentifier(); /** - * Respond to an incoming request + * Respond to an incoming request. * * @param \Psr\Http\Message\ServerRequestInterface $request * @param \League\OAuth2\Server\ResponseTypes\ResponseTypeInterface $responseType @@ -62,40 +61,40 @@ interface GrantTypeInterface extends EmitterAwareInterface * * @param \Psr\Http\Message\ServerRequestInterface $request * - * @return boolean + * @return bool */ public function canRespondToRequest(ServerRequestInterface $request); /** - * Set the client repository + * Set the client repository. * * @param \League\OAuth2\Server\Repositories\ClientRepositoryInterface $clientRepository */ public function setClientRepository(ClientRepositoryInterface $clientRepository); /** - * Set the access token repository + * Set the access token repository. * * @param \League\OAuth2\Server\Repositories\AccessTokenRepositoryInterface $accessTokenRepository */ public function setAccessTokenRepository(AccessTokenRepositoryInterface $accessTokenRepository); /** - * Set the scope repository + * Set the scope repository. * * @param \League\OAuth2\Server\Repositories\ScopeRepositoryInterface $scopeRepository */ public function setScopeRepository(ScopeRepositoryInterface $scopeRepository); /** - * Set the path to the private key + * Set the path to the private key. * * @param string $pathToPrivateKey */ public function setPathToPrivateKey($pathToPrivateKey); /** - * Set the path to the public key + * Set the path to the public key. * * @param string $pathToPublicKey */ diff --git a/src/Grant/PasswordGrant.php b/src/Grant/PasswordGrant.php index 0b30bfe2..1145e6ab 100644 --- a/src/Grant/PasswordGrant.php +++ b/src/Grant/PasswordGrant.php @@ -1,14 +1,13 @@ * @copyright Copyright (c) Alex Bilbie * @license http://mit-license.org/ + * * @link https://github.com/thephpleague/oauth2-server */ - namespace League\OAuth2\Server\Grant; use League\Event\Event; @@ -20,7 +19,7 @@ use League\OAuth2\Server\ResponseTypes\ResponseTypeInterface; use Psr\Http\Message\ServerRequestInterface; /** - * Password grant class + * Password grant class. */ class PasswordGrant extends AbstractGrant { @@ -44,7 +43,7 @@ class PasswordGrant extends AbstractGrant } /** - * @inheritdoc + * {@inheritdoc} */ public function respondToRequest( ServerRequestInterface $request, @@ -53,7 +52,7 @@ class PasswordGrant extends AbstractGrant ) { // Validate request $client = $this->validateClient($request); - $user = $this->validateUser($request); + $user = $this->validateUser($request); $scopes = $this->validateScopes($request, $client); // Issue and persist new tokens @@ -70,9 +69,9 @@ class PasswordGrant extends AbstractGrant /** * @param \Psr\Http\Message\ServerRequestInterface $request * - * @return \League\OAuth2\Server\Entities\Interfaces\UserEntityInterface - * * @throws \League\OAuth2\Server\Exception\OAuthServerException + * + * @return \League\OAuth2\Server\Entities\Interfaces\UserEntityInterface */ protected function validateUser(ServerRequestInterface $request) { @@ -97,7 +96,7 @@ class PasswordGrant extends AbstractGrant } /** - * @inheritdoc + * {@inheritdoc} */ public function getIdentifier() { diff --git a/src/Grant/RefreshTokenGrant.php b/src/Grant/RefreshTokenGrant.php index adaa2306..19bab077 100644 --- a/src/Grant/RefreshTokenGrant.php +++ b/src/Grant/RefreshTokenGrant.php @@ -1,14 +1,13 @@ * @copyright Copyright (c) Alex Bilbie * @license http://mit-license.org/ + * * @link https://github.com/thephpleague/oauth2-server */ - namespace League\OAuth2\Server\Grant; use League\Event\Event; @@ -20,7 +19,7 @@ use League\OAuth2\Server\Utils\KeyCrypt; use Psr\Http\Message\ServerRequestInterface; /** - * Refresh token grant + * Refresh token grant. */ class RefreshTokenGrant extends AbstractGrant { @@ -35,7 +34,7 @@ class RefreshTokenGrant extends AbstractGrant } /** - * @inheritdoc + * {@inheritdoc} */ public function respondToRequest( ServerRequestInterface $request, @@ -52,6 +51,7 @@ class RefreshTokenGrant extends AbstractGrant $scopes = array_map(function ($scopeId) { $scope = new ScopeEntity(); $scope->setIdentifier($scopeId); + return $scope; }, $oldRefreshToken['scopes']); } else { @@ -87,9 +87,9 @@ class RefreshTokenGrant extends AbstractGrant * @param \Psr\Http\Message\ServerRequestInterface $request * @param string $clientId * - * @return array - * * @throws \League\OAuth2\Server\Exception\OAuthServerException + * + * @return array */ protected function validateOldRefreshToken(ServerRequestInterface $request, $clientId) { @@ -102,7 +102,7 @@ class RefreshTokenGrant extends AbstractGrant try { $refreshToken = KeyCrypt::decrypt($encryptedRefreshToken, $this->pathToPublicKey); } catch (\LogicException $e) { - throw OAuthServerException::invalidRefreshToken('Cannot parse refresh token: ' . $e->getMessage()); + throw OAuthServerException::invalidRefreshToken('Cannot parse refresh token: '.$e->getMessage()); } $refreshTokenData = json_decode($refreshToken, true); @@ -110,9 +110,9 @@ class RefreshTokenGrant extends AbstractGrant $this->getEmitter()->emit(new Event('refresh_token.client.failed', $request)); throw OAuthServerException::invalidRefreshToken( - 'Token is not linked to client,' . - ' got: ' . $clientId . - ' expected: ' . $refreshTokenData['client_id'] + 'Token is not linked to client,'. + ' got: '.$clientId. + ' expected: '.$refreshTokenData['client_id'] ); } @@ -128,7 +128,7 @@ class RefreshTokenGrant extends AbstractGrant } /** - * @inheritdoc + * {@inheritdoc} */ public function getIdentifier() { diff --git a/src/Repositories/AccessTokenRepositoryInterface.php b/src/Repositories/AccessTokenRepositoryInterface.php index f39351ff..d9e054d8 100644 --- a/src/Repositories/AccessTokenRepositoryInterface.php +++ b/src/Repositories/AccessTokenRepositoryInterface.php @@ -1,39 +1,38 @@ * @copyright Copyright (c) Alex Bilbie * @license http://mit-license.org/ + * * @link https://github.com/thephpleague/oauth2-server */ - namespace League\OAuth2\Server\Repositories; use League\OAuth2\Server\Entities\Interfaces\AccessTokenEntityInterface; /** - * Access token interface + * Access token interface. */ interface AccessTokenRepositoryInterface extends RepositoryInterface { /** - * Persists a new access token to permanent storage + * Persists a new access token to permanent storage. * * @param \League\OAuth2\Server\Entities\Interfaces\AccessTokenEntityInterface $accessTokenEntity */ public function persistNewAccessToken(AccessTokenEntityInterface $accessTokenEntity); /** - * Revoke an access token + * Revoke an access token. * * @param string $tokenId */ public function revokeAccessToken($tokenId); /** - * Check if the access token has been revoked + * Check if the access token has been revoked. * * @param string $tokenId * diff --git a/src/Repositories/AuthCodeRepositoryInterface.php b/src/Repositories/AuthCodeRepositoryInterface.php index a6742092..16c48742 100644 --- a/src/Repositories/AuthCodeRepositoryInterface.php +++ b/src/Repositories/AuthCodeRepositoryInterface.php @@ -1,39 +1,38 @@ * @copyright Copyright (c) Alex Bilbie * @license http://mit-license.org/ + * * @link https://github.com/thephpleague/oauth2-server */ - namespace League\OAuth2\Server\Repositories; use League\OAuth2\Server\Entities\Interfaces\AuthCodeEntityInterface; /** - * Auth code storage interface + * Auth code storage interface. */ interface AuthCodeRepositoryInterface extends RepositoryInterface { /** - * Persists a new auth code to permanent storage + * Persists a new auth code to permanent storage. * * @param \League\OAuth2\Server\Entities\Interfaces\AuthCodeEntityInterface $authCodeEntity */ public function persistNewAuthCode(AuthCodeEntityInterface $authCodeEntity); /** - * Revoke an auth code + * Revoke an auth code. * * @param string $codeId */ public function revokeAuthCode($codeId); /** - * Check if the auth code has been revoked + * Check if the auth code has been revoked. * * @param string $codeId * diff --git a/src/Repositories/ClientRepositoryInterface.php b/src/Repositories/ClientRepositoryInterface.php index eb88a6cd..0c7ebe4f 100644 --- a/src/Repositories/ClientRepositoryInterface.php +++ b/src/Repositories/ClientRepositoryInterface.php @@ -1,26 +1,25 @@ * @copyright Copyright (c) Alex Bilbie * @license http://mit-license.org/ + * * @link https://github.com/thephpleague/oauth2-server */ - namespace League\OAuth2\Server\Repositories; /** - * Client storage interface + * Client storage interface. */ interface ClientRepositoryInterface extends RepositoryInterface { /** - * Get a client + * Get a client. * - * @param string $clientIdentifier The client's identifier - * @param string $grantType The grant type used + * @param string $clientIdentifier The client's identifier + * @param string $grantType The grant type used * * @return \League\OAuth2\Server\Entities\Interfaces\ClientEntityInterface */ diff --git a/src/Repositories/MacTokenInterface.php b/src/Repositories/MacTokenInterface.php index 833a0d7b..00e35a4c 100644 --- a/src/Repositories/MacTokenInterface.php +++ b/src/Repositories/MacTokenInterface.php @@ -1,25 +1,24 @@ * @copyright Copyright (c) Alex Bilbie * @license http://mit-license.org/ + * * @link https://github.com/thephpleague/oauth2-server */ - namespace League\OAuth2\Server\Storage; use League\OAuth2\Server\Repositories\RepositoryInterface; /** - * MacTokenInterface + * MacTokenInterface. */ interface MacTokenInterface extends RepositoryInterface { /** - * Create a MAC key linked to an access token + * Create a MAC key linked to an access token. * * @param string $macKey * @param string $accessToken @@ -27,9 +26,9 @@ interface MacTokenInterface extends RepositoryInterface public function persistMacTokenEntity($macKey, $accessToken); /** - * Get a MAC key by access token + * Get a MAC key by access token. * - * @param string $accessToken + * @param string $accessToken * * @return string */ diff --git a/src/Repositories/RefreshTokenRepositoryInterface.php b/src/Repositories/RefreshTokenRepositoryInterface.php index 533351d8..d987ab22 100644 --- a/src/Repositories/RefreshTokenRepositoryInterface.php +++ b/src/Repositories/RefreshTokenRepositoryInterface.php @@ -1,39 +1,38 @@ * @copyright Copyright (c) Alex Bilbie * @license http://mit-license.org/ + * * @link https://github.com/thephpleague/oauth2-server */ - namespace League\OAuth2\Server\Repositories; use League\OAuth2\Server\Entities\Interfaces\RefreshTokenEntityInterface; /** - * Refresh token interface + * Refresh token interface. */ interface RefreshTokenRepositoryInterface extends RepositoryInterface { /** - * Create a new refresh token_name + * Create a new refresh token_name. * * @param \League\OAuth2\Server\Entities\Interfaces\RefreshTokenEntityInterface $refreshTokenEntity */ public function persistNewRefreshToken(RefreshTokenEntityInterface $refreshTokenEntity); /** - * Revoke the refresh token + * Revoke the refresh token. * * @param string $tokenId */ public function revokeRefreshToken($tokenId); /** - * Check if the refresh token has been revoked + * Check if the refresh token has been revoked. * * @param string $tokenId * diff --git a/src/Repositories/RepositoryInterface.php b/src/Repositories/RepositoryInterface.php index 030c116f..5273057c 100644 --- a/src/Repositories/RepositoryInterface.php +++ b/src/Repositories/RepositoryInterface.php @@ -1,18 +1,17 @@ * @copyright Copyright (c) Alex Bilbie * @license http://mit-license.org/ + * * @link https://github.com/thephpleague/oauth2-server */ - namespace League\OAuth2\Server\Repositories; /** - * Repository interface + * Repository interface. */ interface RepositoryInterface { diff --git a/src/Repositories/ScopeRepositoryInterface.php b/src/Repositories/ScopeRepositoryInterface.php index 0b45efe9..5ac9aff8 100644 --- a/src/Repositories/ScopeRepositoryInterface.php +++ b/src/Repositories/ScopeRepositoryInterface.php @@ -1,23 +1,22 @@ * @copyright Copyright (c) Alex Bilbie * @license http://mit-license.org/ + * * @link https://github.com/thephpleague/oauth2-server */ - namespace League\OAuth2\Server\Repositories; /** - * Scope interface + * Scope interface. */ interface ScopeRepositoryInterface extends RepositoryInterface { /** - * Return information about a scope + * Return information about a scope. * * @param string $identifier The scope identifier * @param string $grantType The grant type used in the request diff --git a/src/Repositories/UserRepositoryInterface.php b/src/Repositories/UserRepositoryInterface.php index 5767a5ed..d93c85a7 100644 --- a/src/Repositories/UserRepositoryInterface.php +++ b/src/Repositories/UserRepositoryInterface.php @@ -5,7 +5,7 @@ namespace League\OAuth2\Server\Repositories; interface UserRepositoryInterface extends RepositoryInterface { /** - * Get a user entity + * Get a user entity. * * @param string $username * @param string $password diff --git a/src/ResponseTypes/AbstractResponseType.php b/src/ResponseTypes/AbstractResponseType.php index 9605a463..bc218266 100644 --- a/src/ResponseTypes/AbstractResponseType.php +++ b/src/ResponseTypes/AbstractResponseType.php @@ -1,14 +1,13 @@ * @copyright Copyright (c) Alex Bilbie * @license http://mit-license.org/ + * * @link https://github.com/thephpleague/oauth2-server */ - namespace League\OAuth2\Server\ResponseTypes; use League\OAuth2\Server\Entities\Interfaces\AccessTokenEntityInterface; diff --git a/src/ResponseTypes/BearerTokenResponse.php b/src/ResponseTypes/BearerTokenResponse.php index d1b88218..28e9003a 100644 --- a/src/ResponseTypes/BearerTokenResponse.php +++ b/src/ResponseTypes/BearerTokenResponse.php @@ -1,14 +1,13 @@ * @copyright Copyright (c) Alex Bilbie * @license http://mit-license.org/ + * * @link https://github.com/thephpleague/oauth2-server */ - namespace League\OAuth2\Server\ResponseTypes; use Lcobucci\JWT\Builder; @@ -43,7 +42,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, ]; diff --git a/src/ResponseTypes/MAC.php b/src/ResponseTypes/MAC.php index 48c2274f..598214d4 100644 --- a/src/ResponseTypes/MAC.php +++ b/src/ResponseTypes/MAC.php @@ -1,14 +1,13 @@ * @copyright Copyright (c) Alex Bilbie * @license http://mit-license.org/ + * * @link https://github.com/thephpleague/oauth2-server */ - namespace League\OAuth2\Server\TokenTypes; use League\OAuth2\Server\Util\SecureKey; @@ -16,7 +15,7 @@ use Symfony\Component\HttpFoundation\ParameterBag; use Symfony\Component\HttpFoundation\Request; /** - * MAC Token Type + * MAC Token Type. */ class MAC extends AbstractTokenType implements TokenTypeInterface { @@ -29,11 +28,11 @@ class MAC extends AbstractTokenType implements TokenTypeInterface $this->server->getMacStorage()->create($macKey, $this->getParam('access_token')); $response = [ - 'access_token' => $this->getParam('access_token'), - 'token_type' => 'mac', - 'expires_in' => $this->getParam('expires_in'), - 'mac_key' => $macKey, - 'mac_algorithm' => 'hmac-sha-256', + 'access_token' => $this->getParam('access_token'), + 'token_type' => 'mac', + 'expires_in' => $this->getParam('expires_in'), + 'mac_key' => $macKey, + 'mac_algorithm' => 'hmac-sha-256', ]; return $response; @@ -121,9 +120,11 @@ class MAC extends AbstractTokenType implements TokenTypeInterface } /** - * Prevent timing attack - * @param string $knownString - * @param string $userString + * Prevent timing attack. + * + * @param string $knownString + * @param string $userString + * * @return bool */ private function hash_equals($knownString, $userString) diff --git a/src/ResponseTypes/ResponseTypeInterface.php b/src/ResponseTypes/ResponseTypeInterface.php index 6524f049..34198eaf 100644 --- a/src/ResponseTypes/ResponseTypeInterface.php +++ b/src/ResponseTypes/ResponseTypeInterface.php @@ -1,14 +1,13 @@ * @copyright Copyright (c) Alex Bilbie * @license http://mit-license.org/ + * * @link https://github.com/thephpleague/oauth2-server */ - namespace League\OAuth2\Server\ResponseTypes; use League\OAuth2\Server\Entities\Interfaces\AccessTokenEntityInterface; @@ -30,7 +29,7 @@ interface ResponseTypeInterface /** * Determine the access token in the authorization header and append OAUth properties to the request - * as attributes + * as attributes. * * @param ServerRequestInterface $request * diff --git a/src/Server.php b/src/Server.php index 4e7799d3..248a5b7c 100644 --- a/src/Server.php +++ b/src/Server.php @@ -62,7 +62,7 @@ class Server implements EmitterAwareInterface private $scopeRepository; /** - * New server instance + * New server instance. * * @param \League\OAuth2\Server\Repositories\ClientRepositoryInterface $clientRepository * @param \League\OAuth2\Server\Repositories\AccessTokenRepositoryInterface $accessTokenRepository @@ -88,7 +88,7 @@ class Server implements EmitterAwareInterface } /** - * Enable a grant type on the server + * Enable a grant type on the server. * * @param \League\OAuth2\Server\Grant\GrantTypeInterface $grantType * @param \DateInterval $accessTokenTTL @@ -108,13 +108,14 @@ class Server implements EmitterAwareInterface } /** - * Return an access token response + * Return an access token response. * * @param \Psr\Http\Message\ServerRequestInterface|null $request * @param \Psr\Http\Message\ResponseInterface|null $response * - * @return \Psr\Http\Message\ResponseInterface * @throws \League\OAuth2\Server\Exception\OAuthServerException + * + * @return \Psr\Http\Message\ResponseInterface */ public function respondToRequest(ServerRequestInterface $request = null, ResponseInterface $response = null) { @@ -149,13 +150,13 @@ class Server implements EmitterAwareInterface } /** - * Determine the access token validity + * Determine the access token validity. * * @param \Psr\Http\Message\ServerRequestInterface $request * - * @return \Psr\Http\Message\ServerRequestInterface - * * @throws \League\OAuth2\Server\Exception\OAuthServerException + * + * @return \Psr\Http\Message\ServerRequestInterface */ public function validateRequest(ServerRequestInterface $request) { @@ -163,7 +164,7 @@ class Server implements EmitterAwareInterface } /** - * Get the token type that grants will return in the HTTP response + * Get the token type that grants will return in the HTTP response. * * @return ResponseTypeInterface */ diff --git a/src/Utils/KeyCrypt.php b/src/Utils/KeyCrypt.php index 8b62c10a..48659bde 100644 --- a/src/Utils/KeyCrypt.php +++ b/src/Utils/KeyCrypt.php @@ -1,20 +1,19 @@ * @copyright Copyright (c) Alex Bilbie * @license http://mit-license.org/ + * * @link https://github.com/thephpleague/oauth2-server */ - namespace League\OAuth2\Server\Utils; class KeyCrypt { /** - * Encrypt data with a private key + * Encrypt data with a private key. * * @param string $unencryptedData * @param string $pathToPrivateKey @@ -48,7 +47,7 @@ class KeyCrypt } /** - * Decrypt data with a public key + * Decrypt data with a public key. * * @param string $encryptedData * @param string $pathToPublicKey diff --git a/src/Utils/SecureKey.php b/src/Utils/SecureKey.php index ee5a85ea..17a2fcf2 100644 --- a/src/Utils/SecureKey.php +++ b/src/Utils/SecureKey.php @@ -1,31 +1,30 @@ * @copyright Copyright (c) 2013 PHP League of Extraordinary Packages * @license http://mit-license.org/ + * * @link http://github.com/php-loep/oauth2-server */ - namespace League\OAuth2\Server\Utils; use League\OAuth2\Server\Exception\OAuthServerException; - /** - * SecureKey class + * SecureKey class. */ class SecureKey { /** - * Generate a new unique code + * Generate a new unique code. * - * @param integer $len Length of the generated code + * @param int $len Length of the generated code + * + * @throws \League\OAuth2\Server\Exception\OAuthServerException * * @return string - * @throws \League\OAuth2\Server\Exception\OAuthServerException */ public static function generate($len = 40) { @@ -34,13 +33,13 @@ class SecureKey // @codeCoverageIgnoreStart } catch (\TypeError $e) { // Well, it's an integer, so this IS unexpected. - throw OAuthServerException::serverError("An unexpected error has occurred"); + throw OAuthServerException::serverError('An unexpected error has occurred'); } catch (\Error $e) { // This is also unexpected because 32 is a reasonable integer. - throw OAuthServerException::serverError("An unexpected error has occurred"); + throw OAuthServerException::serverError('An unexpected error has occurred'); } catch (\Exception $e) { // If you get this message, the CSPRNG failed hard. - throw OAuthServerException::serverError("Could not generate a random string. Is our OS secure?"); + throw OAuthServerException::serverError('Could not generate a random string. Is our OS secure?'); } // @codeCoverageIgnoreEnd diff --git a/tests/Bootstrap.php b/tests/Bootstrap.php index 7f8cf458..8ea9bc26 100644 --- a/tests/Bootstrap.php +++ b/tests/Bootstrap.php @@ -1,5 +1,5 @@ wget http://getcomposer.org/composer.phar\n> php composer.phar install\n"); } diff --git a/tests/Grant/AbstractGrantTest.php b/tests/Grant/AbstractGrantTest.php index d64f6edb..a2b764d2 100644 --- a/tests/Grant/AbstractGrantTest.php +++ b/tests/Grant/AbstractGrantTest.php @@ -10,11 +10,11 @@ use League\OAuth2\Server\Entities\Interfaces\AuthCodeEntityInterface; use League\OAuth2\Server\Entities\Interfaces\RefreshTokenEntityInterface; use League\OAuth2\Server\Entities\ScopeEntity; use League\OAuth2\Server\Grant\AbstractGrant; -use League\OAuth2\Server\Repositories\ClientRepositoryInterface; -use League\OAuth2\Server\Repositories\ScopeRepositoryInterface; -use League\OAuth2\Server\Repositories\RefreshTokenRepositoryInterface; use League\OAuth2\Server\Repositories\AccessTokenRepositoryInterface; 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 Zend\Diactoros\ServerRequest; class AbstractGrantTest extends \PHPUnit_Framework_TestCase @@ -151,7 +151,7 @@ class AbstractGrantTest extends \PHPUnit_Framework_TestCase $serverRequest = new ServerRequest(); $serverRequest = $serverRequest->withParsedBody([ - 'client_id' => 'foo', + 'client_id' => 'foo', 'client_secret' => 'foo', ]); @@ -180,7 +180,7 @@ class AbstractGrantTest extends \PHPUnit_Framework_TestCase $serverRequest = new ServerRequest(); $serverRequest = $serverRequest->withParsedBody([ 'client_id' => 'foo', - 'redirect_uri' => 'http://bar/foo' + 'redirect_uri' => 'http://bar/foo', ]); $validateClientMethod = $abstractGrantReflection->getMethod('validateClient'); diff --git a/tests/Grant/ClientCredentialsGrantTest.php b/tests/Grant/ClientCredentialsGrantTest.php index 52e51c9a..c67e889c 100644 --- a/tests/Grant/ClientCredentialsGrantTest.php +++ b/tests/Grant/ClientCredentialsGrantTest.php @@ -42,7 +42,7 @@ class ClientCredentialsGrantTest extends \PHPUnit_Framework_TestCase $responseType = new StubResponseType(); $grant->respondToRequest($serverRequest, $responseType, new \DateInterval('PT5M')); - + $this->assertTrue($responseType->getAccessToken() instanceof AccessTokenEntityInterface); } } diff --git a/tests/Grant/RefreshTokenGrantTest.php b/tests/Grant/RefreshTokenGrantTest.php index 8bfe71c9..3be59bdb 100644 --- a/tests/Grant/RefreshTokenGrantTest.php +++ b/tests/Grant/RefreshTokenGrantTest.php @@ -5,7 +5,6 @@ namespace LeagueTests\Grant; use League\OAuth2\Server\Entities\ClientEntity; use League\OAuth2\Server\Entities\Interfaces\AccessTokenEntityInterface; use League\OAuth2\Server\Entities\Interfaces\RefreshTokenEntityInterface; -use League\OAuth2\Server\Grant\PasswordGrant; use League\OAuth2\Server\Grant\RefreshTokenGrant; use League\OAuth2\Server\Repositories\AccessTokenRepositoryInterface; use League\OAuth2\Server\Repositories\ClientRepositoryInterface; @@ -14,7 +13,6 @@ use League\OAuth2\Server\Repositories\UserRepositoryInterface; use League\OAuth2\Server\Utils\KeyCrypt; use LeagueTests\Stubs\StubResponseType; use LeagueTests\Stubs\UserEntity; -use OAuth2ServerExamples\Repositories\RefreshTokenRepository; use Zend\Diactoros\ServerRequest; class RefreshTokenGrantTest extends \PHPUnit_Framework_TestCase diff --git a/tests/ServerTest.php b/tests/ServerTest.php index 9a85c351..3f823a17 100644 --- a/tests/ServerTest.php +++ b/tests/ServerTest.php @@ -4,11 +4,11 @@ namespace LeagueTests; use League\OAuth2\Server\Entities\ClientEntity; use League\OAuth2\Server\Grant\ClientCredentialsGrant; +use League\OAuth2\Server\Repositories\AccessTokenRepositoryInterface; +use League\OAuth2\Server\Repositories\ClientRepositoryInterface; +use League\OAuth2\Server\Repositories\ScopeRepositoryInterface; use League\OAuth2\Server\Server; use LeagueTests\Stubs\StubResponseType; -use League\OAuth2\Server\Repositories\ClientRepositoryInterface; -use League\OAuth2\Server\Repositories\AccessTokenRepositoryInterface; -use League\OAuth2\Server\Repositories\ScopeRepositoryInterface; use Psr\Http\Message\ResponseInterface; class ServerTest extends \PHPUnit_Framework_TestCase diff --git a/tests/Stubs/StubResponseType.php b/tests/Stubs/StubResponseType.php index d62daf9b..22d093a0 100644 --- a/tests/Stubs/StubResponseType.php +++ b/tests/Stubs/StubResponseType.php @@ -11,7 +11,9 @@ use Zend\Diactoros\Response; class StubResponseType extends AbstractResponseType { - public function __construct() {} + public function __construct() + { + } public function getAccessToken() { @@ -58,4 +60,4 @@ class StubResponseType extends AbstractResponseType { return new Response(); } -} \ No newline at end of file +} diff --git a/tests/Stubs/UserEntity.php b/tests/Stubs/UserEntity.php index 4c157df5..5d102c77 100644 --- a/tests/Stubs/UserEntity.php +++ b/tests/Stubs/UserEntity.php @@ -10,4 +10,4 @@ class UserEntity implements UserEntityInterface { return 123; } -} \ No newline at end of file +}