Skip to content

Commit 047ac01

Browse files
committed
Rename responses classes to add prefix OAuth in order to make distinction with Framework responses classes
1 parent 99ab85d commit 047ac01

File tree

11 files changed

+42
-33
lines changed

11 files changed

+42
-33
lines changed

src/AuthorizationServer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
use Platine\OAuth2\Exception\OAuth2Exception;
4343
use Platine\OAuth2\Grant\AuthorizationServerAwareInterface;
4444
use Platine\OAuth2\Grant\GrantInterface;
45-
use Platine\OAuth2\Response\JsonResponse;
45+
use Platine\OAuth2\Response\OAuthJsonResponse;
4646
use Platine\OAuth2\Service\AccessTokenService;
4747
use Platine\OAuth2\Service\ClientService;
4848
use Platine\OAuth2\Service\RefreshTokenService;
@@ -359,7 +359,7 @@ protected function createResponseFromException(OAuth2Exception $exception): Resp
359359
'type' => get_class($exception),
360360
]);
361361

362-
return new JsonResponse($data, 400);
362+
return new OAuthJsonResponse($data, 400);
363363
}
364364

365365
/**

src/Entity/BaseToken.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,16 @@ protected static function createNew(
230230
$token->owner = $owner;
231231
$token->client = $client;
232232
$token->scopes = $scopes ?? [];
233-
$token->expireAt = $ttl ? (new DateTime())->modify(sprintf('%+d seconds', $ttl)) : null;
233+
234+
$expireAt = null;
235+
if ($ttl > 0) {
236+
$res = (new DateTime())->modify(sprintf('%+d seconds', $ttl));
237+
if ($res !== false) {
238+
$expireAt = $res;
239+
}
240+
}
241+
242+
$token->expireAt = $expireAt;
234243

235244
return $token;
236245
}

src/Grant/AuthorizationGrant.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
use Platine\OAuth2\Entity\Client;
3939
use Platine\OAuth2\Entity\TokenOwnerInterface;
4040
use Platine\OAuth2\Exception\OAuth2Exception;
41-
use Platine\OAuth2\Response\RedirectResponse;
41+
use Platine\OAuth2\Response\OAuthRedirectResponse;
4242
use Platine\OAuth2\Service\AccessTokenService;
4343
use Platine\OAuth2\Service\AuthorizationCodeService;
4444
use Platine\OAuth2\Service\RefreshTokenService;
@@ -138,7 +138,7 @@ public function createAuthorizationResponse(
138138
'state' => $state,
139139
]));
140140

141-
return new RedirectResponse($redirectUri . '?' . $uri);
141+
return new OAuthRedirectResponse($redirectUri . '?' . $uri);
142142
}
143143

144144
/**

src/Grant/BaseGrant.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
use Platine\Http\ResponseInterface;
3636
use Platine\OAuth2\Entity\AccessToken;
3737
use Platine\OAuth2\Entity\RefreshToken;
38-
use Platine\OAuth2\Response\JsonResponse;
38+
use Platine\OAuth2\Response\OAuthJsonResponse;
3939

4040
/**
4141
* @class BaseGrant
@@ -89,6 +89,6 @@ protected function generateTokenResponse(
8989
$body['refresh_token'] = $refreshToken->getToken();
9090
}
9191

92-
return new JsonResponse(array_filter($body));
92+
return new OAuthJsonResponse(array_filter($body));
9393
}
9494
}

src/Middleware/ResourceServerMiddleware.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
use Platine\OAuth2\Entity\AccessToken;
4040
use Platine\OAuth2\Exception\InvalidAccessTokenException;
4141
use Platine\OAuth2\ResourceServerInterface;
42-
use Platine\OAuth2\Response\JsonResponse;
42+
use Platine\OAuth2\Response\OAuthJsonResponse;
4343

4444
/**
4545
* Middleware for a resource server
@@ -85,7 +85,7 @@ public function process(
8585
} catch (InvalidAccessTokenException $ex) {
8686
// If we're here, this means that there was an access token, but it's either expired
8787
// or invalid. If that's the case we must immediately return
88-
return new JsonResponse(
88+
return new OAuthJsonResponse(
8989
[
9090
'error' => $ex->getCode(),
9191
'error_description' => $ex->getMessage(),
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@
3636
use Platine\Stdlib\Helper\Json;
3737

3838
/**
39-
* @class JsonResponse
39+
* @class OAuthJsonResponse
4040
* @package Platine\OAuth2\Response
4141
*/
42-
class JsonResponse extends Response
42+
class OAuthJsonResponse extends Response
4343
{
4444
/**
4545
* Create new instance
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@
3535
use Platine\Http\Response;
3636

3737
/**
38-
* @class RedirectResponse
38+
* @class OAuthRedirectResponse
3939
* @package Platine\OAuth2\Response
4040
*/
41-
class RedirectResponse extends Response
41+
class OAuthRedirectResponse extends Response
4242
{
4343
/**
4444
* Create new instance

tests/Entity/AccessTokenTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,18 +62,18 @@ public function testCreateAccessTokenExpired()
6262

6363
$mock_bin2hex = true;
6464

65-
$o = AccessToken::createNewAccessToken(-100, $owner = null, $client = null, ['read']);
65+
$o = AccessToken::createNewAccessToken(-0, $owner = null, $client = null, ['read']);
6666
$this->assertInstanceOf(AccessToken::class, $o);
6767

68-
$this->assertInstanceOf(DateTimeInterface::class, $o->getExpireAt());
68+
$this->assertNull($o->getExpireAt());
6969
$this->assertNull($o->getOwner());
7070
$this->assertNull($o->getClient());
71-
$this->assertTrue($o->isExpired());
72-
$this->assertEquals(-100, $o->getExpiresIn());
71+
$this->assertFalse($o->isExpired());
72+
$this->assertEquals(0, $o->getExpiresIn());
7373
$this->assertEquals('token_bin2hex', $o->getToken());
7474
$this->assertCount(1, $o->getScopes());
7575
$this->assertTrue($o->matchScopes('read'));
76-
$this->assertFalse($o->isValid('read'));
76+
$this->assertTrue($o->isValid('read'));
7777
}
7878

7979
public function testHidrate()

tests/Entity/RefreshTokenTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,18 +62,18 @@ public function testCreateRefreshTokenExpired()
6262

6363
$mock_bin2hex = true;
6464

65-
$o = RefreshToken::createNewRefreshToken(-100, $owner = null, $client = null, ['read']);
65+
$o = RefreshToken::createNewRefreshToken(0, $owner = null, $client = null, ['read']);
6666
$this->assertInstanceOf(RefreshToken::class, $o);
6767

68-
$this->assertInstanceOf(DateTimeInterface::class, $o->getExpireAt());
68+
$this->assertNull($o->getExpireAt());
6969
$this->assertNull($o->getOwner());
7070
$this->assertNull($o->getClient());
71-
$this->assertTrue($o->isExpired());
72-
$this->assertEquals(-100, $o->getExpiresIn());
71+
$this->assertFalse($o->isExpired());
72+
$this->assertEquals(0, $o->getExpiresIn());
7373
$this->assertEquals('token_bin2hex', $o->getToken());
7474
$this->assertCount(1, $o->getScopes());
7575
$this->assertTrue($o->matchScopes('read'));
76-
$this->assertFalse($o->isValid('read'));
76+
$this->assertTrue($o->isValid('read'));
7777
}
7878

7979
public function testHidrate()
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,20 @@
55
namespace Platine\OAuth2\Test\Response;
66

77
use Platine\Dev\PlatineTestCase;
8-
use Platine\OAuth2\Response\JsonResponse;
8+
use Platine\OAuth2\Response\OAuthJsonResponse;
99

1010
/**
11-
* JsonResponse class tests
11+
* OAuthJsonResponse class tests
1212
*
1313
* @group core
1414
* @group oauth2
1515
*/
16-
class JsonResponseTest extends PlatineTestCase
16+
class OAuthJsonResponseTest extends PlatineTestCase
1717
{
1818
public function testCreateDefault()
1919
{
20-
$o = new JsonResponse(['foo' => 'bar']);
21-
$this->assertInstanceOf(JsonResponse::class, $o);
20+
$o = new OAuthJsonResponse(['foo' => 'bar']);
21+
$this->assertInstanceOf(OAuthJsonResponse::class, $o);
2222

2323
$this->assertEquals(200, $o->getStatusCode());
2424
$this->assertEquals('application/json', $o->getHeaderLine('content-type'));

0 commit comments

Comments
 (0)