thephpleague / oauth2-server

A spec compliant, secure by default PHP OAuth 2.0 Server
https://oauth2.thephpleague.com
MIT License
6.49k stars 1.12k forks source link

The `scope` parameter has been mistakenly required on device access token request #1411

Open hafezdivandari opened 1 month ago

hafezdivandari commented 1 month ago

On device authorization flow, according to RFC8628, the "Device Access Token Request" should send these parameters:

As you can see there is no scope parameter, because the scope parameter had been sent on the first step "Device Authorization Request":

The scopes are requested by the client on the first request and should be persisted on the DB. When user enters the user code we display the client info and list of scopes to be approved by user. So the client shouldn't specify scopes on the last request, but the current implementation requires scopes on DeviceCodeGrant::respondToAccessTokenRequest() mistakenly:

https://github.com/thephpleague/oauth2-server/blob/2ed9e5f65045bebf9e99c33ef1558dcd6d0206b7/src/Grant/DeviceCodeGrant.php#L140-L141

I think you should get the scopes from $deviceCodeEntity instead, which was persisted on the DB.

-$scopes = $this->validateScopes($this->getRequestParameter('scope', $request, $this->defaultScope));
$deviceCodeEntity = $this->validateDeviceCode($request, $client);
+$scopes = $deviceCodeEntity->getScopes(); // no need to call `validateScope` because already done on `respondToDeviceAuthorizationRequest` before persisting to DB

Am I missing something?

hafezdivandari commented 1 month ago

@Sephster would you please take a look? it seems to be a bug.

Sephster commented 1 month ago

Does indeed look to be a bug. Thanks for spotting this. I'm tied up the next few days but will get to this early next week. Cheers @hafezdivandari