Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix inconsistent persistDeviceCode usage #1446

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions examples/src/Repositories/DeviceCodeRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,27 @@ 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();

// 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