|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace League\OAuth2\Server\Middleware; |
|
4
|
|
|
|
|
5
|
|
|
use League\OAuth2\Server\Exception\OAuthServerException; |
|
6
|
|
|
use League\OAuth2\Server\Repositories\DeviceAuthorizationRequestRepository; |
|
7
|
|
|
use Psr\Http\Message\ResponseFactoryInterface; |
|
8
|
|
|
use Psr\Http\Message\ResponseInterface; |
|
9
|
|
|
use Psr\Http\Message\ServerRequestInterface; |
|
10
|
|
|
use Psr\Http\Server\MiddlewareInterface; |
|
|
|
|
|
|
11
|
|
|
use Psr\Http\Server\RequestHandlerInterface; |
|
|
|
|
|
|
12
|
|
|
|
|
13
|
|
|
class DeviceGrantMiddleware implements MiddlewareInterface |
|
14
|
|
|
{ |
|
15
|
|
|
private $deviceAuthorizationRequestRepository; |
|
16
|
|
|
private $responseFactory; |
|
17
|
|
|
|
|
18
|
|
|
public function __construct( |
|
19
|
|
|
DeviceAuthorizationRequestRepository $deviceAuthorizationRequestRepository, |
|
20
|
|
|
ResponseFactoryInterface $responseFactory |
|
21
|
|
|
) { |
|
22
|
|
|
$this->deviceAuthorizationRequestRepository = $deviceAuthorizationRequestRepository; |
|
23
|
|
|
$this->responseFactory = $responseFactory; |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface |
|
27
|
|
|
{ |
|
28
|
|
|
$queryParameters = $request->getQueryParams(); |
|
29
|
|
|
$deviceCode = $queryParameters['device_code']; |
|
30
|
|
|
|
|
31
|
|
|
// Get the last timestamp this client requested an access code |
|
32
|
|
|
$lastRequestTimeStamp = $this->deviceAuthorizationRequestRepository->getLast($deviceCode); |
|
33
|
|
|
|
|
34
|
|
|
// If the request is within the last 5 seconds, issue a slowdown notification |
|
35
|
|
|
if ($lastRequestTimeStamp + 5 > \time()) { |
|
36
|
|
|
return OAuthServerException::slowDown()->generateHttpResponse($this->responseFactory->createResponse()); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
return $handler->handle($request); |
|
40
|
|
|
} |
|
41
|
|
|
} |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths