From 16f9de86f2891cc89a8f26062cff2708d6ed5447 Mon Sep 17 00:00:00 2001 From: Marc Bennewitz Date: Thu, 8 Nov 2018 10:41:01 +0100 Subject: [PATCH 1/3] cleanup DateTime handline * DateTime -> DateTimeImmutable * DateTime::format('U') -> DateTime::getTimestamp() * (new DateTime())->getTimestamp() -> time() --- src/AuthorizationServer.php | 11 +- src/Entities/RefreshTokenEntityInterface.php | 10 +- src/Entities/TokenInterface.php | 10 +- src/Entities/Traits/AccessTokenTrait.php | 5 +- src/Entities/Traits/RefreshTokenTrait.php | 11 +- src/Entities/Traits/TokenEntityTrait.php | 11 +- src/Grant/AbstractGrant.php | 20 +-- src/Grant/AuthCodeGrant.php | 22 ++-- src/Grant/ClientCredentialsGrant.php | 3 +- src/Grant/GrantTypeInterface.php | 9 +- src/Grant/ImplicitGrant.php | 19 +-- src/Grant/PasswordGrant.php | 5 +- src/Grant/RefreshTokenGrant.php | 5 +- src/ResponseTypes/BearerTokenResponse.php | 2 +- tests/AuthorizationServerTest.php | 11 +- tests/Grant/AbstractGrantTest.php | 7 +- tests/Grant/AuthCodeGrantTest.php | 117 +++++++++--------- tests/Grant/ClientCredentialsGrantTest.php | 3 +- tests/Grant/ImplicitGrantTest.php | 41 +++--- tests/Grant/PasswordGrantTest.php | 9 +- tests/Grant/RefreshTokenGrantTest.php | 17 +-- .../AuthorizationServerMiddlewareTest.php | 3 +- .../ResourceServerMiddlewareTest.php | 6 +- .../ResponseTypes/BearerResponseTypeTest.php | 22 ++-- 24 files changed, 202 insertions(+), 177 deletions(-) diff --git a/src/AuthorizationServer.php b/src/AuthorizationServer.php index f1e96146..81973b24 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 = []; @@ -112,12 +113,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 === null) { + $accessTokenTTL = new DateInterval('PT1H'); } $grantType->setAccessTokenRepository($this->accessTokenRepository); diff --git a/src/Entities/RefreshTokenEntityInterface.php b/src/Entities/RefreshTokenEntityInterface.php index e4f10400..a197ce5e 100644 --- a/src/Entities/RefreshTokenEntityInterface.php +++ b/src/Entities/RefreshTokenEntityInterface.php @@ -9,6 +9,8 @@ namespace League\OAuth2\Server\Entities; +use DateTimeImmutable; + interface RefreshTokenEntityInterface { /** @@ -28,16 +30,16 @@ interface RefreshTokenEntityInterface /** * Get the token's expiry date time. * - * @return \DateTime + * @return DateTimeImmutable */ - public function getExpiryDateTime(); + public function getExpiryDateTime(): DateTimeImmutable; /** * Set the date time when the token expires. * - * @param \DateTime $dateTime + * @param DateTimeImmutable $dateTime */ - public function setExpiryDateTime(\DateTime $dateTime); + public function setExpiryDateTime(DateTimeImmutable $dateTime); /** * Set the access token that the refresh token was associated with. diff --git a/src/Entities/TokenInterface.php b/src/Entities/TokenInterface.php index 378adbdc..a8d1496d 100644 --- a/src/Entities/TokenInterface.php +++ b/src/Entities/TokenInterface.php @@ -9,6 +9,8 @@ namespace League\OAuth2\Server\Entities; +use DateTimeImmutable; + interface TokenInterface { /** @@ -28,16 +30,16 @@ interface TokenInterface /** * Get the token's expiry date time. * - * @return \DateTime + * @return DateTimeImmutable */ - public function getExpiryDateTime(); + public function getExpiryDateTime(): DateTimeImmutable; /** * Set the date time when the token expires. * - * @param \DateTime $dateTime + * @param DateTimeImmutable $dateTime */ - public function setExpiryDateTime(\DateTime $dateTime); + public function setExpiryDateTime(DateTimeImmutable $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 501233e9..4fa7193a 100644 --- a/src/Entities/Traits/AccessTokenTrait.php +++ b/src/Entities/Traits/AccessTokenTrait.php @@ -9,6 +9,7 @@ namespace League\OAuth2\Server\Entities\Traits; +use DateTimeImmutable; use Lcobucci\JWT\Builder; use Lcobucci\JWT\Signer\Key; use Lcobucci\JWT\Signer\Rsa\Sha256; @@ -67,9 +68,9 @@ trait AccessTokenTrait abstract public function getClient(); /** - * @return \DateTime + * @return DateTimeImmutable */ - abstract public function getExpiryDateTime(); + abstract public function getExpiryDateTime(): DateTimeImmutable; /** * @return string|int diff --git a/src/Entities/Traits/RefreshTokenTrait.php b/src/Entities/Traits/RefreshTokenTrait.php index fb9dbc68..e79cfdaa 100644 --- a/src/Entities/Traits/RefreshTokenTrait.php +++ b/src/Entities/Traits/RefreshTokenTrait.php @@ -9,6 +9,7 @@ namespace League\OAuth2\Server\Entities\Traits; +use DateTimeImmutable; use League\OAuth2\Server\Entities\AccessTokenEntityInterface; trait RefreshTokenTrait @@ -19,7 +20,7 @@ trait RefreshTokenTrait protected $accessToken; /** - * @var \DateTime + * @var DateTimeImmutable */ protected $expiryDateTime; @@ -42,9 +43,9 @@ trait RefreshTokenTrait /** * Get the token's expiry date time. * - * @return \DateTime + * @return DateTimeImmutable */ - public function getExpiryDateTime() + public function getExpiryDateTime(): DateTimeImmutable { return $this->expiryDateTime; } @@ -52,9 +53,9 @@ trait RefreshTokenTrait /** * Set the date time when the token expires. * - * @param \DateTime $dateTime + * @param DateTimeImmutable $dateTime */ - public function setExpiryDateTime(\DateTime $dateTime) + public function setExpiryDateTime(DateTimeImmutable $dateTime) { $this->expiryDateTime = $dateTime; } diff --git a/src/Entities/Traits/TokenEntityTrait.php b/src/Entities/Traits/TokenEntityTrait.php index c6653cce..8ed2b63a 100644 --- a/src/Entities/Traits/TokenEntityTrait.php +++ b/src/Entities/Traits/TokenEntityTrait.php @@ -9,6 +9,7 @@ namespace League\OAuth2\Server\Entities\Traits; +use DateTimeImmutable; use League\OAuth2\Server\Entities\ClientEntityInterface; use League\OAuth2\Server\Entities\ScopeEntityInterface; @@ -20,7 +21,7 @@ trait TokenEntityTrait protected $scopes = []; /** - * @var \DateTime + * @var DateTimeImmutable */ protected $expiryDateTime; @@ -57,9 +58,9 @@ trait TokenEntityTrait /** * Get the token's expiry date time. * - * @return \DateTime + * @return DateTimeImmutable */ - public function getExpiryDateTime() + public function getExpiryDateTime(): DateTimeImmutable { return $this->expiryDateTime; } @@ -67,9 +68,9 @@ trait TokenEntityTrait /** * Set the date time when the token expires. * - * @param \DateTime $dateTime + * @param DateTimeImmutable $dateTime */ - public function setExpiryDateTime(\DateTime $dateTime) + public function setExpiryDateTime(DateTimeImmutable $dateTime) { $this->expiryDateTime = $dateTime; } diff --git a/src/Grant/AbstractGrant.php b/src/Grant/AbstractGrant.php index 4531a6a3..30f5448c 100644 --- a/src/Grant/AbstractGrant.php +++ b/src/Grant/AbstractGrant.php @@ -10,6 +10,8 @@ */ namespace League\OAuth2\Server\Grant; +use DateInterval; +use DateTimeImmutable; use League\Event\EmitterAwareTrait; use League\OAuth2\Server\CryptKey; use League\OAuth2\Server\CryptTrait; @@ -72,7 +74,7 @@ abstract class AbstractGrant implements GrantTypeInterface protected $userRepository; /** - * @var \DateInterval + * @var DateInterval */ protected $refreshTokenTTL; @@ -137,7 +139,7 @@ abstract class AbstractGrant implements GrantTypeInterface /** * {@inheritdoc} */ - public function setRefreshTokenTTL(\DateInterval $refreshTokenTTL) + public function setRefreshTokenTTL(DateInterval $refreshTokenTTL) { $this->refreshTokenTTL = $refreshTokenTTL; } @@ -352,7 +354,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 @@ -363,7 +365,7 @@ abstract class AbstractGrant implements GrantTypeInterface * @return AccessTokenEntityInterface */ protected function issueAccessToken( - \DateInterval $accessTokenTTL, + DateInterval $accessTokenTTL, ClientEntityInterface $client, $userIdentifier, array $scopes = [] @@ -371,7 +373,7 @@ abstract class AbstractGrant implements GrantTypeInterface $maxGenerationAttempts = self::MAX_RANDOM_TOKEN_GENERATION_ATTEMPTS; $accessToken = $this->accessTokenRepository->getNewToken($client, $scopes, $userIdentifier); - $accessToken->setExpiryDateTime((new \DateTime())->add($accessTokenTTL)); + $accessToken->setExpiryDateTime((new DateTimeImmutable())->add($accessTokenTTL)); $accessToken->setPrivateKey($this->privateKey); while ($maxGenerationAttempts-- > 0) { @@ -391,7 +393,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 @@ -403,7 +405,7 @@ abstract class AbstractGrant implements GrantTypeInterface * @return AuthCodeEntityInterface */ protected function issueAuthCode( - \DateInterval $authCodeTTL, + DateInterval $authCodeTTL, ClientEntityInterface $client, $userIdentifier, $redirectUri, @@ -412,7 +414,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 DateTimeImmutable())->add($authCodeTTL)); $authCode->setClient($client); $authCode->setUserIdentifier($userIdentifier); @@ -451,7 +453,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 DateTimeImmutable())->add($this->refreshTokenTTL)); $refreshToken->setAccessToken($accessToken); while ($maxGenerationAttempts-- > 0) { diff --git a/src/Grant/AuthCodeGrant.php b/src/Grant/AuthCodeGrant.php index 974f8373..9758744d 100644 --- a/src/Grant/AuthCodeGrant.php +++ b/src/Grant/AuthCodeGrant.php @@ -9,6 +9,8 @@ namespace League\OAuth2\Server\Grant; +use DateInterval; +use DateTimeImmutable; use League\OAuth2\Server\CodeChallengeVerifiers\CodeChallengeVerifierInterface; use League\OAuth2\Server\CodeChallengeVerifiers\PlainVerifier; use League\OAuth2\Server\CodeChallengeVerifiers\S256Verifier; @@ -27,7 +29,7 @@ use Psr\Http\Message\ServerRequestInterface; class AuthCodeGrant extends AbstractAuthorizeGrant { /** - * @var \DateInterval + * @var DateInterval */ private $authCodeTTL; @@ -44,17 +46,17 @@ class AuthCodeGrant extends AbstractAuthorizeGrant /** * @param AuthCodeRepositoryInterface $authCodeRepository * @param RefreshTokenRepositoryInterface $refreshTokenRepository - * @param \DateInterval $authCodeTTL + * @param DateInterval $authCodeTTL */ 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'); // SHOULD ONLY DO THIS IS SHA256 is supported $s256Verifier = new S256Verifier(); @@ -79,7 +81,7 @@ class AuthCodeGrant extends AbstractAuthorizeGrant * * @param ServerRequestInterface $request * @param ResponseTypeInterface $responseType - * @param \DateInterval $accessTokenTTL + * @param DateInterval $accessTokenTTL * * @throws OAuthServerException * @@ -88,7 +90,7 @@ class AuthCodeGrant extends AbstractAuthorizeGrant public function respondToAccessTokenRequest( ServerRequestInterface $request, ResponseTypeInterface $responseType, - \DateInterval $accessTokenTTL + DateInterval $accessTokenTTL ) { $clientId = $this->getRequestParameter('client_id', $request, null); @@ -354,7 +356,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 DateTimeImmutable())->add($this->authCodeTTL)->getTimestamp(), 'code_challenge' => $authorizationRequest->getCodeChallenge(), 'code_challenge_method' => $authorizationRequest->getCodeChallengeMethod(), ]; @@ -364,11 +366,7 @@ class AuthCodeGrant extends AbstractAuthorizeGrant $this->makeRedirectUri( $finalRedirectUri, [ - 'code' => $this->encrypt( - json_encode( - $payload - ) - ), + 'code' => $this->encrypt(json_encode($payload)), 'state' => $authorizationRequest->getState(), ] ) 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 6a71ab08..5fc08cf1 100644 --- a/src/Grant/ImplicitGrant.php +++ b/src/Grant/ImplicitGrant.php @@ -9,6 +9,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; @@ -22,7 +23,7 @@ use Psr\Http\Message\ServerRequestInterface; class ImplicitGrant extends AbstractAuthorizeGrant { /** - * @var \DateInterval + * @var DateInterval */ private $accessTokenTTL; @@ -32,21 +33,21 @@ 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 */ - public function setRefreshTokenTTL(\DateInterval $refreshTokenTTL) + public function setRefreshTokenTTL(DateInterval $refreshTokenTTL) { throw new \LogicException('The Implicit Grant does not return refresh tokens'); } @@ -84,14 +85,14 @@ 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'); } @@ -203,7 +204,7 @@ class ImplicitGrant extends AbstractAuthorizeGrant [ 'access_token' => (string) $accessToken, 'token_type' => 'Bearer', - 'expires_in' => $accessToken->getExpiryDateTime()->getTimestamp() - (new \DateTime())->getTimestamp(), + 'expires_in' => $accessToken->getExpiryDateTime()->getTimestamp() - \time(), '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..cde4beee 100644 --- a/src/Grant/RefreshTokenGrant.php +++ b/src/Grant/RefreshTokenGrant.php @@ -11,6 +11,7 @@ namespace League\OAuth2\Server\Grant; +use DateInterval; use League\OAuth2\Server\Exception\OAuthServerException; use League\OAuth2\Server\Repositories\RefreshTokenRepositoryInterface; use League\OAuth2\Server\RequestEvent; @@ -29,7 +30,7 @@ class RefreshTokenGrant extends AbstractGrant { $this->setRefreshTokenRepository($refreshTokenRepository); - $this->refreshTokenTTL = new \DateInterval('P1M'); + $this->refreshTokenTTL = new DateInterval('P1M'); } /** @@ -38,7 +39,7 @@ class RefreshTokenGrant extends AbstractGrant public function respondToAccessTokenRequest( ServerRequestInterface $request, ResponseTypeInterface $responseType, - \DateInterval $accessTokenTTL + DateInterval $accessTokenTTL ) { // Validate request $client = $this->validateClient($request); diff --git a/src/ResponseTypes/BearerTokenResponse.php b/src/ResponseTypes/BearerTokenResponse.php index 2e658215..ddcadd63 100644 --- a/src/ResponseTypes/BearerTokenResponse.php +++ b/src/ResponseTypes/BearerTokenResponse.php @@ -26,7 +26,7 @@ class BearerTokenResponse extends AbstractResponseType $responseParams = [ 'token_type' => 'Bearer', - 'expires_in' => $expireDateTime - (new \DateTime())->getTimestamp(), + 'expires_in' => $expireDateTime - \time(), 'access_token' => (string) $this->accessToken, ]; diff --git a/tests/AuthorizationServerTest.php b/tests/AuthorizationServerTest.php index 7e83ee5e..9fe1a020 100644 --- a/tests/AuthorizationServerTest.php +++ b/tests/AuthorizationServerTest.php @@ -2,6 +2,7 @@ namespace LeagueTests; +use DateInterval; use League\OAuth2\Server\AuthorizationServer; use League\OAuth2\Server\Exception\OAuthServerException; use League\OAuth2\Server\Grant\AuthCodeGrant; @@ -48,7 +49,7 @@ class AuthorizationServerTest extends TestCase new StubResponseType() ); - $server->enableGrantType(new ClientCredentialsGrant(), new \DateInterval('PT1M')); + $server->enableGrantType(new ClientCredentialsGrant(), new DateInterval('PT1M')); try { $server->respondToAccessTokenRequest(ServerRequestFactory::fromGlobals(), new Response); @@ -81,7 +82,7 @@ class AuthorizationServerTest extends TestCase ); $server->setDefaultScope(self::DEFAULT_SCOPE); - $server->enableGrantType(new ClientCredentialsGrant(), new \DateInterval('PT1M')); + $server->enableGrantType(new ClientCredentialsGrant(), new DateInterval('PT1M')); $_POST['grant_type'] = 'client_credentials'; $_POST['client_id'] = 'foo'; @@ -127,7 +128,7 @@ class AuthorizationServerTest extends TestCase $grant = new AuthCodeGrant( $authCodeRepository, $this->getMockBuilder(RefreshTokenRepositoryInterface::class)->getMock(), - new \DateInterval('PT10M') + new DateInterval('PT10M') ); $server->enableGrantType($grant); @@ -159,7 +160,7 @@ class AuthorizationServerTest extends TestCase $grant = new AuthCodeGrant( $this->getMockBuilder(AuthCodeRepositoryInterface::class)->getMock(), $this->getMockBuilder(RefreshTokenRepositoryInterface::class)->getMock(), - new \DateInterval('PT10M') + new DateInterval('PT10M') ); $grant->setClientRepository($clientRepositoryMock); @@ -200,7 +201,7 @@ class AuthorizationServerTest extends TestCase $grant = new AuthCodeGrant( $this->getMockBuilder(AuthCodeRepositoryInterface::class)->getMock(), $this->getMockBuilder(RefreshTokenRepositoryInterface::class)->getMock(), - new \DateInterval('PT10M') + new DateInterval('PT10M') ); $grant->setClientRepository($clientRepositoryMock); diff --git a/tests/Grant/AbstractGrantTest.php b/tests/Grant/AbstractGrantTest.php index d6ddd4b1..33103130 100644 --- a/tests/Grant/AbstractGrantTest.php +++ b/tests/Grant/AbstractGrantTest.php @@ -2,6 +2,7 @@ namespace LeagueTests\Grant; +use DateInterval; use League\OAuth2\Server\CryptKey; use League\OAuth2\Server\Entities\AccessTokenEntityInterface; use League\OAuth2\Server\Entities\AuthCodeEntityInterface; @@ -325,7 +326,7 @@ class AbstractGrantTest extends TestCase /** @var AbstractGrant $grantMock */ $grantMock = $this->getMockForAbstractClass(AbstractGrant::class); - $grantMock->setRefreshTokenTTL(new \DateInterval('PT1M')); + $grantMock->setRefreshTokenTTL(new DateInterval('PT1M')); $grantMock->setRefreshTokenRepository($refreshTokenRepoMock); $abstractGrantReflection = new \ReflectionClass($grantMock); @@ -356,7 +357,7 @@ class AbstractGrantTest extends TestCase /** @var AccessTokenEntityInterface $accessToken */ $accessToken = $issueAccessTokenMethod->invoke( $grantMock, - new \DateInterval('PT1H'), + new DateInterval('PT1H'), new ClientEntity(), 123, [new ScopeEntity()] @@ -381,7 +382,7 @@ class AbstractGrantTest extends TestCase AuthCodeEntityInterface::class, $issueAuthCodeMethod->invoke( $grantMock, - new \DateInterval('PT1H'), + new DateInterval('PT1H'), new ClientEntity(), 123, 'http://foo/bar', diff --git a/tests/Grant/AuthCodeGrantTest.php b/tests/Grant/AuthCodeGrantTest.php index 3ea7105a..ed702e8a 100644 --- a/tests/Grant/AuthCodeGrantTest.php +++ b/tests/Grant/AuthCodeGrantTest.php @@ -2,6 +2,7 @@ namespace LeagueTests\Grant; +use DateInterval; use League\OAuth2\Server\CryptKey; use League\OAuth2\Server\Entities\AccessTokenEntityInterface; use League\OAuth2\Server\Entities\RefreshTokenEntityInterface; @@ -49,7 +50,7 @@ class AuthCodeGrantTest extends TestCase $grant = new AuthCodeGrant( $this->getMockBuilder(AuthCodeRepositoryInterface::class)->getMock(), $this->getMockBuilder(RefreshTokenRepositoryInterface::class)->getMock(), - new \DateInterval('PT10M') + new DateInterval('PT10M') ); $this->assertEquals('authorization_code', $grant->getIdentifier()); @@ -60,7 +61,7 @@ class AuthCodeGrantTest extends TestCase $grant = new AuthCodeGrant( $this->getMockBuilder(AuthCodeRepositoryInterface::class)->getMock(), $this->getMockBuilder(RefreshTokenRepositoryInterface::class)->getMock(), - new \DateInterval('PT10M') + new DateInterval('PT10M') ); $request = new ServerRequest( @@ -96,7 +97,7 @@ class AuthCodeGrantTest extends TestCase $grant = new AuthCodeGrant( $this->getMockBuilder(AuthCodeRepositoryInterface::class)->getMock(), $this->getMockBuilder(RefreshTokenRepositoryInterface::class)->getMock(), - new \DateInterval('PT10M') + new DateInterval('PT10M') ); $grant->setClientRepository($clientRepositoryMock); $grant->setScopeRepository($scopeRepositoryMock); @@ -135,7 +136,7 @@ class AuthCodeGrantTest extends TestCase $grant = new AuthCodeGrant( $this->getMockBuilder(AuthCodeRepositoryInterface::class)->getMock(), $this->getMockBuilder(RefreshTokenRepositoryInterface::class)->getMock(), - new \DateInterval('PT10M') + new DateInterval('PT10M') ); $grant->setClientRepository($clientRepositoryMock); $grant->setScopeRepository($scopeRepositoryMock); @@ -173,7 +174,7 @@ class AuthCodeGrantTest extends TestCase $grant = new AuthCodeGrant( $this->getMockBuilder(AuthCodeRepositoryInterface::class)->getMock(), $this->getMockBuilder(RefreshTokenRepositoryInterface::class)->getMock(), - new \DateInterval('PT10M') + new DateInterval('PT10M') ); $grant->setClientRepository($clientRepositoryMock); @@ -212,7 +213,7 @@ class AuthCodeGrantTest extends TestCase $grant = new AuthCodeGrant( $this->getMockBuilder(AuthCodeRepositoryInterface::class)->getMock(), $this->getMockBuilder(RefreshTokenRepositoryInterface::class)->getMock(), - new \DateInterval('PT10M') + new DateInterval('PT10M') ); $grant->setClientRepository($clientRepositoryMock); @@ -249,7 +250,7 @@ class AuthCodeGrantTest extends TestCase $grant = new AuthCodeGrant( $this->getMockBuilder(AuthCodeRepositoryInterface::class)->getMock(), $this->getMockBuilder(RefreshTokenRepositoryInterface::class)->getMock(), - new \DateInterval('PT10M') + new DateInterval('PT10M') ); $grant->setClientRepository($clientRepositoryMock); @@ -286,7 +287,7 @@ class AuthCodeGrantTest extends TestCase $grant = new AuthCodeGrant( $this->getMockBuilder(AuthCodeRepositoryInterface::class)->getMock(), $this->getMockBuilder(RefreshTokenRepositoryInterface::class)->getMock(), - new \DateInterval('PT10M') + new DateInterval('PT10M') ); $grant->setClientRepository($clientRepositoryMock); @@ -321,7 +322,7 @@ class AuthCodeGrantTest extends TestCase $grant = new AuthCodeGrant( $this->getMockBuilder(AuthCodeRepositoryInterface::class)->getMock(), $this->getMockBuilder(RefreshTokenRepositoryInterface::class)->getMock(), - new \DateInterval('PT10M') + new DateInterval('PT10M') ); $grant->setClientRepository($clientRepositoryMock); @@ -353,7 +354,7 @@ class AuthCodeGrantTest extends TestCase $grant = new AuthCodeGrant( $this->getMockBuilder(AuthCodeRepositoryInterface::class)->getMock(), $this->getMockBuilder(RefreshTokenRepositoryInterface::class)->getMock(), - new \DateInterval('PT10M') + new DateInterval('PT10M') ); $grant->setClientRepository($clientRepositoryMock); @@ -388,7 +389,7 @@ class AuthCodeGrantTest extends TestCase $grant = new AuthCodeGrant( $this->getMockBuilder(AuthCodeRepositoryInterface::class)->getMock(), $this->getMockBuilder(RefreshTokenRepositoryInterface::class)->getMock(), - new \DateInterval('PT10M') + new DateInterval('PT10M') ); $grant->setClientRepository($clientRepositoryMock); @@ -424,7 +425,7 @@ class AuthCodeGrantTest extends TestCase $grant = new AuthCodeGrant( $this->getMockBuilder(AuthCodeRepositoryInterface::class)->getMock(), $this->getMockBuilder(RefreshTokenRepositoryInterface::class)->getMock(), - new \DateInterval('PT10M') + new DateInterval('PT10M') ); $grant->setClientRepository($clientRepositoryMock); @@ -464,7 +465,7 @@ class AuthCodeGrantTest extends TestCase $grant = new AuthCodeGrant( $this->getMockBuilder(AuthCodeRepositoryInterface::class)->getMock(), $this->getMockBuilder(RefreshTokenRepositoryInterface::class)->getMock(), - new \DateInterval('PT10M') + new DateInterval('PT10M') ); $grant->setClientRepository($clientRepositoryMock); @@ -505,7 +506,7 @@ class AuthCodeGrantTest extends TestCase $grant = new AuthCodeGrant( $authCodeRepository, $this->getMockBuilder(RefreshTokenRepositoryInterface::class)->getMock(), - new \DateInterval('PT10M') + new DateInterval('PT10M') ); $grant->setEncryptionKey($this->cryptStub->getKey()); @@ -530,7 +531,7 @@ class AuthCodeGrantTest extends TestCase $grant = new AuthCodeGrant( $authCodeRepository, $this->getMockBuilder(RefreshTokenRepositoryInterface::class)->getMock(), - new \DateInterval('PT10M') + new DateInterval('PT10M') ); $grant->setEncryptionKey($this->cryptStub->getKey()); @@ -562,7 +563,7 @@ class AuthCodeGrantTest extends TestCase $grant = new AuthCodeGrant( $this->getMockBuilder(AuthCodeRepositoryInterface::class)->getMock(), $this->getMockBuilder(RefreshTokenRepositoryInterface::class)->getMock(), - new \DateInterval('PT10M') + new DateInterval('PT10M') ); $grant->setClientRepository($clientRepositoryMock); $grant->setScopeRepository($scopeRepositoryMock); @@ -600,7 +601,7 @@ class AuthCodeGrantTest extends TestCase ); /** @var StubResponseType $response */ - $response = $grant->respondToAccessTokenRequest($request, new StubResponseType(), new \DateInterval('PT10M')); + $response = $grant->respondToAccessTokenRequest($request, new StubResponseType(), new DateInterval('PT10M')); $this->assertInstanceOf(AccessTokenEntityInterface::class, $response->getAccessToken()); $this->assertInstanceOf(RefreshTokenEntityInterface::class, $response->getRefreshToken()); @@ -630,7 +631,7 @@ class AuthCodeGrantTest extends TestCase $grant = new AuthCodeGrant( $this->getMockBuilder(AuthCodeRepositoryInterface::class)->getMock(), $this->getMockBuilder(RefreshTokenRepositoryInterface::class)->getMock(), - new \DateInterval('PT10M') + new DateInterval('PT10M') ); $grant->setClientRepository($clientRepositoryMock); $grant->setScopeRepository($scopeRepositoryMock); @@ -668,7 +669,7 @@ class AuthCodeGrantTest extends TestCase ); /** @var StubResponseType $response */ - $response = $grant->respondToAccessTokenRequest($request, new StubResponseType(), new \DateInterval('PT10M')); + $response = $grant->respondToAccessTokenRequest($request, new StubResponseType(), new DateInterval('PT10M')); $this->assertInstanceOf(AccessTokenEntityInterface::class, $response->getAccessToken()); $this->assertInstanceOf(RefreshTokenEntityInterface::class, $response->getRefreshToken()); @@ -699,7 +700,7 @@ class AuthCodeGrantTest extends TestCase $grant = new AuthCodeGrant( $this->getMockBuilder(AuthCodeRepositoryInterface::class)->getMock(), $this->getMockBuilder(RefreshTokenRepositoryInterface::class)->getMock(), - new \DateInterval('PT10M') + new DateInterval('PT10M') ); $grant->setClientRepository($clientRepositoryMock); @@ -741,7 +742,7 @@ class AuthCodeGrantTest extends TestCase ); /** @var StubResponseType $response */ - $response = $grant->respondToAccessTokenRequest($request, new StubResponseType(), new \DateInterval('PT10M')); + $response = $grant->respondToAccessTokenRequest($request, new StubResponseType(), new DateInterval('PT10M')); $this->assertInstanceOf(AccessTokenEntityInterface::class, $response->getAccessToken()); $this->assertInstanceOf(RefreshTokenEntityInterface::class, $response->getRefreshToken()); @@ -772,7 +773,7 @@ class AuthCodeGrantTest extends TestCase $grant = new AuthCodeGrant( $this->getMockBuilder(AuthCodeRepositoryInterface::class)->getMock(), $this->getMockBuilder(RefreshTokenRepositoryInterface::class)->getMock(), - new \DateInterval('PT10M') + new DateInterval('PT10M') ); $grant->setClientRepository($clientRepositoryMock); @@ -814,7 +815,7 @@ class AuthCodeGrantTest extends TestCase ); /** @var StubResponseType $response */ - $response = $grant->respondToAccessTokenRequest($request, new StubResponseType(), new \DateInterval('PT10M')); + $response = $grant->respondToAccessTokenRequest($request, new StubResponseType(), new DateInterval('PT10M')); $this->assertInstanceOf(AccessTokenEntityInterface::class, $response->getAccessToken()); $this->assertInstanceOf(RefreshTokenEntityInterface::class, $response->getRefreshToken()); @@ -835,7 +836,7 @@ class AuthCodeGrantTest extends TestCase $grant = new AuthCodeGrant( $this->getMockBuilder(AuthCodeRepositoryInterface::class)->getMock(), $this->getMockBuilder(RefreshTokenRepositoryInterface::class)->getMock(), - new \DateInterval('PT10M') + new DateInterval('PT10M') ); $grant->setClientRepository($clientRepositoryMock); $grant->setEncryptionKey($this->cryptStub->getKey()); @@ -865,7 +866,7 @@ class AuthCodeGrantTest extends TestCase ] ); - $grant->respondToAccessTokenRequest($request, new StubResponseType(), new \DateInterval('PT10M')); + $grant->respondToAccessTokenRequest($request, new StubResponseType(), new DateInterval('PT10M')); } /** @@ -883,7 +884,7 @@ class AuthCodeGrantTest extends TestCase $grant = new AuthCodeGrant( $this->getMockBuilder(AuthCodeRepositoryInterface::class)->getMock(), $this->getMockBuilder(RefreshTokenRepositoryInterface::class)->getMock(), - new \DateInterval('PT10M') + new DateInterval('PT10M') ); $grant->setClientRepository($clientRepositoryMock); $grant->setEncryptionKey($this->cryptStub->getKey()); @@ -914,7 +915,7 @@ class AuthCodeGrantTest extends TestCase ] ); - $grant->respondToAccessTokenRequest($request, new StubResponseType(), new \DateInterval('PT10M')); + $grant->respondToAccessTokenRequest($request, new StubResponseType(), new DateInterval('PT10M')); } /** @@ -935,7 +936,7 @@ class AuthCodeGrantTest extends TestCase $grant = new AuthCodeGrant( $this->getMockBuilder(AuthCodeRepositoryInterface::class)->getMock(), $this->getMockBuilder(RefreshTokenRepositoryInterface::class)->getMock(), - new \DateInterval('PT10M') + new DateInterval('PT10M') ); $grant->setClientRepository($clientRepositoryMock); $grant->setAccessTokenRepository($accessTokenRepositoryMock); @@ -960,7 +961,7 @@ class AuthCodeGrantTest extends TestCase ); /* @var StubResponseType $response */ - $grant->respondToAccessTokenRequest($request, new StubResponseType(), new \DateInterval('PT10M')); + $grant->respondToAccessTokenRequest($request, new StubResponseType(), new DateInterval('PT10M')); } public function testRespondToAccessTokenRequestExpiredCode() @@ -981,7 +982,7 @@ class AuthCodeGrantTest extends TestCase $grant = new AuthCodeGrant( $this->getMockBuilder(AuthCodeRepositoryInterface::class)->getMock(), $this->getMockBuilder(RefreshTokenRepositoryInterface::class)->getMock(), - new \DateInterval('PT10M') + new DateInterval('PT10M') ); $grant->setClientRepository($clientRepositoryMock); $grant->setAccessTokenRepository($accessTokenRepositoryMock); @@ -1018,7 +1019,7 @@ class AuthCodeGrantTest extends TestCase try { /* @var StubResponseType $response */ - $grant->respondToAccessTokenRequest($request, new StubResponseType(), new \DateInterval('PT10M')); + $grant->respondToAccessTokenRequest($request, new StubResponseType(), new DateInterval('PT10M')); } catch (OAuthServerException $e) { $this->assertEquals($e->getHint(), 'Authorization code has expired'); } @@ -1045,7 +1046,7 @@ class AuthCodeGrantTest extends TestCase $grant = new AuthCodeGrant( $authCodeRepositoryMock, $this->getMockBuilder(RefreshTokenRepositoryInterface::class)->getMock(), - new \DateInterval('PT10M') + new DateInterval('PT10M') ); $grant->setClientRepository($clientRepositoryMock); $grant->setAccessTokenRepository($accessTokenRepositoryMock); @@ -1082,7 +1083,7 @@ class AuthCodeGrantTest extends TestCase try { /* @var StubResponseType $response */ - $grant->respondToAccessTokenRequest($request, new StubResponseType(), new \DateInterval('PT10M')); + $grant->respondToAccessTokenRequest($request, new StubResponseType(), new DateInterval('PT10M')); } catch (OAuthServerException $e) { $this->assertEquals($e->getHint(), 'Authorization code has been revoked'); } @@ -1106,7 +1107,7 @@ class AuthCodeGrantTest extends TestCase $grant = new AuthCodeGrant( $this->getMockBuilder(AuthCodeRepositoryInterface::class)->getMock(), $this->getMockBuilder(RefreshTokenRepositoryInterface::class)->getMock(), - new \DateInterval('PT10M') + new DateInterval('PT10M') ); $grant->setClientRepository($clientRepositoryMock); $grant->setAccessTokenRepository($accessTokenRepositoryMock); @@ -1143,7 +1144,7 @@ class AuthCodeGrantTest extends TestCase try { /* @var StubResponseType $response */ - $grant->respondToAccessTokenRequest($request, new StubResponseType(), new \DateInterval('PT10M')); + $grant->respondToAccessTokenRequest($request, new StubResponseType(), new DateInterval('PT10M')); } catch (OAuthServerException $e) { $this->assertEquals($e->getHint(), 'Authorization code was not issued to this client'); } @@ -1167,7 +1168,7 @@ class AuthCodeGrantTest extends TestCase $grant = new AuthCodeGrant( $this->getMockBuilder(AuthCodeRepositoryInterface::class)->getMock(), $this->getMockBuilder(RefreshTokenRepositoryInterface::class)->getMock(), - new \DateInterval('PT10M') + new DateInterval('PT10M') ); $grant->setClientRepository($clientRepositoryMock); $grant->setAccessTokenRepository($accessTokenRepositoryMock); @@ -1193,7 +1194,7 @@ class AuthCodeGrantTest extends TestCase try { /* @var StubResponseType $response */ - $grant->respondToAccessTokenRequest($request, new StubResponseType(), new \DateInterval('PT10M')); + $grant->respondToAccessTokenRequest($request, new StubResponseType(), new DateInterval('PT10M')); } catch (OAuthServerException $e) { $this->assertEquals($e->getHint(), 'Cannot decrypt the authorization code'); } @@ -1224,7 +1225,7 @@ class AuthCodeGrantTest extends TestCase $grant = new AuthCodeGrant( $this->getMockBuilder(AuthCodeRepositoryInterface::class)->getMock(), $this->getMockBuilder(RefreshTokenRepositoryInterface::class)->getMock(), - new \DateInterval('PT10M') + new DateInterval('PT10M') ); $grant->setClientRepository($clientRepositoryMock); @@ -1266,7 +1267,7 @@ class AuthCodeGrantTest extends TestCase try { /* @var StubResponseType $response */ - $grant->respondToAccessTokenRequest($request, new StubResponseType(), new \DateInterval('PT10M')); + $grant->respondToAccessTokenRequest($request, new StubResponseType(), new DateInterval('PT10M')); } catch (OAuthServerException $e) { $this->assertEquals($e->getHint(), 'Failed to verify `code_verifier`.'); } @@ -1297,7 +1298,7 @@ class AuthCodeGrantTest extends TestCase $grant = new AuthCodeGrant( $this->getMockBuilder(AuthCodeRepositoryInterface::class)->getMock(), $this->getMockBuilder(RefreshTokenRepositoryInterface::class)->getMock(), - new \DateInterval('PT10M') + new DateInterval('PT10M') ); $grant->setClientRepository($clientRepositoryMock); @@ -1339,7 +1340,7 @@ class AuthCodeGrantTest extends TestCase try { /* @var StubResponseType $response */ - $grant->respondToAccessTokenRequest($request, new StubResponseType(), new \DateInterval('PT10M')); + $grant->respondToAccessTokenRequest($request, new StubResponseType(), new DateInterval('PT10M')); } catch (OAuthServerException $e) { $this->assertEquals($e->getHint(), 'Code Verifier must follow the specifications of RFC-7636.'); } @@ -1370,7 +1371,7 @@ class AuthCodeGrantTest extends TestCase $grant = new AuthCodeGrant( $this->getMockBuilder(AuthCodeRepositoryInterface::class)->getMock(), $this->getMockBuilder(RefreshTokenRepositoryInterface::class)->getMock(), - new \DateInterval('PT10M') + new DateInterval('PT10M') ); $grant->setClientRepository($clientRepositoryMock); @@ -1412,7 +1413,7 @@ class AuthCodeGrantTest extends TestCase try { /* @var StubResponseType $response */ - $grant->respondToAccessTokenRequest($request, new StubResponseType(), new \DateInterval('PT10M')); + $grant->respondToAccessTokenRequest($request, new StubResponseType(), new DateInterval('PT10M')); } catch (OAuthServerException $e) { $this->assertEquals($e->getHint(), 'Code Verifier must follow the specifications of RFC-7636.'); } @@ -1443,7 +1444,7 @@ class AuthCodeGrantTest extends TestCase $grant = new AuthCodeGrant( $this->getMockBuilder(AuthCodeRepositoryInterface::class)->getMock(), $this->getMockBuilder(RefreshTokenRepositoryInterface::class)->getMock(), - new \DateInterval('PT10M') + new DateInterval('PT10M') ); $grant->setClientRepository($clientRepositoryMock); @@ -1485,7 +1486,7 @@ class AuthCodeGrantTest extends TestCase try { /* @var StubResponseType $response */ - $grant->respondToAccessTokenRequest($request, new StubResponseType(), new \DateInterval('PT10M')); + $grant->respondToAccessTokenRequest($request, new StubResponseType(), new DateInterval('PT10M')); } catch (OAuthServerException $e) { $this->assertEquals($e->getHint(), 'Code Verifier must follow the specifications of RFC-7636.'); } @@ -1516,7 +1517,7 @@ class AuthCodeGrantTest extends TestCase $grant = new AuthCodeGrant( $this->getMockBuilder(AuthCodeRepositoryInterface::class)->getMock(), $this->getMockBuilder(RefreshTokenRepositoryInterface::class)->getMock(), - new \DateInterval('PT10M') + new DateInterval('PT10M') ); $grant->setClientRepository($clientRepositoryMock); @@ -1557,7 +1558,7 @@ class AuthCodeGrantTest extends TestCase try { /* @var StubResponseType $response */ - $grant->respondToAccessTokenRequest($request, new StubResponseType(), new \DateInterval('PT10M')); + $grant->respondToAccessTokenRequest($request, new StubResponseType(), new DateInterval('PT10M')); } catch (OAuthServerException $e) { $this->assertEquals($e->getHint(), 'Check the `code_verifier` parameter'); } @@ -1580,7 +1581,7 @@ class AuthCodeGrantTest extends TestCase $grant = new AuthCodeGrant( $authCodeRepository, $this->getMockBuilder(RefreshTokenRepositoryInterface::class)->getMock(), - new \DateInterval('PT10M') + new DateInterval('PT10M') ); $grant->setEncryptionKey($this->cryptStub->getKey()); $grant->setPrivateKey(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key')); @@ -1607,7 +1608,7 @@ class AuthCodeGrantTest extends TestCase $grant = new AuthCodeGrant( $authCodeRepository, $this->getMockBuilder(RefreshTokenRepositoryInterface::class)->getMock(), - new \DateInterval('PT10M') + new DateInterval('PT10M') ); $grant->setEncryptionKey($this->cryptStub->getKey()); @@ -1633,7 +1634,7 @@ class AuthCodeGrantTest extends TestCase $grant = new AuthCodeGrant( $authCodeRepository, $this->getMockBuilder(RefreshTokenRepositoryInterface::class)->getMock(), - new \DateInterval('PT10M') + new DateInterval('PT10M') ); $this->assertInstanceOf(RedirectResponse::class, $grant->completeAuthorizationRequest($authRequest)); @@ -1664,7 +1665,7 @@ class AuthCodeGrantTest extends TestCase $grant = new AuthCodeGrant( $this->getMockBuilder(AuthCodeRepositoryInterface::class)->getMock(), $this->getMockBuilder(RefreshTokenRepositoryInterface::class)->getMock(), - new \DateInterval('PT10M') + new DateInterval('PT10M') ); $grant->setClientRepository($clientRepositoryMock); $grant->setScopeRepository($scopeRepositoryMock); @@ -1702,7 +1703,7 @@ class AuthCodeGrantTest extends TestCase ); /** @var StubResponseType $response */ - $response = $grant->respondToAccessTokenRequest($request, new StubResponseType(), new \DateInterval('PT10M')); + $response = $grant->respondToAccessTokenRequest($request, new StubResponseType(), new DateInterval('PT10M')); $this->assertInstanceOf(AccessTokenEntityInterface::class, $response->getAccessToken()); $this->assertInstanceOf(RefreshTokenEntityInterface::class, $response->getRefreshToken()); @@ -1736,7 +1737,7 @@ class AuthCodeGrantTest extends TestCase $grant = new AuthCodeGrant( $this->getMockBuilder(AuthCodeRepositoryInterface::class)->getMock(), $this->getMockBuilder(RefreshTokenRepositoryInterface::class)->getMock(), - new \DateInterval('PT10M') + new DateInterval('PT10M') ); $grant->setClientRepository($clientRepositoryMock); $grant->setScopeRepository($scopeRepositoryMock); @@ -1774,7 +1775,7 @@ class AuthCodeGrantTest extends TestCase ); /** @var StubResponseType $response */ - $response = $grant->respondToAccessTokenRequest($request, new StubResponseType(), new \DateInterval('PT10M')); + $response = $grant->respondToAccessTokenRequest($request, new StubResponseType(), new DateInterval('PT10M')); $this->assertInstanceOf(AccessTokenEntityInterface::class, $response->getAccessToken()); $this->assertInstanceOf(RefreshTokenEntityInterface::class, $response->getRefreshToken()); @@ -1808,7 +1809,7 @@ class AuthCodeGrantTest extends TestCase $grant = new AuthCodeGrant( $this->getMockBuilder(AuthCodeRepositoryInterface::class)->getMock(), $this->getMockBuilder(RefreshTokenRepositoryInterface::class)->getMock(), - new \DateInterval('PT10M') + new DateInterval('PT10M') ); $grant->setClientRepository($clientRepositoryMock); $grant->setScopeRepository($scopeRepositoryMock); @@ -1846,7 +1847,7 @@ class AuthCodeGrantTest extends TestCase ); /** @var StubResponseType $response */ - $response = $grant->respondToAccessTokenRequest($request, new StubResponseType(), new \DateInterval('PT10M')); + $response = $grant->respondToAccessTokenRequest($request, new StubResponseType(), new DateInterval('PT10M')); $this->assertInstanceOf(AccessTokenEntityInterface::class, $response->getAccessToken()); $this->assertInstanceOf(RefreshTokenEntityInterface::class, $response->getRefreshToken()); @@ -1860,7 +1861,7 @@ class AuthCodeGrantTest extends TestCase $grant = new AuthCodeGrant( $this->getMockBuilder(AuthCodeRepositoryInterface::class)->getMock(), $this->getMockBuilder(RefreshTokenRepositoryInterface::class)->getMock(), - new \DateInterval('PT10M') + new DateInterval('PT10M') ); $grant->completeAuthorizationRequest(new AuthorizationRequest()); @@ -1881,7 +1882,7 @@ class AuthCodeGrantTest extends TestCase $grant = new AuthCodeGrant( $this->getMockBuilder(AuthCodeRepositoryInterface::class)->getMock(), $this->getMockBuilder(RefreshTokenRepositoryInterface::class)->getMock(), - new \DateInterval('PT10M') + new DateInterval('PT10M') ); $grant->setClientRepository($clientRepositoryMock); diff --git a/tests/Grant/ClientCredentialsGrantTest.php b/tests/Grant/ClientCredentialsGrantTest.php index dfd78b41..b02f1190 100644 --- a/tests/Grant/ClientCredentialsGrantTest.php +++ b/tests/Grant/ClientCredentialsGrantTest.php @@ -2,6 +2,7 @@ namespace LeagueTests\Grant; +use DateInterval; use League\OAuth2\Server\CryptKey; use League\OAuth2\Server\Entities\AccessTokenEntityInterface; use League\OAuth2\Server\Grant\ClientCredentialsGrant; @@ -56,7 +57,7 @@ class ClientCredentialsGrantTest extends TestCase ); $responseType = new StubResponseType(); - $grant->respondToAccessTokenRequest($serverRequest, $responseType, new \DateInterval('PT5M')); + $grant->respondToAccessTokenRequest($serverRequest, $responseType, new DateInterval('PT5M')); $this->assertInstanceOf(AccessTokenEntityInterface::class, $responseType->getAccessToken()); } diff --git a/tests/Grant/ImplicitGrantTest.php b/tests/Grant/ImplicitGrantTest.php index df7b6985..5e702e01 100644 --- a/tests/Grant/ImplicitGrantTest.php +++ b/tests/Grant/ImplicitGrantTest.php @@ -2,6 +2,7 @@ namespace LeagueTests\Grant; +use DateInterval; use League\OAuth2\Server\CryptKey; use League\OAuth2\Server\Exception\OAuthServerException; use League\OAuth2\Server\Exception\UniqueTokenIdentifierConstraintViolationException; @@ -37,13 +38,13 @@ class ImplicitGrantTest extends TestCase public function testGetIdentifier() { - $grant = new ImplicitGrant(new \DateInterval('PT10M')); + $grant = new ImplicitGrant(new DateInterval('PT10M')); $this->assertEquals('implicit', $grant->getIdentifier()); } public function testCanRespondToAccessTokenRequest() { - $grant = new ImplicitGrant(new \DateInterval('PT10M')); + $grant = new ImplicitGrant(new DateInterval('PT10M')); $this->assertFalse( $grant->canRespondToAccessTokenRequest(new ServerRequest()) @@ -55,17 +56,17 @@ class ImplicitGrantTest extends TestCase */ public function testRespondToAccessTokenRequest() { - $grant = new ImplicitGrant(new \DateInterval('PT10M')); + $grant = new ImplicitGrant(new DateInterval('PT10M')); $grant->respondToAccessTokenRequest( new ServerRequest(), new StubResponseType(), - new \DateInterval('PT10M') + new DateInterval('PT10M') ); } public function testCanRespondToAuthorizationRequest() { - $grant = new ImplicitGrant(new \DateInterval('PT10M')); + $grant = new ImplicitGrant(new DateInterval('PT10M')); $request = new ServerRequest( [], @@ -96,7 +97,7 @@ class ImplicitGrantTest extends TestCase $scopeRepositoryMock->method('getScopeEntityByIdentifier')->willReturn($scopeEntity); $scopeRepositoryMock->method('finalizeScopes')->willReturnArgument(0); - $grant = new ImplicitGrant(new \DateInterval('PT10M')); + $grant = new ImplicitGrant(new DateInterval('PT10M')); $grant->setClientRepository($clientRepositoryMock); $grant->setScopeRepository($scopeRepositoryMock); $grant->setDefaultScope(self::DEFAULT_SCOPE); @@ -131,7 +132,7 @@ class ImplicitGrantTest extends TestCase $scopeRepositoryMock->method('getScopeEntityByIdentifier')->willReturn($scopeEntity); $scopeRepositoryMock->method('finalizeScopes')->willReturnArgument(0); - $grant = new ImplicitGrant(new \DateInterval('PT10M')); + $grant = new ImplicitGrant(new DateInterval('PT10M')); $grant->setClientRepository($clientRepositoryMock); $grant->setScopeRepository($scopeRepositoryMock); $grant->setDefaultScope(self::DEFAULT_SCOPE); @@ -162,7 +163,7 @@ class ImplicitGrantTest extends TestCase { $clientRepositoryMock = $this->getMockBuilder(ClientRepositoryInterface::class)->getMock(); - $grant = new ImplicitGrant(new \DateInterval('PT10M')); + $grant = new ImplicitGrant(new DateInterval('PT10M')); $grant->setClientRepository($clientRepositoryMock); $request = new ServerRequest( @@ -190,7 +191,7 @@ class ImplicitGrantTest extends TestCase $clientRepositoryMock = $this->getMockBuilder(ClientRepositoryInterface::class)->getMock(); $clientRepositoryMock->method('getClientEntity')->willReturn(null); - $grant = new ImplicitGrant(new \DateInterval('PT10M')); + $grant = new ImplicitGrant(new DateInterval('PT10M')); $grant->setClientRepository($clientRepositoryMock); $request = new ServerRequest( @@ -221,7 +222,7 @@ class ImplicitGrantTest extends TestCase $clientRepositoryMock = $this->getMockBuilder(ClientRepositoryInterface::class)->getMock(); $clientRepositoryMock->method('getClientEntity')->willReturn($client); - $grant = new ImplicitGrant(new \DateInterval('PT10M')); + $grant = new ImplicitGrant(new DateInterval('PT10M')); $grant->setClientRepository($clientRepositoryMock); $request = new ServerRequest( @@ -253,7 +254,7 @@ class ImplicitGrantTest extends TestCase $clientRepositoryMock = $this->getMockBuilder(ClientRepositoryInterface::class)->getMock(); $clientRepositoryMock->method('getClientEntity')->willReturn($client); - $grant = new ImplicitGrant(new \DateInterval('PT10M')); + $grant = new ImplicitGrant(new DateInterval('PT10M')); $grant->setClientRepository($clientRepositoryMock); $request = new ServerRequest( @@ -292,7 +293,7 @@ class ImplicitGrantTest extends TestCase $accessTokenRepositoryMock->method('getNewToken')->willReturn($accessToken); $accessTokenRepositoryMock->method('persistNewAccessToken')->willReturnSelf(); - $grant = new ImplicitGrant(new \DateInterval('PT10M')); + $grant = new ImplicitGrant(new DateInterval('PT10M')); $grant->setPrivateKey(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key')); $grant->setAccessTokenRepository($accessTokenRepositoryMock); @@ -315,7 +316,7 @@ class ImplicitGrantTest extends TestCase $accessTokenRepositoryMock->method('getNewToken')->willReturn(new AccessTokenEntity()); $accessTokenRepositoryMock->method('persistNewAccessToken')->willReturnSelf(); - $grant = new ImplicitGrant(new \DateInterval('PT10M')); + $grant = new ImplicitGrant(new DateInterval('PT10M')); $grant->setPrivateKey(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key')); $grant->setAccessTokenRepository($accessTokenRepositoryMock); @@ -342,7 +343,7 @@ class ImplicitGrantTest extends TestCase $accessTokenRepositoryMock->expects($this->at(0))->method('persistNewAccessToken')->willThrowException(UniqueTokenIdentifierConstraintViolationException::create()); $accessTokenRepositoryMock->expects($this->at(1))->method('persistNewAccessToken')->willReturnSelf(); - $grant = new ImplicitGrant(new \DateInterval('PT10M')); + $grant = new ImplicitGrant(new DateInterval('PT10M')); $grant->setPrivateKey(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key')); $grant->setAccessTokenRepository($accessTokenRepositoryMock); @@ -366,7 +367,7 @@ class ImplicitGrantTest extends TestCase $accessTokenRepositoryMock->method('getNewToken')->willReturn(new AccessTokenEntity()); $accessTokenRepositoryMock->method('persistNewAccessToken')->willThrowException(OAuthServerException::serverError('something bad happened')); - $grant = new ImplicitGrant(new \DateInterval('PT10M')); + $grant = new ImplicitGrant(new DateInterval('PT10M')); $grant->setPrivateKey(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key')); $grant->setAccessTokenRepository($accessTokenRepositoryMock); @@ -390,7 +391,7 @@ class ImplicitGrantTest extends TestCase $accessTokenRepositoryMock->method('getNewToken')->willReturn(new AccessTokenEntity()); $accessTokenRepositoryMock->method('persistNewAccessToken')->willThrowException(UniqueTokenIdentifierConstraintViolationException::create()); - $grant = new ImplicitGrant(new \DateInterval('PT10M')); + $grant = new ImplicitGrant(new DateInterval('PT10M')); $grant->setPrivateKey(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key')); $grant->setAccessTokenRepository($accessTokenRepositoryMock); @@ -402,8 +403,8 @@ class ImplicitGrantTest extends TestCase */ public function testSetRefreshTokenTTL() { - $grant = new ImplicitGrant(new \DateInterval('PT10M')); - $grant->setRefreshTokenTTL(new \DateInterval('PT10M')); + $grant = new ImplicitGrant(new DateInterval('PT10M')); + $grant->setRefreshTokenTTL(new DateInterval('PT10M')); } /** @@ -411,7 +412,7 @@ class ImplicitGrantTest extends TestCase */ public function testSetRefreshTokenRepository() { - $grant = new ImplicitGrant(new \DateInterval('PT10M')); + $grant = new ImplicitGrant(new DateInterval('PT10M')); $refreshTokenRepositoryMock = $this->getMockBuilder(RefreshTokenRepositoryInterface::class)->getMock(); $grant->setRefreshTokenRepository($refreshTokenRepositoryMock); } @@ -421,7 +422,7 @@ class ImplicitGrantTest extends TestCase */ public function testCompleteAuthorizationRequestNoUser() { - $grant = new ImplicitGrant(new \DateInterval('PT10M')); + $grant = new ImplicitGrant(new DateInterval('PT10M')); $grant->completeAuthorizationRequest(new AuthorizationRequest()); } } diff --git a/tests/Grant/PasswordGrantTest.php b/tests/Grant/PasswordGrantTest.php index c90a83db..56a278df 100644 --- a/tests/Grant/PasswordGrantTest.php +++ b/tests/Grant/PasswordGrantTest.php @@ -2,6 +2,7 @@ namespace LeagueTests\Grant; +use DateInterval; use League\OAuth2\Server\CryptKey; use League\OAuth2\Server\Entities\AccessTokenEntityInterface; use League\OAuth2\Server\Entities\RefreshTokenEntityInterface; @@ -74,7 +75,7 @@ class PasswordGrantTest extends TestCase ); $responseType = new StubResponseType(); - $grant->respondToAccessTokenRequest($serverRequest, $responseType, new \DateInterval('PT5M')); + $grant->respondToAccessTokenRequest($serverRequest, $responseType, new DateInterval('PT5M')); $this->assertInstanceOf(AccessTokenEntityInterface::class, $responseType->getAccessToken()); $this->assertInstanceOf(RefreshTokenEntityInterface::class, $responseType->getRefreshToken()); @@ -108,7 +109,7 @@ class PasswordGrantTest extends TestCase ); $responseType = new StubResponseType(); - $grant->respondToAccessTokenRequest($serverRequest, $responseType, new \DateInterval('PT5M')); + $grant->respondToAccessTokenRequest($serverRequest, $responseType, new DateInterval('PT5M')); } /** @@ -140,7 +141,7 @@ class PasswordGrantTest extends TestCase ); $responseType = new StubResponseType(); - $grant->respondToAccessTokenRequest($serverRequest, $responseType, new \DateInterval('PT5M')); + $grant->respondToAccessTokenRequest($serverRequest, $responseType, new DateInterval('PT5M')); } /** @@ -174,6 +175,6 @@ class PasswordGrantTest extends TestCase ); $responseType = new StubResponseType(); - $grant->respondToAccessTokenRequest($serverRequest, $responseType, new \DateInterval('PT5M')); + $grant->respondToAccessTokenRequest($serverRequest, $responseType, new DateInterval('PT5M')); } } diff --git a/tests/Grant/RefreshTokenGrantTest.php b/tests/Grant/RefreshTokenGrantTest.php index 89598115..6d1cbdf2 100644 --- a/tests/Grant/RefreshTokenGrantTest.php +++ b/tests/Grant/RefreshTokenGrantTest.php @@ -2,6 +2,7 @@ namespace LeagueTests\Grant; +use DateInterval; use League\OAuth2\Server\CryptKey; use League\OAuth2\Server\Entities\AccessTokenEntityInterface; use League\OAuth2\Server\Entities\RefreshTokenEntityInterface; @@ -88,7 +89,7 @@ class RefreshTokenGrantTest extends TestCase ]); $responseType = new StubResponseType(); - $grant->respondToAccessTokenRequest($serverRequest, $responseType, new \DateInterval('PT5M')); + $grant->respondToAccessTokenRequest($serverRequest, $responseType, new DateInterval('PT5M')); $this->assertInstanceOf(AccessTokenEntityInterface::class, $responseType->getAccessToken()); $this->assertInstanceOf(RefreshTokenEntityInterface::class, $responseType->getRefreshToken()); @@ -145,7 +146,7 @@ class RefreshTokenGrantTest extends TestCase ); $responseType = new StubResponseType(); - $grant->respondToAccessTokenRequest($serverRequest, $responseType, new \DateInterval('PT5M')); + $grant->respondToAccessTokenRequest($serverRequest, $responseType, new DateInterval('PT5M')); $this->assertInstanceOf(AccessTokenEntityInterface::class, $responseType->getAccessToken()); $this->assertInstanceOf(RefreshTokenEntityInterface::class, $responseType->getRefreshToken()); @@ -204,7 +205,7 @@ class RefreshTokenGrantTest extends TestCase ); $responseType = new StubResponseType(); - $grant->respondToAccessTokenRequest($serverRequest, $responseType, new \DateInterval('PT5M')); + $grant->respondToAccessTokenRequest($serverRequest, $responseType, new DateInterval('PT5M')); } /** @@ -236,7 +237,7 @@ class RefreshTokenGrantTest extends TestCase ); $responseType = new StubResponseType(); - $grant->respondToAccessTokenRequest($serverRequest, $responseType, new \DateInterval('PT5M')); + $grant->respondToAccessTokenRequest($serverRequest, $responseType, new DateInterval('PT5M')); } /** @@ -271,7 +272,7 @@ class RefreshTokenGrantTest extends TestCase ); $responseType = new StubResponseType(); - $grant->respondToAccessTokenRequest($serverRequest, $responseType, new \DateInterval('PT5M')); + $grant->respondToAccessTokenRequest($serverRequest, $responseType, new DateInterval('PT5M')); } /** @@ -320,7 +321,7 @@ class RefreshTokenGrantTest extends TestCase ); $responseType = new StubResponseType(); - $grant->respondToAccessTokenRequest($serverRequest, $responseType, new \DateInterval('PT5M')); + $grant->respondToAccessTokenRequest($serverRequest, $responseType, new DateInterval('PT5M')); } /** @@ -366,7 +367,7 @@ class RefreshTokenGrantTest extends TestCase ); $responseType = new StubResponseType(); - $grant->respondToAccessTokenRequest($serverRequest, $responseType, new \DateInterval('PT5M')); + $grant->respondToAccessTokenRequest($serverRequest, $responseType, new DateInterval('PT5M')); } /** @@ -413,6 +414,6 @@ class RefreshTokenGrantTest extends TestCase ); $responseType = new StubResponseType(); - $grant->respondToAccessTokenRequest($serverRequest, $responseType, new \DateInterval('PT5M')); + $grant->respondToAccessTokenRequest($serverRequest, $responseType, new DateInterval('PT5M')); } } diff --git a/tests/Middleware/AuthorizationServerMiddlewareTest.php b/tests/Middleware/AuthorizationServerMiddlewareTest.php index dcfcfbd9..a7ef803d 100644 --- a/tests/Middleware/AuthorizationServerMiddlewareTest.php +++ b/tests/Middleware/AuthorizationServerMiddlewareTest.php @@ -2,6 +2,7 @@ namespace LeagueTests\Middleware; +use DateInterval; use League\OAuth2\Server\AuthorizationServer; use League\OAuth2\Server\Exception\OAuthServerException; use League\OAuth2\Server\Grant\ClientCredentialsGrant; @@ -77,7 +78,7 @@ class AuthorizationServerMiddlewareTest extends TestCase new StubResponseType() ); - $server->enableGrantType(new ClientCredentialsGrant(), new \DateInterval('PT1M')); + $server->enableGrantType(new ClientCredentialsGrant(), new DateInterval('PT1M')); $_POST['grant_type'] = 'client_credentials'; $_POST['client_id'] = 'foo'; diff --git a/tests/Middleware/ResourceServerMiddlewareTest.php b/tests/Middleware/ResourceServerMiddlewareTest.php index d1a96042..7210567b 100644 --- a/tests/Middleware/ResourceServerMiddlewareTest.php +++ b/tests/Middleware/ResourceServerMiddlewareTest.php @@ -2,6 +2,8 @@ namespace LeagueTests\Middleware; +use DateInterval; +use DateTimeImmutable; use League\OAuth2\Server\CryptKey; use League\OAuth2\Server\Middleware\ResourceServerMiddleware; use League\OAuth2\Server\Repositories\AccessTokenRepositoryInterface; @@ -27,7 +29,7 @@ class ResourceServerMiddlewareTest extends TestCase $accessToken = new AccessTokenEntity(); $accessToken->setIdentifier('test'); $accessToken->setUserIdentifier(123); - $accessToken->setExpiryDateTime((new \DateTime())->add(new \DateInterval('PT1H'))); + $accessToken->setExpiryDateTime((new DateTimeImmutable())->add(new DateInterval('PT1H'))); $accessToken->setClient($client); $accessToken->setPrivateKey(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key')); @@ -63,7 +65,7 @@ class ResourceServerMiddlewareTest extends TestCase $accessToken = new AccessTokenEntity(); $accessToken->setIdentifier('test'); $accessToken->setUserIdentifier(123); - $accessToken->setExpiryDateTime((new \DateTime())->sub(new \DateInterval('PT1H'))); + $accessToken->setExpiryDateTime((new DateTimeImmutable())->sub(new DateInterval('PT1H'))); $accessToken->setClient($client); $accessToken->setPrivateKey(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key')); diff --git a/tests/ResponseTypes/BearerResponseTypeTest.php b/tests/ResponseTypes/BearerResponseTypeTest.php index 2eb87238..5eddfdef 100644 --- a/tests/ResponseTypes/BearerResponseTypeTest.php +++ b/tests/ResponseTypes/BearerResponseTypeTest.php @@ -2,6 +2,8 @@ namespace LeagueTests\ResponseTypes; +use DateInterval; +use DateTimeImmutable; use League\OAuth2\Server\AuthorizationValidators\BearerTokenValidator; use League\OAuth2\Server\CryptKey; use League\OAuth2\Server\Exception\OAuthServerException; @@ -32,7 +34,7 @@ class BearerResponseTypeTest extends TestCase $accessToken = new AccessTokenEntity(); $accessToken->setIdentifier('abcdef'); - $accessToken->setExpiryDateTime((new \DateTime())->add(new \DateInterval('PT1H'))); + $accessToken->setExpiryDateTime((new DateTimeImmutable())->add(new DateInterval('PT1H'))); $accessToken->setClient($client); $accessToken->addScope($scope); $accessToken->setPrivateKey(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key')); @@ -40,7 +42,7 @@ class BearerResponseTypeTest extends TestCase $refreshToken = new RefreshTokenEntity(); $refreshToken->setIdentifier('abcdef'); $refreshToken->setAccessToken($accessToken); - $refreshToken->setExpiryDateTime((new \DateTime())->add(new \DateInterval('PT1H'))); + $refreshToken->setExpiryDateTime((new DateTimeImmutable())->add(new DateInterval('PT1H'))); $responseType->setAccessToken($accessToken); $responseType->setRefreshToken($refreshToken); @@ -75,7 +77,7 @@ class BearerResponseTypeTest extends TestCase $accessToken = new AccessTokenEntity(); $accessToken->setIdentifier('abcdef'); - $accessToken->setExpiryDateTime((new \DateTime())->add(new \DateInterval('PT1H'))); + $accessToken->setExpiryDateTime((new DateTimeImmutable())->add(new DateInterval('PT1H'))); $accessToken->setClient($client); $accessToken->addScope($scope); $accessToken->setPrivateKey(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key')); @@ -83,7 +85,7 @@ class BearerResponseTypeTest extends TestCase $refreshToken = new RefreshTokenEntity(); $refreshToken->setIdentifier('abcdef'); $refreshToken->setAccessToken($accessToken); - $refreshToken->setExpiryDateTime((new \DateTime())->add(new \DateInterval('PT1H'))); + $refreshToken->setExpiryDateTime((new DateTimeImmutable())->add(new DateInterval('PT1H'))); $responseType->setAccessToken($accessToken); $responseType->setRefreshToken($refreshToken); @@ -119,14 +121,14 @@ class BearerResponseTypeTest extends TestCase $accessToken = new AccessTokenEntity(); $accessToken->setIdentifier('abcdef'); $accessToken->setUserIdentifier(123); - $accessToken->setExpiryDateTime((new \DateTime())->add(new \DateInterval('PT1H'))); + $accessToken->setExpiryDateTime((new DateTimeImmutable())->add(new DateInterval('PT1H'))); $accessToken->setClient($client); $accessToken->setPrivateKey(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key')); $refreshToken = new RefreshTokenEntity(); $refreshToken->setIdentifier('abcdef'); $refreshToken->setAccessToken($accessToken); - $refreshToken->setExpiryDateTime((new \DateTime())->add(new \DateInterval('PT1H'))); + $refreshToken->setExpiryDateTime((new DateTimeImmutable())->add(new DateInterval('PT1H'))); $responseType->setAccessToken($accessToken); $responseType->setRefreshToken($refreshToken); @@ -165,14 +167,14 @@ class BearerResponseTypeTest extends TestCase $accessToken = new AccessTokenEntity(); $accessToken->setIdentifier('abcdef'); $accessToken->setUserIdentifier(123); - $accessToken->setExpiryDateTime((new \DateTime())->add(new \DateInterval('PT1H'))); + $accessToken->setExpiryDateTime((new DateTimeImmutable())->add(new DateInterval('PT1H'))); $accessToken->setClient($client); $accessToken->setPrivateKey(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key')); $refreshToken = new RefreshTokenEntity(); $refreshToken->setIdentifier('abcdef'); $refreshToken->setAccessToken($accessToken); - $refreshToken->setExpiryDateTime((new \DateTime())->add(new \DateInterval('PT1H'))); + $refreshToken->setExpiryDateTime((new DateTimeImmutable())->add(new DateInterval('PT1H'))); $responseType->setAccessToken($accessToken); $responseType->setRefreshToken($refreshToken); @@ -208,14 +210,14 @@ class BearerResponseTypeTest extends TestCase $accessToken = new AccessTokenEntity(); $accessToken->setIdentifier('abcdef'); $accessToken->setUserIdentifier(123); - $accessToken->setExpiryDateTime((new \DateTime())->add(new \DateInterval('PT1H'))); + $accessToken->setExpiryDateTime((new DateTimeImmutable())->add(new DateInterval('PT1H'))); $accessToken->setClient($client); $accessToken->setPrivateKey(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key')); $refreshToken = new RefreshTokenEntity(); $refreshToken->setIdentifier('abcdef'); $refreshToken->setAccessToken($accessToken); - $refreshToken->setExpiryDateTime((new \DateTime())->add(new \DateInterval('PT1H'))); + $refreshToken->setExpiryDateTime((new DateTimeImmutable())->add(new DateInterval('PT1H'))); $responseType->setAccessToken($accessToken); $responseType->setRefreshToken($refreshToken); From c2cd12e0b89b698285dafeb6a68367018827c60f Mon Sep 17 00:00:00 2001 From: sephster Date: Wed, 19 Dec 2018 12:54:26 +0000 Subject: [PATCH 2/3] Remove return types --- src/Entities/RefreshTokenEntityInterface.php | 2 +- src/Entities/TokenInterface.php | 2 +- src/Entities/Traits/AccessTokenTrait.php | 2 +- src/Entities/Traits/RefreshTokenTrait.php | 2 +- src/Entities/Traits/TokenEntityTrait.php | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Entities/RefreshTokenEntityInterface.php b/src/Entities/RefreshTokenEntityInterface.php index a197ce5e..551ad052 100644 --- a/src/Entities/RefreshTokenEntityInterface.php +++ b/src/Entities/RefreshTokenEntityInterface.php @@ -32,7 +32,7 @@ interface RefreshTokenEntityInterface * * @return DateTimeImmutable */ - public function getExpiryDateTime(): DateTimeImmutable; + public function getExpiryDateTime(); /** * Set the date time when the token expires. diff --git a/src/Entities/TokenInterface.php b/src/Entities/TokenInterface.php index a8d1496d..7b063e13 100644 --- a/src/Entities/TokenInterface.php +++ b/src/Entities/TokenInterface.php @@ -32,7 +32,7 @@ interface TokenInterface * * @return DateTimeImmutable */ - public function getExpiryDateTime(): DateTimeImmutable; + public function getExpiryDateTime(); /** * Set the date time when the token expires. diff --git a/src/Entities/Traits/AccessTokenTrait.php b/src/Entities/Traits/AccessTokenTrait.php index 4fa7193a..872e8c18 100644 --- a/src/Entities/Traits/AccessTokenTrait.php +++ b/src/Entities/Traits/AccessTokenTrait.php @@ -70,7 +70,7 @@ trait AccessTokenTrait /** * @return DateTimeImmutable */ - abstract public function getExpiryDateTime(): DateTimeImmutable; + abstract public function getExpiryDateTime(); /** * @return string|int diff --git a/src/Entities/Traits/RefreshTokenTrait.php b/src/Entities/Traits/RefreshTokenTrait.php index e79cfdaa..f0f15444 100644 --- a/src/Entities/Traits/RefreshTokenTrait.php +++ b/src/Entities/Traits/RefreshTokenTrait.php @@ -45,7 +45,7 @@ trait RefreshTokenTrait * * @return DateTimeImmutable */ - public function getExpiryDateTime(): DateTimeImmutable + public function getExpiryDateTime() { return $this->expiryDateTime; } diff --git a/src/Entities/Traits/TokenEntityTrait.php b/src/Entities/Traits/TokenEntityTrait.php index 8ed2b63a..5275c462 100644 --- a/src/Entities/Traits/TokenEntityTrait.php +++ b/src/Entities/Traits/TokenEntityTrait.php @@ -60,7 +60,7 @@ trait TokenEntityTrait * * @return DateTimeImmutable */ - public function getExpiryDateTime(): DateTimeImmutable + public function getExpiryDateTime() { return $this->expiryDateTime; } From 5ed8e59ef3fd9bf57e4d456be3957ef97d5f2469 Mon Sep 17 00:00:00 2001 From: sephster Date: Wed, 19 Dec 2018 12:58:11 +0000 Subject: [PATCH 3/3] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b8b6ecba..dfe3c16f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - `issueAccessToken()` in the Abstract Grant no longer sets access token client, user ID or scopes. These values should already have been set when calling `getNewToken()` (PR #919) - No longer need to enable PKCE with `enableCodeExchangeProof` flag. Any client sending a code challenge will initiate PKCE checks. (PR #938) - Function `getClientEntity()` no longer performs client validation (PR #938) +- Use `DateTimeImmutable()` instead of `DateTime()`, `time()` instead of `(new DateTime())->getTimeStamp()`, and `DateTime::getTimeStamp()` instead of `DateTime::format('U')` (PR #963) ### Removed - `enableCodeExchangeProof` flag (PR #938)