1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @author Alex Bilbie <[email protected]> |
5
|
|
|
* @copyright Copyright (c) Alex Bilbie |
6
|
|
|
* @license http://mit-license.org/ |
7
|
|
|
* |
8
|
|
|
* @link https://github.com/thephpleague/oauth2-server |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
declare(strict_types=1); |
12
|
|
|
|
13
|
|
|
namespace League\OAuth2\Server; |
14
|
|
|
|
15
|
|
|
use League\OAuth2\Server\AuthorizationValidators\AuthorizationValidatorInterface; |
16
|
|
|
use League\OAuth2\Server\AuthorizationValidators\BearerTokenValidator; |
17
|
|
|
use League\OAuth2\Server\Exception\OAuthServerException; |
18
|
|
|
use League\OAuth2\Server\Repositories\AccessTokenRepositoryInterface; |
19
|
|
|
use Psr\Http\Message\ServerRequestInterface; |
20
|
|
|
|
21
|
|
|
class ResourceServer |
22
|
|
|
{ |
23
|
|
|
private CryptKeyInterface $publicKey; |
24
|
|
|
|
25
|
|
|
private ?AuthorizationValidatorInterface $authorizationValidator = null; |
26
|
|
|
|
27
|
4 |
|
public function __construct( |
28
|
|
|
private AccessTokenRepositoryInterface $accessTokenRepository, |
29
|
|
|
CryptKeyInterface|string $publicKey, |
30
|
|
|
AuthorizationValidatorInterface $authorizationValidator = null |
31
|
|
|
) { |
32
|
4 |
|
if ($publicKey instanceof CryptKeyInterface === false) { |
33
|
4 |
|
$publicKey = new CryptKey($publicKey); |
34
|
|
|
} |
35
|
4 |
|
$this->publicKey = $publicKey; |
36
|
|
|
|
37
|
4 |
|
$this->authorizationValidator = $authorizationValidator; |
38
|
|
|
} |
39
|
|
|
|
40
|
4 |
|
protected function getAuthorizationValidator(): AuthorizationValidatorInterface |
41
|
|
|
{ |
42
|
4 |
|
if ($this->authorizationValidator instanceof AuthorizationValidatorInterface === false) { |
43
|
4 |
|
$this->authorizationValidator = new BearerTokenValidator($this->accessTokenRepository); |
44
|
|
|
} |
45
|
|
|
|
46
|
4 |
|
if ($this->authorizationValidator instanceof BearerTokenValidator === true) { |
47
|
4 |
|
$this->authorizationValidator->setPublicKey($this->publicKey); |
|
|
|
|
48
|
|
|
} |
49
|
|
|
|
50
|
4 |
|
return $this->authorizationValidator; |
|
|
|
|
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Determine the access token validity. |
55
|
|
|
* |
56
|
|
|
* @throws OAuthServerException |
57
|
|
|
*/ |
58
|
4 |
|
public function validateAuthenticatedRequest(ServerRequestInterface $request): ServerRequestInterface |
59
|
|
|
{ |
60
|
4 |
|
return $this->getAuthorizationValidator()->validateAuthorization($request); |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|
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.