mirror of
https://github.com/elyby/oauth2-server.git
synced 2024-12-28 16:00:24 +05:30
4ab9c52767
V5 - rename validateRequest
54 lines
1.6 KiB
PHP
54 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace League\OAuth2\Server\Middleware;
|
|
|
|
use League\OAuth2\Server\Exception\OAuthServerException;
|
|
use League\OAuth2\Server\Server;
|
|
use Psr\Http\Message\ResponseInterface;
|
|
use Psr\Http\Message\ServerRequestInterface;
|
|
use Zend\Diactoros\Stream;
|
|
|
|
class ResourceServerMiddleware
|
|
{
|
|
/**
|
|
* @var \League\OAuth2\Server\Server
|
|
*/
|
|
private $server;
|
|
|
|
/**
|
|
* ResourceServerMiddleware constructor.
|
|
*
|
|
* @param \League\OAuth2\Server\Server $server
|
|
*/
|
|
public function __construct(Server $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) {
|
|
$body = new Stream('php://temp', 'r+');
|
|
$body->write($exception->getMessage());
|
|
|
|
return $response->withStatus(500)->withBody($body);
|
|
// @codeCoverageIgnoreEnd
|
|
}
|
|
|
|
// Pass the request and response on to the next responder in the chain
|
|
return $next($request, $response);
|
|
}
|
|
}
|