From e95d6647ffcf480e29c13de2f7d7f139e814c4b0 Mon Sep 17 00:00:00 2001 From: Hafez Divandari Date: Wed, 25 Sep 2024 22:03:17 +0330 Subject: [PATCH 1/2] fix `persistDeviceCode` usage --- .../src/Repositories/DeviceCodeRepository.php | 22 +++++++++++++++++++ src/Grant/DeviceCodeGrant.php | 4 ++-- .../DeviceCodeRepositoryInterface.php | 10 +++++++++ 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/examples/src/Repositories/DeviceCodeRepository.php b/examples/src/Repositories/DeviceCodeRepository.php index 9495c9a15..e57d275a3 100644 --- a/examples/src/Repositories/DeviceCodeRepository.php +++ b/examples/src/Repositories/DeviceCodeRepository.php @@ -36,6 +36,28 @@ public function persistDeviceCode(DeviceCodeEntityInterface $deviceCodeEntity): // Some logic to persist a new device code to a database } + /** + * {@inheritdoc} + */ + public function persistUser(DeviceCodeEntityInterface $deviceCodeEntity): void + { + $user = $deviceCodeEntity->getUserIdentifier(); + $approved = $deviceCodeEntity->getUserApproved(); + + // Some logic to persist user ID and approval status of the given device code entity to a database + } + + /** + * {@inheritdoc} + */ + public function persistLastPolledAt(DeviceCodeEntityInterface $deviceCodeEntity): void + { + $lastPolledAt = $deviceCodeEntity->getLastPolledAt(); + $approved = $deviceCodeEntity->getUserApproved(); + + // Some logic to persist "last polled at" datetime of the given device code entity to a database + } + /** * {@inheritdoc} */ diff --git a/src/Grant/DeviceCodeGrant.php b/src/Grant/DeviceCodeGrant.php index 3804e2027..84744c093 100644 --- a/src/Grant/DeviceCodeGrant.php +++ b/src/Grant/DeviceCodeGrant.php @@ -124,7 +124,7 @@ public function completeDeviceAuthorizationRequest(string $deviceCode, string $u $deviceCode->setUserIdentifier($userId); $deviceCode->setUserApproved($userApproved); - $this->deviceCodeRepository->persistDeviceCode($deviceCode); + $this->deviceCodeRepository->persistUser($deviceCode); } /** @@ -141,7 +141,7 @@ public function respondToAccessTokenRequest( $deviceCodeEntity = $this->validateDeviceCode($request, $client); $deviceCodeEntity->setLastPolledAt(new DateTimeImmutable()); - $this->deviceCodeRepository->persistDeviceCode($deviceCodeEntity); + $this->deviceCodeRepository->persistLastPolledAt($deviceCodeEntity); // If device code has no user associated, respond with pending if (is_null($deviceCodeEntity->getUserIdentifier())) { diff --git a/src/Repositories/DeviceCodeRepositoryInterface.php b/src/Repositories/DeviceCodeRepositoryInterface.php index 09575ab18..302404b73 100644 --- a/src/Repositories/DeviceCodeRepositoryInterface.php +++ b/src/Repositories/DeviceCodeRepositoryInterface.php @@ -29,6 +29,16 @@ public function getNewDeviceCode(): DeviceCodeEntityInterface; */ public function persistDeviceCode(DeviceCodeEntityInterface $deviceCodeEntity): void; + /** + * Persists user ID and approval status of the given device code entity to permanent storage. + */ + public function persistUser(DeviceCodeEntityInterface $deviceCodeEntity): void; + + /** + * Persists "last polled at" datetime of the given device code entity to permanent storage. + */ + public function persistLastPolledAt(DeviceCodeEntityInterface $deviceCodeEntity): void; + /** * Get a device code entity. */ From bd3d7e452332580736eacbb0afdea114f4311ed6 Mon Sep 17 00:00:00 2001 From: Hafez Divandari Date: Thu, 26 Sep 2024 00:02:57 +0330 Subject: [PATCH 2/2] formatting --- examples/src/Repositories/DeviceCodeRepository.php | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/src/Repositories/DeviceCodeRepository.php b/examples/src/Repositories/DeviceCodeRepository.php index e57d275a3..169e6ba6c 100644 --- a/examples/src/Repositories/DeviceCodeRepository.php +++ b/examples/src/Repositories/DeviceCodeRepository.php @@ -53,7 +53,6 @@ public function persistUser(DeviceCodeEntityInterface $deviceCodeEntity): void public function persistLastPolledAt(DeviceCodeEntityInterface $deviceCodeEntity): void { $lastPolledAt = $deviceCodeEntity->getLastPolledAt(); - $approved = $deviceCodeEntity->getUserApproved(); // Some logic to persist "last polled at" datetime of the given device code entity to a database }