mirror of
https://github.com/elyby/oauth2-server.git
synced 2025-05-31 14:12:07 +05:30
59 lines
1.7 KiB
PHP
59 lines
1.7 KiB
PHP
<?php
|
|
/**
|
|
* @author Alex Bilbie <hello@alexbilbie.com>
|
|
* @copyright Copyright (c) Alex Bilbie
|
|
* @license http://mit-license.org/
|
|
*
|
|
* @link https://github.com/thephpleague/oauth2-server
|
|
*/
|
|
|
|
namespace League\OAuth2\Server\Middleware;
|
|
|
|
use League\OAuth2\Server\Exception\OAuthServerException;
|
|
use League\OAuth2\Server\ResourceServer;
|
|
use Psr\Http\Message\ResponseInterface;
|
|
use Psr\Http\Message\ServerRequestInterface;
|
|
|
|
class ResourceServerMiddleware
|
|
{
|
|
/**
|
|
* @var \League\OAuth2\Server\ResourceServer
|
|
*/
|
|
private $server;
|
|
|
|
/**
|
|
* ResourceServerMiddleware constructor.
|
|
*
|
|
* @param \League\OAuth2\Server\ResourceServer $server
|
|
*/
|
|
public function __construct(ResourceServer $server)
|
|
{
|
|
$this->server = $server;
|
|
}
|
|
|
|
/**
|
|
* @param \Psr\Http\Message\ServerRequestInterface $request
|
|
* @param \Psr\Http\Message\ResponseInterface $response
|
|
* @param callable $next
|
|
*
|
|
* @return \Psr\Http\Message\ResponseInterface
|
|
*/
|
|
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next)
|
|
{
|
|
try {
|
|
$request = $this->server->validateAuthenticatedRequest($request);
|
|
} catch (OAuthServerException $exception) {
|
|
return $exception->generateHttpResponse($response);
|
|
// @codeCoverageIgnoreStart
|
|
} catch (\Exception $exception) {
|
|
$response->getBody()->write($exception->getMessage());
|
|
|
|
return $response->withStatus(500);
|
|
// @codeCoverageIgnoreEnd
|
|
}
|
|
|
|
// Pass the request and response on to the next responder in the chain
|
|
return $next($request, $response);
|
|
}
|
|
}
|