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