Skip to content

Commit

Permalink
Merge pull request #966 from ceeram/fully_qualified_strict_types
Browse files Browse the repository at this point in the history
Replace fqn with unqualified name
  • Loading branch information
Sephster authored Nov 13, 2018
2 parents 34ec350 + 4bb5b74 commit 95a9f46
Show file tree
Hide file tree
Showing 23 changed files with 137 additions and 95 deletions.
1 change: 1 addition & 0 deletions .styleci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 6 additions & 5 deletions src/AuthorizationServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

namespace League\OAuth2\Server;

use DateInterval;
use Defuse\Crypto\Key;
use League\Event\EmitterAwareInterface;
use League\Event\EmitterAwareTrait;
Expand All @@ -34,7 +35,7 @@ class AuthorizationServer implements EmitterAwareInterface
protected $enabledGrantTypes = [];

/**
* @var \DateInterval[]
* @var DateInterval[]
*/
protected $grantTypeAccessTokenTTL = [];

Expand Down Expand Up @@ -126,12 +127,12 @@ public function __construct(
* 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);
Expand Down
13 changes: 8 additions & 5 deletions src/AuthorizationValidators/BearerTokenValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -17,6 +19,7 @@
use League\OAuth2\Server\Exception\OAuthServerException;
use League\OAuth2\Server\Repositories\AccessTokenRepositoryInterface;
use Psr\Http\Message\ServerRequestInterface;
use RuntimeException;

class BearerTokenValidator implements AuthorizationValidatorInterface
{
Expand All @@ -28,7 +31,7 @@ class BearerTokenValidator implements AuthorizationValidatorInterface
private $accessTokenRepository;

/**
* @var \League\OAuth2\Server\CryptKey
* @var CryptKey
*/
protected $publicKey;

Expand All @@ -43,7 +46,7 @@ public function __construct(AccessTokenRepositoryInterface $accessTokenRepositor
/**
* Set the public key
*
* @param \League\OAuth2\Server\CryptKey $key
* @param CryptKey $key
*/
public function setPublicKey(CryptKey $key)
{
Expand All @@ -69,7 +72,7 @@ public function validateAuthorization(ServerRequestInterface $request)
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');
}

Expand All @@ -92,10 +95,10 @@ public function validateAuthorization(ServerRequestInterface $request)
->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');
}
Expand Down
13 changes: 8 additions & 5 deletions src/CryptKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@

namespace League\OAuth2\Server;

use LogicException;
use RuntimeException;

class CryptKey
{
const RSA_KEY_PATTERN =
Expand Down Expand Up @@ -42,7 +45,7 @@ public function __construct($keyPath, $passPhrase = null, $keyPermissionsCheck =
}

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) {
Expand All @@ -64,7 +67,7 @@ public function __construct($keyPath, $passPhrase = null, $keyPermissionsCheck =
/**
* @param string $key
*
* @throws \RuntimeException
* @throws RuntimeException
*
* @return string
*/
Expand All @@ -79,19 +82,19 @@ private function saveKeyToFile($key)

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
}

Expand Down
14 changes: 8 additions & 6 deletions src/CryptTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

use Defuse\Crypto\Crypto;
use Defuse\Crypto\Key;
use Exception;
use LogicException;

trait CryptTrait
{
Expand All @@ -26,7 +28,7 @@ trait CryptTrait
*
* @param string $unencryptedData
*
* @throws \LogicException
* @throws LogicException
*
* @return string
*/
Expand All @@ -38,8 +40,8 @@ protected function encrypt($unencryptedData)
}

return Crypto::encryptWithPassword($unencryptedData, $this->encryptionKey);
} catch (\Exception $e) {
throw new \LogicException($e->getMessage());
} catch (Exception $e) {
throw new LogicException($e->getMessage());
}
}

Expand All @@ -48,7 +50,7 @@ protected function encrypt($unencryptedData)
*
* @param string $encryptedData
*
* @throws \LogicException
* @throws LogicException
*
* @return string
*/
Expand All @@ -60,8 +62,8 @@ protected function decrypt($encryptedData)
}

return Crypto::decryptWithPassword($encryptedData, $this->encryptionKey);
} catch (\Exception $e) {
throw new \LogicException($e->getMessage());
} catch (Exception $e) {
throw new LogicException($e->getMessage());
}
}

Expand Down
8 changes: 5 additions & 3 deletions src/Entities/RefreshTokenEntityInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

namespace League\OAuth2\Server\Entities;

use DateTime;

interface RefreshTokenEntityInterface
{
/**
Expand All @@ -28,16 +30,16 @@ public function setIdentifier($identifier);
/**
* 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.
Expand Down
4 changes: 3 additions & 1 deletion src/Entities/ScopeEntityInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@

namespace League\OAuth2\Server\Entities;

interface ScopeEntityInterface extends \JsonSerializable
use JsonSerializable;

interface ScopeEntityInterface extends JsonSerializable
{
/**
* Get the scope's identifier.
Expand Down
8 changes: 5 additions & 3 deletions src/Entities/TokenInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

namespace League\OAuth2\Server\Entities;

use DateTime;

interface TokenInterface
{
/**
Expand All @@ -28,16 +30,16 @@ public function setIdentifier($identifier);
/**
* 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.
Expand Down
3 changes: 2 additions & 1 deletion src/Entities/Traits/AccessTokenTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -46,7 +47,7 @@ public function convertToJWT(CryptKey $privateKey)
abstract public function getClient();

/**
* @return \DateTime
* @return DateTime
*/
abstract public function getExpiryDateTime();

Expand Down
9 changes: 5 additions & 4 deletions src/Entities/Traits/RefreshTokenTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

namespace League\OAuth2\Server\Entities\Traits;

use DateTime;
use League\OAuth2\Server\Entities\AccessTokenEntityInterface;

trait RefreshTokenTrait
Expand All @@ -19,7 +20,7 @@ trait RefreshTokenTrait
protected $accessToken;

/**
* @var \DateTime
* @var DateTime
*/
protected $expiryDateTime;

Expand All @@ -42,7 +43,7 @@ public function getAccessToken()
/**
* Get the token's expiry date time.
*
* @return \DateTime
* @return DateTime
*/
public function getExpiryDateTime()
{
Expand All @@ -52,9 +53,9 @@ 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)
{
$this->expiryDateTime = $dateTime;
}
Expand Down
9 changes: 5 additions & 4 deletions src/Entities/Traits/TokenEntityTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

namespace League\OAuth2\Server\Entities\Traits;

use DateTime;
use League\OAuth2\Server\Entities\ClientEntityInterface;
use League\OAuth2\Server\Entities\ScopeEntityInterface;

Expand All @@ -20,7 +21,7 @@ trait TokenEntityTrait
protected $scopes = [];

/**
* @var \DateTime
* @var DateTime
*/
protected $expiryDateTime;

Expand Down Expand Up @@ -57,7 +58,7 @@ public function getScopes()
/**
* Get the token's expiry date time.
*
* @return \DateTime
* @return DateTime
*/
public function getExpiryDateTime()
{
Expand All @@ -67,9 +68,9 @@ 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)
{
$this->expiryDateTime = $dateTime;
}
Expand Down
3 changes: 2 additions & 1 deletion src/Exception/OAuthServerException.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit 95a9f46

Please sign in to comment.