diff --git a/src/Middleware/ResourceServerMiddleware.php b/src/Middleware/ResourceServerMiddleware.php index 1b127608..7836a4ce 100644 --- a/src/Middleware/ResourceServerMiddleware.php +++ b/src/Middleware/ResourceServerMiddleware.php @@ -3,23 +3,23 @@ namespace League\OAuth2\Server\Middleware; use League\OAuth2\Server\Exception\OAuthServerException; -use League\OAuth2\Server\Server; +use League\OAuth2\Server\ResourceServer; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; class ResourceServerMiddleware { /** - * @var \League\OAuth2\Server\Server + * @var \League\OAuth2\Server\ResourceServer */ private $server; /** * ResourceServerMiddleware constructor. * - * @param \League\OAuth2\Server\Server $server + * @param \League\OAuth2\Server\ResourceServer $server */ - public function __construct(Server $server) + public function __construct(ResourceServer $server) { $this->server = $server; } diff --git a/src/ResourceServer.php b/src/ResourceServer.php new file mode 100644 index 00000000..1b12e8de --- /dev/null +++ b/src/ResourceServer.php @@ -0,0 +1,74 @@ +accessTokenRepository = $accessTokenRepository; + + if (!$publicKey instanceof CryptKey) { + $publicKey = new CryptKey($publicKey); + } + $this->publicKey = $publicKey; + + $this->authorizationValidator = $authorizationValidator; + } + + /** + * @return \League\OAuth2\Server\AuthorizationValidators\AuthorizationValidatorInterface + */ + protected function getAuthorizationValidator() + { + if (!$this->authorizationValidator instanceof AuthorizationValidatorInterface) { + $this->authorizationValidator = new BearerTokenValidator($this->accessTokenRepository); + } + + $this->authorizationValidator->setPublicKey($this->publicKey); + + return $this->authorizationValidator; + } + + /** + * Determine the access token validity. + * + * @param \Psr\Http\Message\ServerRequestInterface $request + * + * @throws \League\OAuth2\Server\Exception\OAuthServerException + * + * @return \Psr\Http\Message\ServerRequestInterface + */ + public function validateAuthenticatedRequest(ServerRequestInterface $request) + { + return $this->getAuthorizationValidator()->validateAuthorization($request); + } +}