From 7b626507bc968b06f71bb6b2418d05abf1527b6e Mon Sep 17 00:00:00 2001 From: Octol1ttle Date: Wed, 25 Dec 2024 20:48:38 +0500 Subject: [PATCH] fix: send refresh tokens to Device Code clients too (#41) --- .../OAuth2/Grants/DeviceCodeGrant.php | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/common/components/OAuth2/Grants/DeviceCodeGrant.php b/common/components/OAuth2/Grants/DeviceCodeGrant.php index 2c62a7c..b4d154e 100644 --- a/common/components/OAuth2/Grants/DeviceCodeGrant.php +++ b/common/components/OAuth2/Grants/DeviceCodeGrant.php @@ -3,9 +3,13 @@ declare(strict_types=1); namespace common\components\OAuth2\Grants; +use common\components\OAuth2\Events\RequestedRefreshToken; use common\components\OAuth2\Repositories\ExtendedDeviceCodeRepositoryInterface; +use common\components\OAuth2\Repositories\PublicScopeRepository; use common\components\OAuth2\ResponseTypes\EmptyResponse; use DateInterval; +use League\OAuth2\Server\Entities\AccessTokenEntityInterface; +use League\OAuth2\Server\Entities\ClientEntityInterface; use League\OAuth2\Server\Exception\OAuthServerException; use League\OAuth2\Server\Grant\DeviceCodeGrant as BaseDeviceCodeGrant; use League\OAuth2\Server\Repositories\RefreshTokenRepositoryInterface; @@ -85,4 +89,20 @@ final class DeviceCodeGrant extends BaseDeviceCodeGrant { return new EmptyResponse(); } + protected function issueAccessToken( + DateInterval $accessTokenTTL, + ClientEntityInterface $client, + ?string $userIdentifier, + array $scopes = [], + ): AccessTokenEntityInterface { + foreach ($scopes as $i => $scope) { + if ($scope->getIdentifier() === PublicScopeRepository::OFFLINE_ACCESS) { + unset($scopes[$i]); + $this->getEmitter()->emit(new RequestedRefreshToken('refresh_token_requested')); + } + } + + return parent::issueAccessToken($accessTokenTTL, $client, $userIdentifier, $scopes); + } + }