abstract access token validation

This commit is contained in:
Julián Gutiérrez
2016-02-12 14:19:47 +01:00
parent 95919a688e
commit f314154216
4 changed files with 28 additions and 10 deletions

View File

@@ -6,6 +6,7 @@ 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 AuthenticationServerMiddleware
{
@@ -38,9 +39,10 @@ class AuthenticationServerMiddleware
} catch (OAuthServerException $exception) {
return $exception->generateHttpResponse($response);
} catch (\Exception $exception) {
$response->getBody()->write($exception->getMessage());
$body = new Stream('php://temp', 'r+');
$body->write($exception->getMessage());
return $response->withStatus(500);
return $response->withStatus(500)->withBody($body);
}
if (in_array($response->getStatusCode(), [400, 401, 500])) {

View File

@@ -6,6 +6,7 @@ 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
{
@@ -34,13 +35,14 @@ class ResourceServerMiddleware
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next)
{
try {
$request = $this->server->getResponseType()->determineAccessTokenInHeader($request);
$request = $this->server->validateRequest($request);
} catch (OAuthServerException $exception) {
return $exception->generateHttpResponse($response);
} catch (\Exception $exception) {
$response->getBody()->write($exception->getMessage());
$body = new Stream('php://temp', 'r+');
$body->write($exception->getMessage());
return $response->withStatus(500);
return $response->withStatus(500)->withBody($body);
}
// Pass the request and response on to the next responder in the chain