|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace League\OAuth2\Server; |
|
6
|
|
|
|
|
7
|
|
|
use Defuse\Crypto\Key; |
|
8
|
|
|
use League\OAuth2\Server\EventEmitting\EmitterAwareInterface; |
|
9
|
|
|
use League\OAuth2\Server\EventEmitting\EmitterAwarePolyfill; |
|
10
|
|
|
use League\OAuth2\Server\Handlers\TokenHandlerInterface; |
|
11
|
|
|
use League\OAuth2\Server\Handlers\TokenIntrospectionHandler; |
|
12
|
|
|
use League\OAuth2\Server\Handlers\TokenRevocationHandler; |
|
13
|
|
|
use League\OAuth2\Server\Repositories\AccessTokenRepositoryInterface; |
|
14
|
|
|
use League\OAuth2\Server\Repositories\ClientRepositoryInterface; |
|
15
|
|
|
use League\OAuth2\Server\Repositories\RefreshTokenRepositoryInterface; |
|
16
|
|
|
use Psr\Http\Message\ResponseInterface; |
|
17
|
|
|
use Psr\Http\Message\ServerRequestInterface; |
|
18
|
|
|
|
|
19
|
|
|
class TokenServer implements EmitterAwareInterface |
|
20
|
|
|
{ |
|
21
|
|
|
use EmitterAwarePolyfill; |
|
22
|
|
|
|
|
23
|
|
|
private CryptKeyInterface $publicKey; |
|
24
|
|
|
|
|
25
|
|
|
protected ?TokenHandlerInterface $tokenRevocationHandler = null; |
|
26
|
|
|
|
|
27
|
|
|
protected ?TokenHandlerInterface $tokenIntrospectionHandler = null; |
|
28
|
|
|
|
|
29
|
|
|
public function __construct( |
|
30
|
|
|
private ClientRepositoryInterface $clientRepository, |
|
31
|
|
|
private AccessTokenRepositoryInterface $accessTokenRepository, |
|
32
|
|
|
private RefreshTokenRepositoryInterface $refreshTokenRepository, |
|
33
|
|
|
CryptKeyInterface|string $publicKey, |
|
34
|
|
|
private Key|string $encryptionKey |
|
35
|
|
|
) { |
|
36
|
|
|
if ($publicKey instanceof CryptKeyInterface === false) { |
|
37
|
|
|
$publicKey = new CryptKey($publicKey); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
$this->publicKey = $publicKey; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
public function setTokenRevocationHandler(TokenHandlerInterface $handler): void |
|
44
|
|
|
{ |
|
45
|
|
|
$this->tokenRevocationHandler = $handler; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
public function setTokenIntrospectionHandler(TokenHandlerInterface $handler): void |
|
49
|
|
|
{ |
|
50
|
|
|
$this->tokenIntrospectionHandler = $handler; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
protected function getTokenRevocationHandler(): TokenHandlerInterface |
|
54
|
|
|
{ |
|
55
|
|
|
$this->tokenRevocationHandler ??= new TokenRevocationHandler(); |
|
56
|
|
|
|
|
57
|
|
|
$this->tokenRevocationHandler->setClientRepository($this->clientRepository); |
|
|
|
|
|
|
58
|
|
|
$this->tokenRevocationHandler->setAccessTokenRepository($this->accessTokenRepository); |
|
59
|
|
|
$this->tokenRevocationHandler->setRefreshTokenRepository($this->refreshTokenRepository); |
|
60
|
|
|
$this->tokenRevocationHandler->setPublicKey($this->publicKey); |
|
61
|
|
|
$this->tokenRevocationHandler->setEmitter($this->getEmitter()); |
|
62
|
|
|
$this->tokenRevocationHandler->setEncryptionKey($this->encryptionKey); |
|
63
|
|
|
|
|
64
|
|
|
return $this->tokenRevocationHandler; |
|
|
|
|
|
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
protected function getTokenIntrospectionHandler(): TokenHandlerInterface |
|
68
|
|
|
{ |
|
69
|
|
|
$this->tokenIntrospectionHandler ??= new TokenIntrospectionHandler(); |
|
70
|
|
|
|
|
71
|
|
|
$this->tokenIntrospectionHandler->setClientRepository($this->clientRepository); |
|
|
|
|
|
|
72
|
|
|
$this->tokenIntrospectionHandler->setAccessTokenRepository($this->accessTokenRepository); |
|
73
|
|
|
$this->tokenIntrospectionHandler->setRefreshTokenRepository($this->refreshTokenRepository); |
|
74
|
|
|
$this->tokenIntrospectionHandler->setPublicKey($this->publicKey); |
|
75
|
|
|
$this->tokenIntrospectionHandler->setEmitter($this->getEmitter()); |
|
76
|
|
|
$this->tokenIntrospectionHandler->setEncryptionKey($this->encryptionKey); |
|
77
|
|
|
|
|
78
|
|
|
return $this->tokenIntrospectionHandler; |
|
|
|
|
|
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
public function respondToTokenRevocationRequest( |
|
82
|
|
|
ServerRequestInterface $request, |
|
83
|
|
|
ResponseInterface $response |
|
84
|
|
|
): ResponseInterface { |
|
85
|
|
|
return $this->getTokenRevocationHandler()->respondToRequest($request, $response); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
public function respondToTokenIntrospectionRequest( |
|
89
|
|
|
ServerRequestInterface $request, |
|
90
|
|
|
ResponseInterface $response |
|
91
|
|
|
): ResponseInterface { |
|
92
|
|
|
return $this->getTokenIntrospectionHandler()->respondToRequest($request, $response); |
|
93
|
|
|
} |
|
94
|
|
|
} |
|
95
|
|
|
|
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.