2016-01-17 23:10:26 +05:30
|
|
|
<?php
|
2016-04-17 17:36:05 +05:30
|
|
|
/**
|
|
|
|
* @author Alex Bilbie <hello@alexbilbie.com>
|
|
|
|
* @copyright Copyright (c) Alex Bilbie
|
|
|
|
* @license http://mit-license.org/
|
|
|
|
*
|
|
|
|
* @link https://github.com/thephpleague/oauth2-server
|
|
|
|
*/
|
2016-01-17 23:10:26 +05:30
|
|
|
|
|
|
|
namespace League\OAuth2\Server\Middleware;
|
|
|
|
|
2016-04-17 17:24:25 +05:30
|
|
|
use League\OAuth2\Server\AuthorizationServer;
|
2016-04-17 17:36:17 +05:30
|
|
|
use League\OAuth2\Server\Exception\OAuthServerException;
|
2016-01-17 23:10:26 +05:30
|
|
|
use Psr\Http\Message\ResponseInterface;
|
|
|
|
use Psr\Http\Message\ServerRequestInterface;
|
|
|
|
|
2016-04-17 17:24:25 +05:30
|
|
|
class AuthorizationServerMiddleware
|
2016-01-17 23:10:26 +05:30
|
|
|
{
|
|
|
|
/**
|
2016-07-09 04:30:44 +05:30
|
|
|
* @var AuthorizationServer
|
2016-01-17 23:10:26 +05:30
|
|
|
*/
|
|
|
|
private $server;
|
|
|
|
|
|
|
|
/**
|
2016-07-09 04:30:44 +05:30
|
|
|
* @param AuthorizationServer $server
|
2016-01-17 23:10:26 +05:30
|
|
|
*/
|
2016-04-17 17:24:25 +05:30
|
|
|
public function __construct(AuthorizationServer $server)
|
2016-01-17 23:10:26 +05:30
|
|
|
{
|
|
|
|
$this->server = $server;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-07-09 04:30:44 +05:30
|
|
|
* @param ServerRequestInterface $request
|
|
|
|
* @param ResponseInterface $response
|
|
|
|
* @param callable $next
|
2016-01-17 23:10:26 +05:30
|
|
|
*
|
2016-07-09 04:30:44 +05:30
|
|
|
* @return ResponseInterface
|
2016-01-17 23:10:26 +05:30
|
|
|
*/
|
|
|
|
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next)
|
|
|
|
{
|
|
|
|
try {
|
2016-04-09 20:52:22 +05:30
|
|
|
$response = $this->server->respondToAccessTokenRequest($request, $response);
|
2016-01-17 23:10:26 +05:30
|
|
|
} catch (OAuthServerException $exception) {
|
|
|
|
return $exception->generateHttpResponse($response);
|
2016-03-10 22:52:10 +05:30
|
|
|
// @codeCoverageIgnoreStart
|
2016-01-17 23:10:26 +05:30
|
|
|
} catch (\Exception $exception) {
|
2016-05-11 17:43:58 +05:30
|
|
|
return (new OAuthServerException($exception->getMessage(), 0, 'unknown_error', 500))
|
|
|
|
->generateHttpResponse($response);
|
2016-03-10 22:52:10 +05:30
|
|
|
// @codeCoverageIgnoreEnd
|
2016-01-17 23:10:26 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
// Pass the request and response on to the next responder in the chain
|
|
|
|
return $next($request, $response);
|
|
|
|
}
|
|
|
|
}
|