Skip to content

Commit

Permalink
fix persistDeviceCode usage
Browse files Browse the repository at this point in the history
  • Loading branch information
hafezdivandari committed Sep 25, 2024
1 parent 1d82315 commit e95d664
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
22 changes: 22 additions & 0 deletions examples/src/Repositories/DeviceCodeRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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}
*/
Expand Down
4 changes: 2 additions & 2 deletions src/Grant/DeviceCodeGrant.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand All @@ -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())) {
Expand Down
10 changes: 10 additions & 0 deletions src/Repositories/DeviceCodeRepositoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down

0 comments on commit e95d664

Please sign in to comment.