|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* OAuth 2.0 Bearer Token Response. |
|
5
|
|
|
* |
|
6
|
|
|
* @author Alex Bilbie <[email protected]> |
|
7
|
|
|
* @copyright Copyright (c) Alex Bilbie |
|
8
|
|
|
* @license http://mit-license.org/ |
|
9
|
|
|
* |
|
10
|
|
|
* @link https://github.com/thephpleague/oauth2-server |
|
11
|
|
|
*/ |
|
12
|
|
|
|
|
13
|
|
|
declare(strict_types=1); |
|
14
|
|
|
|
|
15
|
|
|
namespace League\OAuth2\Server\ResponseTypes; |
|
16
|
|
|
|
|
17
|
|
|
use League\OAuth2\Server\Entities\AccessTokenEntityInterface; |
|
18
|
|
|
use LogicException; |
|
19
|
|
|
use Psr\Http\Message\ResponseInterface; |
|
20
|
|
|
use SensitiveParameter; |
|
|
|
|
|
|
21
|
|
|
|
|
22
|
|
|
use function array_merge; |
|
23
|
|
|
use function json_encode; |
|
24
|
|
|
use function time; |
|
25
|
|
|
|
|
26
|
|
|
class BearerTokenResponse extends AbstractResponseType |
|
27
|
|
|
{ |
|
28
|
6 |
|
public function generateHttpResponse(ResponseInterface $response): ResponseInterface |
|
29
|
|
|
{ |
|
30
|
6 |
|
$expireDateTime = $this->accessToken->getExpiryDateTime()->getTimestamp(); |
|
31
|
|
|
|
|
32
|
6 |
|
$responseParams = [ |
|
33
|
6 |
|
'token_type' => 'Bearer', |
|
34
|
6 |
|
'expires_in' => $expireDateTime - time(), |
|
35
|
6 |
|
'access_token' => $this->accessToken->toString(), |
|
36
|
6 |
|
]; |
|
37
|
|
|
|
|
38
|
6 |
|
if (isset($this->refreshToken)) { |
|
39
|
6 |
|
$refreshTokenPayload = json_encode([ |
|
40
|
6 |
|
'client_id' => $this->accessToken->getClient()->getIdentifier(), |
|
41
|
6 |
|
'refresh_token_id' => $this->refreshToken->getIdentifier(), |
|
42
|
6 |
|
'access_token_id' => $this->accessToken->getIdentifier(), |
|
43
|
6 |
|
'scopes' => $this->accessToken->getScopes(), |
|
44
|
6 |
|
'user_id' => $this->accessToken->getUserIdentifier(), |
|
45
|
6 |
|
'expire_time' => $this->refreshToken->getExpiryDateTime()->getTimestamp(), |
|
46
|
6 |
|
]); |
|
47
|
|
|
|
|
48
|
6 |
|
if ($refreshTokenPayload === false) { |
|
49
|
|
|
throw new LogicException('Error encountered JSON encoding the refresh token payload'); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
6 |
|
$responseParams['refresh_token'] = $this->encrypt($refreshTokenPayload); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
6 |
|
$responseParams = json_encode(array_merge($this->getExtraParams($this->accessToken), $responseParams)); |
|
56
|
|
|
|
|
57
|
6 |
|
if ($responseParams === false) { |
|
58
|
|
|
throw new LogicException('Error encountered JSON encoding response parameters'); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
6 |
|
$response = $response |
|
62
|
6 |
|
->withStatus(200) |
|
63
|
6 |
|
->withHeader('pragma', 'no-cache') |
|
64
|
6 |
|
->withHeader('cache-control', 'no-store') |
|
65
|
6 |
|
->withHeader('content-type', 'application/json; charset=UTF-8'); |
|
66
|
|
|
|
|
67
|
6 |
|
$response->getBody()->write($responseParams); |
|
68
|
|
|
|
|
69
|
6 |
|
return $response; |
|
|
|
|
|
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* Add custom fields to your Bearer Token response here, then override |
|
74
|
|
|
* AuthorizationServer::getResponseType() to pull in your version of |
|
75
|
|
|
* this class rather than the default. |
|
76
|
|
|
* |
|
77
|
|
|
* @return array<array-key,mixed> |
|
|
|
|
|
|
78
|
|
|
*/ |
|
79
|
5 |
|
protected function getExtraParams( |
|
80
|
|
|
#[SensitiveParameter] |
|
|
|
|
|
|
81
|
|
|
AccessTokenEntityInterface $accessToken |
|
82
|
|
|
): array { |
|
83
|
5 |
|
return []; |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
|
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