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 | 4 | public function __construct( |
|
26 | private AccessTokenRepositoryInterface $accessTokenRepository, |
||
27 | CryptKeyInterface|string $publicKey, |
||
28 | private ?AuthorizationValidatorInterface $authorizationValidator = null |
||
29 | ) { |
||
30 | 4 | if ($publicKey instanceof CryptKeyInterface === false) { |
|
31 | 4 | $publicKey = new CryptKey($publicKey); |
|
32 | } |
||
33 | 4 | $this->publicKey = $publicKey; |
|
34 | } |
||
35 | |||
36 | 4 | protected function getAuthorizationValidator(): AuthorizationValidatorInterface |
|
37 | { |
||
38 | 4 | if ($this->authorizationValidator instanceof AuthorizationValidatorInterface === false) { |
|
39 | 4 | $this->authorizationValidator = new BearerTokenValidator($this->accessTokenRepository); |
|
40 | } |
||
41 | |||
42 | 4 | if ($this->authorizationValidator instanceof BearerTokenValidator === true) { |
|
43 | 4 | $this->authorizationValidator->setPublicKey($this->publicKey); |
|
44 | } |
||
45 | |||
46 | 4 | return $this->authorizationValidator; |
|
0 ignored issues
–
show
Bug
Best Practice
introduced
by
![]() |
|||
47 | } |
||
48 | |||
49 | /** |
||
50 | * Determine the access token validity. |
||
51 | * |
||
52 | * @throws OAuthServerException |
||
53 | */ |
||
54 | 4 | public function validateAuthenticatedRequest(ServerRequestInterface $request): ServerRequestInterface |
|
55 | { |
||
56 | 4 | return $this->getAuthorizationValidator()->validateAuthorization($request); |
|
57 | } |
||
58 | } |
||
59 |