Remove refresh_token from OAuth2 result. Return the same access_token as a refresh_token in case when it's requested. Make access_tokens to live forever.

This commit is contained in:
ErickSkrauch
2019-12-09 19:31:54 +03:00
parent efb97a2006
commit ba7fad84a0
23 changed files with 231 additions and 297 deletions

View File

@@ -5,7 +5,6 @@ namespace api\tests\unit\components\OAuth2\Entities;
use api\components\OAuth2\Entities\AccessTokenEntity;
use api\tests\unit\TestCase;
use DateInterval;
use DateTimeImmutable;
use League\OAuth2\Server\Entities\ClientEntityInterface;
use League\OAuth2\Server\Entities\ScopeEntityInterface;
@@ -22,35 +21,10 @@ class AccessTokenEntityTest extends TestCase {
$entity->setExpiryDateTime(new DateTimeImmutable());
$entity->addScope($this->createScopeEntity('first'));
$entity->addScope($this->createScopeEntity('second'));
$entity->addScope($this->createScopeEntity('offline_access'));
$token = (string)$entity;
$payloads = json_decode(base64_decode(explode('.', $token)[1]), true);
$this->assertStringNotContainsString('offline_access', $payloads['ely-scopes']);
$scopes = $entity->getScopes();
$this->assertCount(3, $scopes);
$this->assertSame('first', $scopes[0]->getIdentifier());
$this->assertSame('second', $scopes[1]->getIdentifier());
$this->assertSame('offline_access', $scopes[2]->getIdentifier());
}
public function testGetExpiryDateTime() {
$initialExpiry = (new DateTimeImmutable())->add(new DateInterval('P1D'));
$entity = new AccessTokenEntity();
$entity->setExpiryDateTime($initialExpiry);
$this->assertSame($initialExpiry, $entity->getExpiryDateTime());
$entity = new AccessTokenEntity();
$entity->setExpiryDateTime($initialExpiry);
$entity->addScope($this->createScopeEntity('change_skin'));
$this->assertEqualsWithDelta(time() + 60 * 60, $entity->getExpiryDateTime()->getTimestamp(), 5);
$entity = new AccessTokenEntity();
$entity->setExpiryDateTime($initialExpiry);
$entity->addScope($this->createScopeEntity('obtain_account_email'));
$this->assertEqualsWithDelta(time() + 60 * 60, $entity->getExpiryDateTime()->getTimestamp(), 5);
$this->assertSame('first,second', $payloads['ely-scopes']);
}
private function createScopeEntity(string $id): ScopeEntityInterface {