diff --git a/.travis.yml b/.travis.yml index a9023fa6..187d4f6f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,7 +7,6 @@ cache: - vendor php: - - 5.6 - 7.0 - 7.1 - 7.2 @@ -17,6 +16,7 @@ install: script: - vendor/bin/phpunit + - vendor/bin/phpstan analyse -l 6 src branches: only: diff --git a/composer.json b/composer.json index d8d11125..86f82c41 100644 --- a/composer.json +++ b/composer.json @@ -4,7 +4,7 @@ "homepage": "https://oauth2.thephpleague.com/", "license": "MIT", "require": { - "php": ">=5.6.0", + "php": ">=7.0.0", "ext-openssl": "*", "league/event": "^2.1", "lcobucci/jwt": "^3.1", @@ -14,7 +14,8 @@ }, "require-dev": { "phpunit/phpunit": "^4.8.38 || ^5.7.21", - "zendframework/zend-diactoros": "^1.0" + "zendframework/zend-diactoros": "^1.0", + "phpstan/phpstan": "^0.9.2" }, "repositories": [ { diff --git a/src/AuthorizationServer.php b/src/AuthorizationServer.php index 69c16954..876b0083 100644 --- a/src/AuthorizationServer.php +++ b/src/AuthorizationServer.php @@ -17,6 +17,7 @@ use League\OAuth2\Server\Repositories\AccessTokenRepositoryInterface; use League\OAuth2\Server\Repositories\ClientRepositoryInterface; use League\OAuth2\Server\Repositories\ScopeRepositoryInterface; use League\OAuth2\Server\RequestTypes\AuthorizationRequest; +use League\OAuth2\Server\ResponseTypes\AbstractResponseType; use League\OAuth2\Server\ResponseTypes\BearerTokenResponse; use League\OAuth2\Server\ResponseTypes\ResponseTypeInterface; use Psr\Http\Message\ResponseInterface; @@ -190,7 +191,7 @@ class AuthorizationServer implements EmitterAwareInterface if ($tokenResponse instanceof ResponseTypeInterface) { return $tokenResponse->generateHttpResponse($response); } - + } throw OAuthServerException::unsupportedGrantType(); @@ -207,7 +208,9 @@ class AuthorizationServer implements EmitterAwareInterface $this->responseType = new BearerTokenResponse(); } - $this->responseType->setPrivateKey($this->privateKey); + if ($this->responseType instanceof AbstractResponseType === true) { + $this->responseType->setPrivateKey($this->privateKey); + } $this->responseType->setEncryptionKey($this->encryptionKey); return $this->responseType; diff --git a/src/Entities/AccessTokenEntityInterface.php b/src/Entities/AccessTokenEntityInterface.php index c297e267..4da7600e 100644 --- a/src/Entities/AccessTokenEntityInterface.php +++ b/src/Entities/AccessTokenEntityInterface.php @@ -9,6 +9,7 @@ namespace League\OAuth2\Server\Entities; +use Lcobucci\JWT\Token; use League\OAuth2\Server\CryptKey; interface AccessTokenEntityInterface extends TokenInterface @@ -18,7 +19,7 @@ interface AccessTokenEntityInterface extends TokenInterface * * @param CryptKey $privateKey * - * @return string + * @return Token */ public function convertToJWT(CryptKey $privateKey); } diff --git a/src/Entities/RefreshTokenEntityInterface.php b/src/Entities/RefreshTokenEntityInterface.php index 05e86e00..e4f10400 100644 --- a/src/Entities/RefreshTokenEntityInterface.php +++ b/src/Entities/RefreshTokenEntityInterface.php @@ -21,7 +21,7 @@ interface RefreshTokenEntityInterface /** * Set the token's identifier. * - * @param $identifier + * @param mixed $identifier */ public function setIdentifier($identifier); diff --git a/src/Entities/TokenInterface.php b/src/Entities/TokenInterface.php index c842b09a..378adbdc 100644 --- a/src/Entities/TokenInterface.php +++ b/src/Entities/TokenInterface.php @@ -21,7 +21,7 @@ interface TokenInterface /** * Set the token's identifier. * - * @param $identifier + * @param mixed $identifier */ public function setIdentifier($identifier); @@ -42,14 +42,14 @@ interface TokenInterface /** * Set the identifier of the user associated with the token. * - * @param string|int $identifier The identifier of the user + * @param string|int|null $identifier The identifier of the user */ public function setUserIdentifier($identifier); /** * Get the token user's identifier. * - * @return string|int + * @return string|int|null */ public function getUserIdentifier(); diff --git a/src/Entities/Traits/AccessTokenTrait.php b/src/Entities/Traits/AccessTokenTrait.php index 741d6c19..81fc1bfd 100644 --- a/src/Entities/Traits/AccessTokenTrait.php +++ b/src/Entities/Traits/AccessTokenTrait.php @@ -12,6 +12,7 @@ namespace League\OAuth2\Server\Entities\Traits; use Lcobucci\JWT\Builder; use Lcobucci\JWT\Signer\Key; use Lcobucci\JWT\Signer\Rsa\Sha256; +use Lcobucci\JWT\Token; use League\OAuth2\Server\CryptKey; use League\OAuth2\Server\Entities\ClientEntityInterface; use League\OAuth2\Server\Entities\ScopeEntityInterface; @@ -23,7 +24,7 @@ trait AccessTokenTrait * * @param CryptKey $privateKey * - * @return string + * @return Token */ public function convertToJWT(CryptKey $privateKey) { diff --git a/src/Entities/Traits/TokenEntityTrait.php b/src/Entities/Traits/TokenEntityTrait.php index 0b5608cd..c6653cce 100644 --- a/src/Entities/Traits/TokenEntityTrait.php +++ b/src/Entities/Traits/TokenEntityTrait.php @@ -25,7 +25,7 @@ trait TokenEntityTrait protected $expiryDateTime; /** - * @var string|int + * @var string|int|null */ protected $userIdentifier; @@ -77,7 +77,7 @@ trait TokenEntityTrait /** * Set the identifier of the user associated with the token. * - * @param string|int $identifier The identifier of the user + * @param string|int|null $identifier The identifier of the user */ public function setUserIdentifier($identifier) { @@ -87,7 +87,7 @@ trait TokenEntityTrait /** * Get the token user's identifier. * - * @return string|int + * @return string|int|null */ public function getUserIdentifier() { diff --git a/src/Exception/OAuthServerException.php b/src/Exception/OAuthServerException.php index 8d101c4c..756dfd3b 100644 --- a/src/Exception/OAuthServerException.php +++ b/src/Exception/OAuthServerException.php @@ -131,7 +131,7 @@ class OAuthServerException extends \Exception /** * Server error. * - * @param $hint + * @param string $hint * * @return static * diff --git a/src/Grant/AbstractGrant.php b/src/Grant/AbstractGrant.php index 25378955..e806ba09 100644 --- a/src/Grant/AbstractGrant.php +++ b/src/Grant/AbstractGrant.php @@ -341,7 +341,7 @@ abstract class AbstractGrant implements GrantTypeInterface * * @param \DateInterval $accessTokenTTL * @param ClientEntityInterface $client - * @param string $userIdentifier + * @param string|null $userIdentifier * @param ScopeEntityInterface[] $scopes * * @throws OAuthServerException diff --git a/src/RequestTypes/AuthorizationRequest.php b/src/RequestTypes/AuthorizationRequest.php index 41bfb509..ce5a0034 100644 --- a/src/RequestTypes/AuthorizationRequest.php +++ b/src/RequestTypes/AuthorizationRequest.php @@ -53,7 +53,7 @@ class AuthorizationRequest /** * The redirect URI used in the request * - * @var string + * @var string|null */ protected $redirectUri; @@ -159,7 +159,7 @@ class AuthorizationRequest } /** - * @return string + * @return string|null */ public function getRedirectUri() { @@ -167,7 +167,7 @@ class AuthorizationRequest } /** - * @param string $redirectUri + * @param string|null $redirectUri */ public function setRedirectUri($redirectUri) { diff --git a/src/ResourceServer.php b/src/ResourceServer.php index 5e9c13f3..e1f98d6d 100644 --- a/src/ResourceServer.php +++ b/src/ResourceServer.php @@ -63,7 +63,9 @@ class ResourceServer $this->authorizationValidator = new BearerTokenValidator($this->accessTokenRepository); } - $this->authorizationValidator->setPublicKey($this->publicKey); + if ($this->authorizationValidator instanceof BearerTokenValidator === true) { + $this->authorizationValidator->setPublicKey($this->publicKey); + } return $this->authorizationValidator; }