|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace League\OAuth2\Server\ResponseTypes\Introspection; |
|
6
|
|
|
|
|
7
|
|
|
use Lcobucci\JWT\Configuration; |
|
8
|
|
|
use Lcobucci\JWT\Signer\Key\InMemory; |
|
9
|
|
|
use Lcobucci\JWT\Signer\Rsa\Sha256; |
|
10
|
|
|
use Lcobucci\JWT\Token; |
|
11
|
|
|
use Lcobucci\JWT\UnencryptedToken; |
|
12
|
|
|
|
|
13
|
|
|
class BearerTokenResponse extends AbstractResponseType |
|
14
|
|
|
{ |
|
15
|
|
|
/** |
|
16
|
|
|
* @var Configuration|null |
|
17
|
|
|
*/ |
|
18
|
|
|
private $jwtConfiguration; |
|
19
|
|
|
|
|
20
|
|
|
public function __construct() |
|
21
|
|
|
{ |
|
22
|
|
|
$this->initJwtConfiguration(); |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Initialise the JWT configuration. |
|
28
|
|
|
*/ |
|
29
|
|
|
private function initJwtConfiguration(): void |
|
30
|
|
|
{ |
|
31
|
|
|
$this->jwtConfiguration = Configuration::forSymmetricSigner(new Sha256(), InMemory::empty()); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Add the token data to the response. |
|
36
|
|
|
* |
|
37
|
|
|
* @return array |
|
38
|
|
|
*/ |
|
39
|
|
|
protected function validIntrospectionResponse(): array |
|
40
|
|
|
{ |
|
41
|
|
|
$token = $this->getTokenFromRequest(); |
|
42
|
|
|
|
|
43
|
|
|
$responseParams = [ |
|
44
|
|
|
'active' => true, |
|
45
|
|
|
'token_type' => 'access_token', |
|
46
|
|
|
'scope' => $this->getClaimFromToken($token, 'scopes', ''), |
|
47
|
|
|
'client_id' => $this->getClaimFromToken($token, 'aud'), |
|
48
|
|
|
'exp' => $this->getClaimFromToken($token, 'exp'), |
|
49
|
|
|
'iat' => $this->getClaimFromToken($token, 'iat'), |
|
50
|
|
|
'sub' => $this->getClaimFromToken($token, 'sub'), |
|
51
|
|
|
'jti' => $this->getClaimFromToken($token, 'jti'), |
|
52
|
|
|
]; |
|
53
|
|
|
|
|
54
|
|
|
return array_merge($this->getExtraParams(), $responseParams); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* Gets the token from the request body. |
|
59
|
|
|
* |
|
60
|
|
|
* @return UnencryptedToken|Token |
|
61
|
|
|
*/ |
|
62
|
|
|
protected function getTokenFromRequest() |
|
63
|
|
|
{ |
|
64
|
|
|
$jwt = $this->request->getParsedBody()['token'] ?? ''; |
|
65
|
|
|
|
|
66
|
|
|
return $this->jwtConfiguration->parser() |
|
|
|
|
|
|
67
|
|
|
->parse($jwt); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* Gets a single claim from the JWT token. |
|
72
|
|
|
* |
|
73
|
|
|
* @param UnencryptedToken|Token\Plain $token |
|
74
|
|
|
* @param string $claim |
|
75
|
|
|
* @param mixed|null $default |
|
76
|
|
|
* |
|
77
|
|
|
* @return mixed |
|
78
|
|
|
*/ |
|
79
|
|
|
protected function getClaimFromToken($token, string $claim, $default = null) |
|
80
|
|
|
{ |
|
81
|
|
|
return $token->claims()->get($claim, $default); |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.