-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
Copy pathPsr15AuthorizationServerMiddleware.php
66 lines (58 loc) · 2.08 KB
/
Psr15AuthorizationServerMiddleware.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
/**
* @author Alex Bilbie <hello@alexbilbie.com>
* @copyright Copyright (c) Alex Bilbie
* @license http://mit-license.org/
*
* @link https://github.com/thephpleague/oauth2-server
*/
namespace League\OAuth2\Server\Middleware;
use Exception;
use League\OAuth2\Server\AuthorizationServer;
use League\OAuth2\Server\Exception\OAuthServerException;
use Psr\Http\Message\ResponseFactoryInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;
class Psr15AuthorizationServerMiddleware implements MiddlewareInterface
{
/**
* @var AuthorizationServer
*/
private $server;
/**
* @var ResponseFactoryInterface
*/
private $responseFactory;
/**
* @param AuthorizationServer $server
* @param ResponseFactoryInterface $responseFactory
*/
public function __construct(AuthorizationServer $server, ResponseFactoryInterface $responseFactory)
{
$this->server = $server;
$this->responseFactory = $responseFactory;
}
/**
* @param ServerRequestInterface $request
* @param RequestHandlerInterface $handler
*
* @return ResponseInterface
*/
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
try {
$response = $this->server->respondToAccessTokenRequest($request, $this->responseFactory->createResponse());
} catch (OAuthServerException $exception) {
return $exception->generateHttpResponse($this->responseFactory->createResponse());
// @codeCoverageIgnoreStart
} catch (Exception $exception) {
return (new OAuthServerException($exception->getMessage(), 0, 'unknown_error', 500))
->generateHttpResponse($this->responseFactory->createResponse());
// @codeCoverageIgnoreEnd
}
// Pass the request on to the next responder in the chain
return $handler->handle($request);
}
}