diff --git a/src/Entities/DeviceCodeEntityInterface.php b/src/Entities/DeviceCodeEntityInterface.php index 81834bca9..6969eca01 100644 --- a/src/Entities/DeviceCodeEntityInterface.php +++ b/src/Entities/DeviceCodeEntityInterface.php @@ -34,10 +34,6 @@ public function getInterval(): int; public function setInterval(int $interval): void; - public function getIntervalInAuthResponse(): bool; - - public function setIntervalInAuthResponse(bool $intervalInAuthResponse): void; - public function getUserApproved(): bool; public function setUserApproved(bool $userApproved): void; diff --git a/src/Entities/Traits/DeviceCodeTrait.php b/src/Entities/Traits/DeviceCodeTrait.php index 942c6a3ec..22af197bb 100644 --- a/src/Entities/Traits/DeviceCodeTrait.php +++ b/src/Entities/Traits/DeviceCodeTrait.php @@ -19,7 +19,6 @@ trait DeviceCodeTrait { private bool $userApproved = false; - private bool $intervalInAuthResponse = false; private bool $includeVerificationUriComplete = false; private int $interval = 5; private string $userCode; @@ -82,16 +81,6 @@ public function setInterval(int $interval): void $this->interval = $interval; } - public function getIntervalInAuthResponse(): bool - { - return $this->intervalInAuthResponse; - } - - public function setIntervalInAuthResponse(bool $intervalInAuthResponse): void - { - $this->intervalInAuthResponse = $intervalInAuthResponse; - } - public function getUserApproved(): bool { return $this->userApproved; diff --git a/src/Grant/DeviceCodeGrant.php b/src/Grant/DeviceCodeGrant.php index bb23c276a..d32afd421 100644 --- a/src/Grant/DeviceCodeGrant.php +++ b/src/Grant/DeviceCodeGrant.php @@ -108,6 +108,7 @@ public function respondToDeviceAuthorizationRequest(ServerRequestInterface $requ 'expire_time' => $deviceCode->getExpiryDateTime()->getTimestamp(), 'client_id' => $deviceCode->getClient()->getIdentifier(), 'scopes' => $deviceCode->getScopes(), + 'interval' => $deviceCode->getInterval(), ]; $response = new DeviceCodeResponse(); @@ -355,7 +356,7 @@ protected function generateUniqueUserCode(int $length = 8): string // @codeCoverageIgnoreEnd } - // TODO: Check interface + // TODO: Check interface public function setIntervalVisibility(bool $intervalVisibility): void { $this->intervalVisibility = $intervalVisibility; diff --git a/src/ResponseTypes/DeviceCodeResponse.php b/src/ResponseTypes/DeviceCodeResponse.php index dfb1c932e..1b0268b8d 100644 --- a/src/ResponseTypes/DeviceCodeResponse.php +++ b/src/ResponseTypes/DeviceCodeResponse.php @@ -26,6 +26,7 @@ class DeviceCodeResponse extends AbstractResponseType protected DeviceCodeEntityInterface $deviceCode; protected string $payload; private bool $includeVerificationUriComplete = false; + private const DEFAULT_INTERVAL = 5; /** * {@inheritdoc} @@ -40,12 +41,12 @@ public function generateHttpResponse(ResponseInterface $response): ResponseInter 'verification_uri' => $this->deviceCode->getVerificationUri(), 'expires_in' => $expireDateTime - time(), ]; - + if ($this->includeVerificationUriComplete === true) { $responseParams['verification_uri_complete'] = $this->deviceCode->getVerificationUriComplete(); } - if ($this->deviceCode->getIntervalInAuthResponse() === true) { + if ($this->deviceCode->getInterval() !== self::DEFAULT_INTERVAL) { $responseParams['interval'] = $this->deviceCode->getInterval(); } diff --git a/tests/Grant/DeviceCodeGrantTest.php b/tests/Grant/DeviceCodeGrantTest.php index 730336b9b..66d7d3024 100644 --- a/tests/Grant/DeviceCodeGrantTest.php +++ b/tests/Grant/DeviceCodeGrantTest.php @@ -36,6 +36,7 @@ class DeviceCodeGrantTest extends TestCase { private const DEFAULT_SCOPE = 'basic'; + private const INTERVAL_RATE = 10; protected CryptTraitStub $cryptStub; @@ -335,7 +336,6 @@ public function testDeviceAuthorizationResponse(): void $this::assertObjectHasProperty('user_code', $responseObject); $this::assertObjectHasProperty('verification_uri', $responseObject); $this::assertObjectHasProperty('expires_in', $responseObject); - // TODO: $this->assertObjectHasAttribute('interval', $responseObject); } public function testRespondToAccessTokenRequest(): void @@ -674,7 +674,7 @@ public function testIssueExpiredTokenError(): void $grant->respondToAccessTokenRequest($serverRequest, $responseType, new DateInterval('PT5M')); } - public function testIntervalVisibility(): void + public function testSettingDeviceCodeIntervalRate(): void { $client = new ClientEntity(); $client->setIdentifier('foo'); @@ -684,8 +684,6 @@ public function testIntervalVisibility(): void $deviceCode = new DeviceCodeEntity(); - $deviceCode->setIntervalInAuthResponse(true); - $deviceCodeRepository = $this->getMockBuilder(DeviceCodeRepositoryInterface::class)->getMock(); $deviceCodeRepository->method('getNewDeviceCode')->willReturn($deviceCode); @@ -698,13 +696,15 @@ public function testIntervalVisibility(): void $deviceCodeRepository, $this->getMockBuilder(RefreshTokenRepositoryInterface::class)->getMock(), new DateInterval('PT10M'), - "http://foo/bar" + "http://foo/bar", + self::INTERVAL_RATE ); $grant->setClientRepository($clientRepositoryMock); $grant->setDefaultScope(self::DEFAULT_SCOPE); $grant->setEncryptionKey($this->cryptStub->getKey()); $grant->setScopeRepository($scopeRepositoryMock); + $grant->setIntervalVisibility(true); $request = (new ServerRequest())->withParsedBody([ 'client_id' => 'foo', @@ -718,9 +718,8 @@ public function testIntervalVisibility(): void $deviceCode = json_decode((string) $deviceCodeResponse->getBody()); $this::assertObjectHasProperty('interval', $deviceCode); - $this::assertEquals(5, $deviceCode->interval); + $this::assertEquals(self::INTERVAL_RATE, $deviceCode->interval); } - public function testIssueAccessDeniedError(): void { $client = new ClientEntity();