1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @author Alex Bilbie <[email protected]> |
5
|
|
|
* @copyright Copyright (c) Alex Bilbie |
6
|
|
|
* @license http://mit-license.org/ |
7
|
|
|
* |
8
|
|
|
* @link https://github.com/thephpleague/oauth2-server |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace League\OAuth2\Server\Middleware; |
12
|
|
|
|
13
|
|
|
use Exception; |
14
|
|
|
use League\OAuth2\Server\AuthorizationServer; |
15
|
|
|
use League\OAuth2\Server\Exception\OAuthServerException; |
16
|
|
|
use Psr\Http\Message\ResponseFactoryInterface; |
17
|
|
|
use Psr\Http\Message\ResponseInterface; |
18
|
|
|
use Psr\Http\Message\ServerRequestInterface; |
19
|
|
|
use Psr\Http\Server\MiddlewareInterface; |
20
|
|
|
use Psr\Http\Server\RequestHandlerInterface; |
21
|
|
|
|
22
|
|
|
class Psr15AuthorizationServerMiddleware implements MiddlewareInterface |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* @var AuthorizationServer |
26
|
|
|
*/ |
27
|
|
|
private $server; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var ResponseFactoryInterface |
31
|
|
|
*/ |
32
|
|
|
private $responseFactory; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @param AuthorizationServer $server |
36
|
|
|
* @param ResponseFactoryInterface $responseFactory |
37
|
|
|
*/ |
38
|
1 |
|
public function __construct(AuthorizationServer $server, ResponseFactoryInterface $responseFactory) |
39
|
|
|
{ |
40
|
1 |
|
$this->server = $server; |
41
|
1 |
|
$this->responseFactory = $responseFactory; |
42
|
1 |
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @param ServerRequestInterface $request |
46
|
|
|
* @param RequestHandlerInterface $handler |
47
|
|
|
* |
48
|
|
|
* @return ResponseInterface |
49
|
|
|
*/ |
50
|
1 |
|
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface |
51
|
|
|
{ |
52
|
|
|
try { |
53
|
1 |
|
$response = $this->server->respondToAccessTokenRequest($request, $this->responseFactory->createResponse()); |
|
|
|
|
54
|
1 |
|
} catch (OAuthServerException $exception) { |
55
|
1 |
|
return $exception->generateHttpResponse($this->responseFactory->createResponse()); |
56
|
|
|
// @codeCoverageIgnoreStart |
57
|
|
|
} catch (Exception $exception) { |
58
|
|
|
return (new OAuthServerException($exception->getMessage(), 0, 'unknown_error', 500)) |
59
|
|
|
->generateHttpResponse($this->responseFactory->createResponse()); |
60
|
|
|
// @codeCoverageIgnoreEnd |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
// Pass the request on to the next responder in the chain |
64
|
|
|
return $handler->handle($request); |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.