From 7c2c8d0e06cee8fd7505ad5dbe6c255cb581ddcc Mon Sep 17 00:00:00 2001 From: Hafez Divandari Date: Mon, 28 Oct 2024 04:50:04 +0330 Subject: [PATCH] include interval on authorization_pending and slow_down error responses --- src/Exception/OAuthServerException.php | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/src/Exception/OAuthServerException.php b/src/Exception/OAuthServerException.php index 24a38d3fe..6953575eb 100644 --- a/src/Exception/OAuthServerException.php +++ b/src/Exception/OAuthServerException.php @@ -215,9 +215,9 @@ public static function expiredToken(?string $hint = null, ?Throwable $previous = return new static($errorMessage, 11, 'expired_token', 400, $hint, null, $previous); } - public static function authorizationPending(string $hint = '', ?Throwable $previous = null): static + public static function authorizationPending(?int $interval = null, string $hint = '', ?Throwable $previous = null): static { - return new static( + $exception = new static( 'The authorization request is still pending as the end user ' . 'hasn\'t yet completed the user interaction steps. The client ' . 'SHOULD repeat the Access Token Request to the token endpoint', @@ -228,6 +228,15 @@ public static function authorizationPending(string $hint = '', ?Throwable $previ null, $previous ); + + if (!is_null($interval)) { + $exception->setPayload([ + ...$exception->getPayload(), + 'interval' => $interval, + ]); + } + + return $exception; } /** @@ -236,9 +245,9 @@ public static function authorizationPending(string $hint = '', ?Throwable $previ * * @return static */ - public static function slowDown(string $hint = '', ?Throwable $previous = null): static + public static function slowDown(?int $interval = null, string $hint = '', ?Throwable $previous = null): static { - return new static( + $exception = 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.', @@ -249,6 +258,15 @@ public static function slowDown(string $hint = '', ?Throwable $previous = null): null, $previous ); + + if (!is_null($interval)) { + $exception->setPayload([ + ...$exception->getPayload(), + 'interval' => $interval, + ]); + } + + return $exception; } /**