2016-01-17 19:38:42 +05:30
|
|
|
<?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;
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2016-01-20 05:02:59 +05:30
|
|
|
try {
|
|
|
|
$request = $this->server->getResponseType()->determineAccessTokenInHeader($request);
|
|
|
|
} catch (OAuthServerException $exception) {
|
2016-01-17 19:38:42 +05:30
|
|
|
return $exception->generateHttpResponse($response);
|
2016-01-20 05:02:59 +05:30
|
|
|
} catch (\Exception $exception) {
|
2016-01-20 15:28:45 +05:30
|
|
|
$response->getBody()->write($exception->getMessage());
|
|
|
|
|
|
|
|
return $response->withStatus(500);
|
2016-01-17 19:38:42 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
// Pass the request and response on to the next responder in the chain
|
|
|
|
return $next($request, $response);
|
|
|
|
}
|
|
|
|
}
|