exception based determineAccessTokenInHeader

This commit is contained in:
Julián Gutiérrez
2016-01-20 00:32:59 +01:00
parent 94cc7c2bc7
commit ef5904ab1a
3 changed files with 27 additions and 17 deletions

View File

@@ -33,18 +33,12 @@ class ResourceServerMiddleware
*/
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next)
{
if ($request->hasHeader('authorization') === false) {
$exception = OAuthServerException::accessDenied('Missing authorization header');
return $exception->generateHttpResponse($response);
}
$request = $this->server->getResponseType()->determineAccessTokenInHeader($request);
if ($request->getAttribute('oauth_access_token') === null) {
$exception = OAuthServerException::accessDenied($request->getAttribute('oauth_access_token_error'));
try {
$request = $this->server->getResponseType()->determineAccessTokenInHeader($request);
} catch (OAuthServerException $exception) {
return $exception->generateHttpResponse($response);
} catch (\Exception $exception) {
return $response->withStatus(500)->write($exception->getMessage());
}
// Pass the request and response on to the next responder in the chain