|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Acme\App\Presentation\Api\Rest\Oauth; |
|
6
|
|
|
|
|
7
|
|
|
use DateInterval; |
|
8
|
|
|
use Exception; |
|
9
|
|
|
use League\OAuth2\Server\AuthorizationServer; |
|
10
|
|
|
use League\OAuth2\Server\Exception\OAuthServerException; |
|
11
|
|
|
use League\OAuth2\Server\Grant\PasswordGrant; |
|
12
|
|
|
use Psr\Http\Message\ResponseInterface; |
|
13
|
|
|
use Psr\Http\Message\ServerRequestInterface; |
|
14
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
15
|
|
|
use Throwable; |
|
16
|
|
|
use Zend\Diactoros\Response as Psr7Response; |
|
17
|
|
|
|
|
18
|
|
|
final class AccessTokenController |
|
19
|
|
|
{ |
|
20
|
|
|
/** |
|
21
|
|
|
* @var AuthorizationServer |
|
22
|
|
|
*/ |
|
23
|
|
|
private $authorizationServer; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @var PasswordGrant |
|
27
|
|
|
*/ |
|
28
|
|
|
private $passwordGrant; |
|
29
|
|
|
|
|
30
|
|
|
public function __construct(AuthorizationServer $authorizationServer, PasswordGrant $passwordGrant) |
|
31
|
|
|
{ |
|
32
|
|
|
$this->authorizationServer = $authorizationServer; |
|
33
|
|
|
$this->passwordGrant = $passwordGrant; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @throws Exception |
|
38
|
|
|
*/ |
|
39
|
|
|
public function post(ServerRequestInterface $request): ?ResponseInterface |
|
40
|
|
|
{ |
|
41
|
|
|
try { |
|
42
|
|
|
$this->passwordGrant->setRefreshTokenTTL(new DateInterval('P1M')); |
|
43
|
|
|
$this->authorizationServer->enableGrantType($this->passwordGrant, new DateInterval('PT1H')); |
|
44
|
|
|
|
|
45
|
|
|
return $this->authorizationServer->respondToAccessTokenRequest($request, new Psr7Response()); |
|
46
|
|
|
} catch (OAuthServerException $e) { |
|
|
|
|
|
|
47
|
|
|
return $this->convertResponse($e->generateHttpResponse(new Psr7Response())); |
|
48
|
|
|
} catch (Throwable $e) { |
|
49
|
|
|
return new Psr7Response($e->getMessage(), Response::HTTP_INTERNAL_SERVER_ERROR); |
|
50
|
|
|
} |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
private function convertResponse(ResponseInterface $psrResponse): ResponseInterface |
|
54
|
|
|
{ |
|
55
|
|
|
return new Psr7Response($psrResponse->getBody(), $psrResponse->getStatusCode(), $psrResponse->getHeaders()); |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
|
Scrutinizer analyzes your
composer.json/composer.lockfile if available to determine the classes, and functions that are defined by your dependencies.It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.