Skip to content

Commit e76e647

Browse files
authored
Merge pull request #1412 from hafezdivandari/master-fix-scope
Fix scope on device code grant
2 parents 15fa18a + ee3d0b6 commit e76e647

File tree

4 files changed

+50
-126
lines changed

4 files changed

+50
-126
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
88
### Added
99
- Support for PHP 8.4 (PR #1454)
1010

11+
### Fixed
12+
- Fixed spec compliance issue where device access token request was mistakenly expecting to receive scopes in the request (PR #1412)
13+
1114
## [9.0.1] - released 2024-10-14
1215
### Fixed
1316
- Auto-generated event emitter is now persisted. Previously, a new emitter was generated every time (PR #1428)

examples/src/Repositories/DeviceCodeRepository.php

+9
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use League\OAuth2\Server\Repositories\DeviceCodeRepositoryInterface;
1818
use OAuth2ServerExamples\Entities\ClientEntity;
1919
use OAuth2ServerExamples\Entities\DeviceCodeEntity;
20+
use OAuth2ServerExamples\Entities\ScopeEntity;
2021

2122
class DeviceCodeRepository implements DeviceCodeRepositoryInterface
2223
{
@@ -49,6 +50,14 @@ public function getDeviceCodeEntityByDeviceCode($deviceCode): ?DeviceCodeEntityI
4950
$deviceCodeEntity->setIdentifier($deviceCode);
5051
$deviceCodeEntity->setExpiryDateTime(new DateTimeImmutable('now +1 hour'));
5152
$deviceCodeEntity->setClient($clientEntity);
53+
$deviceCodeEntity->setLastPolledAt(new DateTimeImmutable());
54+
55+
$scopes = [];
56+
foreach ($scopes as $scope) {
57+
$scopeEntity = new ScopeEntity();
58+
$scopeEntity->setIdentifier($scope);
59+
$deviceCodeEntity->addScope($scopeEntity);
60+
}
5261

5362
// The user identifier should be set when the user authenticates on the
5463
// OAuth server, along with whether they approved the request

src/Grant/DeviceCodeGrant.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,6 @@ public function respondToAccessTokenRequest(
137137
): ResponseTypeInterface {
138138
// Validate request
139139
$client = $this->validateClient($request);
140-
$scopes = $this->validateScopes($this->getRequestParameter('scope', $request, $this->defaultScope));
141140
$deviceCodeEntity = $this->validateDeviceCode($request, $client);
142141

143142
$deviceCodeEntity->setLastPolledAt(new DateTimeImmutable());
@@ -153,7 +152,7 @@ public function respondToAccessTokenRequest(
153152
}
154153

155154
// Finalize the requested scopes
156-
$finalizedScopes = $this->scopeRepository->finalizeScopes($scopes, $this->getIdentifier(), $client, $deviceCodeEntity->getUserIdentifier());
155+
$finalizedScopes = $this->scopeRepository->finalizeScopes($deviceCodeEntity->getScopes(), $this->getIdentifier(), $client, $deviceCodeEntity->getUserIdentifier());
157156

158157
// Issue and persist new access token
159158
$accessToken = $this->issueAccessToken($accessTokenTTL, $client, $deviceCodeEntity->getUserIdentifier(), $finalizedScopes);

0 commit comments

Comments
 (0)