GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Pull Request — master (#10)
by Lukáš
01:41
created

OAuth2Presenter::actionAccessToken()   B

Complexity

Conditions 6
Paths 10

Size

Total Lines 27
Code Lines 18

Duplication

Lines 5
Ratio 18.52 %

Importance

Changes 0
Metric Value
dl 5
loc 27
c 0
b 0
f 0
rs 8.439
cc 6
eloc 18
nc 10
nop 0
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace Lookyman\Nette\OAuth2\Server\UI;
6
7
use League\OAuth2\Server\AuthorizationServer;
8
use League\OAuth2\Server\Exception\OAuthServerException;
9
use Lookyman\Nette\OAuth2\Server\Psr7\ApplicationPsr7ResponseInterface;
10
use Lookyman\Nette\OAuth2\Server\Storage\IAuthorizationRequestSerializer;
11
use Nette\Application\AbortException;
12
use Nette\Application\UI\Presenter;
13
use Nette\Http\IRequest;
14
use Nette\Http\IResponse;
15
use Psr\Log\LoggerAwareInterface;
16
use Psr\Log\LoggerAwareTrait;
17
18
final class OAuth2Presenter extends Presenter implements LoggerAwareInterface
19
{
20
	use LoggerAwareTrait;
21
	use Psr7Trait;
22
23
	const SESSION_NAMESPACE = 'nette-oauth2-server';
24
25
	/**
26
	 * @var IAuthorizationRequestSerializer
27
	 * @inject
28
	 */
29
	public $authorizationRequestSerializer;
30
31
	/**
32
	 * @var AuthorizationServer
33
	 * @inject
34
	 */
35
	public $authorizationServer;
36
37
	/**
38
	 * @var RedirectService
39
	 * @inject
40
	 */
41
	public $redirectService;
42
43
	public function actionAccessToken()
44
	{
45
		$response = $this->createResponse();
46
47 View Code Duplication
		if (!$this->getHttpRequest()->isMethod(IRequest::POST)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
48
			$body = $this->createStream();
49
			$body->write('Method not allowed');
50
			/** @var ApplicationPsr7ResponseInterface $response */
51
			$response = $response->withStatus(IResponse::S405_METHOD_NOT_ALLOWED)->withBody($body);
52
			$this->sendResponse($response);
53
		}
54
55
		try {
56
			/** @var ApplicationPsr7ResponseInterface $response */
57
			$response = $this->authorizationServer->respondToAccessTokenRequest($this->createServerRequest(), $response);
58
			$this->sendResponse($response);
59
60
		} catch (AbortException $e) {
0 ignored issues
show
Bug introduced by
The class Nette\Application\AbortException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
61
			throw $e;
62
63
		} catch (OAuthServerException $e) {
0 ignored issues
show
Bug introduced by
The class League\OAuth2\Server\Exc...on\OAuthServerException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
64
			/** @var ApplicationPsr7ResponseInterface $response */
65
			$response = $e->generateHttpResponse($response);
66
			$this->sendResponse($response);
67
68
		} catch (\Throwable $e) {
69
			if ($this->logger) {
70
				$this->logger->error($e->getMessage(), ['exception' => $e]);
71
			}
72
			$body = $this->createStream();
73
			$body->write('Unknown error');
74
			/** @var ApplicationPsr7ResponseInterface $response */
75
			$response = $response->withStatus(IResponse::S500_INTERNAL_SERVER_ERROR)->withBody($body);
76
			$this->sendResponse($response);
77
		}
78
	}
79
80
	public function actionAuthorize()
81
	{
82
		$response = $this->createResponse();
83
84 View Code Duplication
		if (!$this->getHttpRequest()->isMethod(IRequest::GET)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
85
			$body = $this->createStream();
86
			$body->write('Method not allowed');
87
			/** @var ApplicationPsr7ResponseInterface $response */
88
			$response = $response->withStatus(IResponse::S405_METHOD_NOT_ALLOWED)->withBody($body);
89
			$this->sendResponse($response);
90
		}
91
92
		try {
93
			$this->getSession(self::SESSION_NAMESPACE)->authorizationRequest = $this->authorizationRequestSerializer->serialize(
94
				$this->authorizationServer->validateAuthorizationRequest($this->createServerRequest())
95
			);
96
			if (!$this->getUser()->isLoggedIn()) {
97
				$this->redirectService->redirectToLoginDestination($this);
98
			}
99
			$this->redirectService->redirectToApproveDestination($this);
100
101
		} catch (AbortException $e) {
0 ignored issues
show
Bug introduced by
The class Nette\Application\AbortException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
102
			throw $e;
103
104
		} catch (OAuthServerException $e) {
0 ignored issues
show
Bug introduced by
The class League\OAuth2\Server\Exc...on\OAuthServerException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
105
			/** @var ApplicationPsr7ResponseInterface $response */
106
			$response = $e->generateHttpResponse($response);
107
			$this->sendResponse($response);
108
109
		} catch (\Throwable $e) {
110
			if ($this->logger) {
111
				$this->logger->error($e->getMessage(), ['exception' => $e]);
112
			}
113
			$body = $this->createStream();
114
			$body->write('Unknown error');
115
			/** @var ApplicationPsr7ResponseInterface $response */
116
			$response = $response->withStatus(IResponse::S500_INTERNAL_SERVER_ERROR)->withBody($body);
117
			$this->sendResponse($response);
118
		}
119
	}
120
121
}
122