Skip to content

Commit

Permalink
revert increasing interval on slow_down error
Browse files Browse the repository at this point in the history
  • Loading branch information
hafezdivandari committed Nov 14, 2024
1 parent a298c56 commit ca53def
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 26 deletions.
19 changes: 5 additions & 14 deletions src/Exception/OAuthServerException.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
class OAuthServerException extends Exception
{
/**
* @var array<string, string|int>
* @var array<string, string>
*/
private array $payload;

Expand All @@ -49,7 +49,7 @@ final public function __construct(string $message, int $code, private string $er
/**
* Returns the current payload.
*
* @return array<string, string|int>
* @return array<string, string>
*/
public function getPayload(): array
{
Expand All @@ -59,7 +59,7 @@ public function getPayload(): array
/**
* Updates the current payload.
*
* @param array<string, string|int> $payload
* @param array<string, string> $payload
*/
public function setPayload(array $payload): void
{
Expand Down Expand Up @@ -236,9 +236,9 @@ public static function authorizationPending(string $hint = '', ?Throwable $previ
*
* @return static
*/
public static function slowDown(string $hint = '', ?Throwable $previous = null, ?int $interval = null): static
public static function slowDown(string $hint = '', ?Throwable $previous = null): static
{
$exception = new static(
return new static(
'The authorization request is still pending and polling should ' .
'continue, but the interval MUST be increased ' .
'by 5 seconds for this and all subsequent requests.',
Expand All @@ -249,15 +249,6 @@ public static function slowDown(string $hint = '', ?Throwable $previous = null,
null,
$previous
);

if (!is_null($interval)) {
$exception->setPayload([
...$exception->getPayload(),
'interval' => $interval,
]);
}

return $exception;
}

/**
Expand Down
14 changes: 2 additions & 12 deletions src/Grant/DeviceCodeGrant.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,21 +145,11 @@ public function respondToAccessTokenRequest(

// If device code has no user associated, respond with pending or slow down
if (is_null($deviceCodeEntity->getUserIdentifier())) {
$shouldSlowDown = false;

if ($this->deviceCodePolledTooSoon($deviceCodeEntity) === true) {
$deviceCodeEntity->setInterval($deviceCodeEntity->getInterval() + 5);

$shouldSlowDown = true;
}

$deviceCodeEntity->setLastPolledAt(new DateTimeImmutable());
$this->deviceCodeRepository->persistDeviceCode($deviceCodeEntity);

if ($shouldSlowDown) {
throw OAuthServerException::slowDown(
interval: $this->intervalVisibility ? $deviceCodeEntity->getInterval() : null
);
if ($this->deviceCodePolledTooSoon($deviceCodeEntity) === true) {
throw OAuthServerException::slowDown();
}

throw OAuthServerException::authorizationPending();
Expand Down

0 comments on commit ca53def

Please sign in to comment.