|
28 | 28 | use League\OAuth2\Server\RequestEvent;
|
29 | 29 | use League\OAuth2\Server\ResponseTypes\DeviceCodeResponse;
|
30 | 30 | use League\OAuth2\Server\ResponseTypes\ResponseTypeInterface;
|
31 |
| -use LogicException; |
32 | 31 | use Psr\Http\Message\ServerRequestInterface;
|
33 | 32 | use TypeError;
|
34 | 33 |
|
@@ -97,7 +96,6 @@ public function respondToDeviceAuthorizationRequest(ServerRequestInterface $requ
|
97 | 96 | );
|
98 | 97 |
|
99 | 98 | $response = new DeviceCodeResponse();
|
100 |
| - $response->setEncryptionKey($this->encryptionKey); |
101 | 99 |
|
102 | 100 | if ($this->includeVerificationUriComplete === true) {
|
103 | 101 | $response->includeVerificationUriComplete();
|
@@ -179,58 +177,38 @@ public function respondToAccessTokenRequest(
|
179 | 177 | */
|
180 | 178 | protected function validateDeviceCode(ServerRequestInterface $request, ClientEntityInterface $client): DeviceCodeEntityInterface
|
181 | 179 | {
|
182 |
| - $encryptedDeviceCode = $this->getRequestParameter('device_code', $request); |
| 180 | + $deviceCode = $this->getRequestParameter('device_code', $request); |
183 | 181 |
|
184 |
| - if (is_null($encryptedDeviceCode)) { |
| 182 | + if (is_null($deviceCode)) { |
185 | 183 | throw OAuthServerException::invalidRequest('device_code');
|
186 | 184 | }
|
187 | 185 |
|
188 |
| - try { |
189 |
| - $deviceCodePayload = json_decode($this->decrypt($encryptedDeviceCode)); |
190 |
| - } catch (LogicException $e) { |
191 |
| - throw OAuthServerException::invalidRequest('code', 'Cannot decrypt the device code', $e); |
192 |
| - } |
| 186 | + $deviceCodeEntity = $this->deviceCodeRepository->getDeviceCodeEntityByDeviceCode( |
| 187 | + $deviceCode |
| 188 | + ); |
193 | 189 |
|
194 |
| - if (!property_exists($deviceCodePayload, 'device_code_id')) { |
195 |
| - throw OAuthServerException::invalidRequest('device_code', 'Device code malformed'); |
| 190 | + if ($deviceCodeEntity instanceof DeviceCodeEntityInterface === false) { |
| 191 | + $this->getEmitter()->emit(new RequestEvent(RequestEvent::USER_AUTHENTICATION_FAILED, $request)); |
| 192 | + |
| 193 | + throw OAuthServerException::invalidGrant(); |
196 | 194 | }
|
197 | 195 |
|
198 |
| - if (time() > $deviceCodePayload->expire_time) { |
| 196 | + if (time() > $deviceCodeEntity->getExpiryDateTime()->getTimestamp()) { |
199 | 197 | throw OAuthServerException::expiredToken('device_code');
|
200 | 198 | }
|
201 | 199 |
|
202 |
| - if ($this->deviceCodeRepository->isDeviceCodeRevoked($deviceCodePayload->device_code_id) === true) { |
| 200 | + if ($this->deviceCodeRepository->isDeviceCodeRevoked($deviceCode) === true) { |
203 | 201 | throw OAuthServerException::invalidRequest('device_code', 'Device code has been revoked');
|
204 | 202 | }
|
205 | 203 |
|
206 |
| - if ($deviceCodePayload->client_id !== $client->getIdentifier()) { |
| 204 | + if ($deviceCodeEntity->getClient()->getIdentifier() !== $client->getIdentifier()) { |
207 | 205 | throw OAuthServerException::invalidRequest('device_code', 'Device code was not issued to this client');
|
208 | 206 | }
|
209 | 207 |
|
210 |
| - $deviceCodeEntity = $this->deviceCodeRepository->getDeviceCodeEntityByDeviceCode( |
211 |
| - $deviceCodePayload->device_code_id |
212 |
| - ); |
213 |
| - |
214 |
| - if ($deviceCodeEntity instanceof DeviceCodeEntityInterface === false) { |
215 |
| - $this->getEmitter()->emit(new RequestEvent(RequestEvent::USER_AUTHENTICATION_FAILED, $request)); |
216 |
| - |
217 |
| - throw OAuthServerException::invalidGrant(); |
218 |
| - } |
219 |
| - |
220 | 208 | if ($this->deviceCodePolledTooSoon($deviceCodeEntity->getLastPolledAt()) === true) {
|
221 | 209 | throw OAuthServerException::slowDown();
|
222 | 210 | }
|
223 | 211 |
|
224 |
| - $deviceCodeEntity->setIdentifier($deviceCodePayload->device_code_id); |
225 |
| - $deviceCodeEntity->setClient($client); |
226 |
| - $deviceCodeEntity->setExpiryDateTime((new DateTimeImmutable())->setTimestamp($deviceCodePayload->expire_time)); |
227 |
| - |
228 |
| - $scopes = $this->validateScopes($deviceCodePayload->scopes); |
229 |
| - |
230 |
| - foreach ($scopes as $scope) { |
231 |
| - $deviceCodeEntity->addScope($scope); |
232 |
| - } |
233 |
| - |
234 | 212 | return $deviceCodeEntity;
|
235 | 213 | }
|
236 | 214 |
|
|
0 commit comments