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áš
07:03
created

OAuth2Presenter::actionAuthorize()   C

Complexity

Conditions 7
Paths 44

Size

Total Lines 33
Code Lines 22

Duplication

Lines 5
Ratio 15.15 %

Importance

Changes 0
Metric Value
dl 5
loc 33
c 0
b 0
f 0
rs 6.7272
cc 7
eloc 22
nc 44
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\RedirectConfig;
11
use Lookyman\Nette\OAuth2\Server\Storage\IAuthorizationRequestSerializer;
12
use Nette\Application\AbortException;
13
use Nette\Application\UI\Presenter;
14
use Nette\Http\IRequest;
15
use Nette\Http\IResponse;
16
use Psr\Log\LoggerAwareInterface;
17
use Psr\Log\LoggerAwareTrait;
18
19
final class OAuth2Presenter extends Presenter implements LoggerAwareInterface
20
{
21
	use LoggerAwareTrait;
22
	use Psr7Trait;
23
24
	const SESSION_NAMESPACE = 'nette-oauth2-server';
25
26
	/**
27
	 * @var IAuthorizationRequestSerializer
28
	 * @inject
29
	 */
30
	public $authorizationRequestSerializer;
31
32
	/**
33
	 * @var AuthorizationServer
34
	 * @inject
35
	 */
36
	public $authorizationServer;
37
38
	/**
39
	 * @var RedirectConfig
40
	 * @inject
41
	 */
42
	public $redirectConfig;
43
44
	public function actionAccessToken()
45
	{
46 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...
47
			$body = $this->createStream();
48
			$body->write('Method not allowed');
49
			$this->sendResponse($this->createResponse()->withStatus(IResponse::S405_METHOD_NOT_ALLOWED)->withBody($body));
50
		}
51
52
		$response = $this->createResponse();
53
		try {
54
			/** @var ApplicationPsr7ResponseInterface $response */
55
			$response = $this->authorizationServer->respondToAccessTokenRequest($this->createServerRequest(), $response);
56
			$this->sendResponse($response);
57
58
		} catch (AbortException $e) {
59
			throw $e;
60
61
		} catch (OAuthServerException $e) {
62
			/** @var ApplicationPsr7ResponseInterface $response */
63
			$response = $e->generateHttpResponse($response);
64
			$this->sendResponse($response);
65
66
		} catch (\Throwable $e) {
67
			if ($this->logger) {
68
				$this->logger->error($e->getMessage(), ['exception' => $e]);
69
			}
70
			$body = $this->createStream();
71
			$body->write('Unknown error');
72
			$this->sendResponse($response->withStatus(IResponse::S500_INTERNAL_SERVER_ERROR)->withBody($body));
73
		}
74
	}
75
76
	public function actionAuthorize()
77
	{
78 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...
79
			$body = $this->createStream();
80
			$body->write('Method not allowed');
81
			$this->sendResponse($this->createResponse()->withStatus(IResponse::S405_METHOD_NOT_ALLOWED)->withBody($body));
82
		}
83
84
		$response = $this->createResponse();
85
		try {
86
			$this->getSession(self::SESSION_NAMESPACE)->authorizationRequest = $this->authorizationRequestSerializer->serialize(
87
				$this->authorizationServer->validateAuthorizationRequest($this->createServerRequest())
88
			);
89
			if (!$this->getUser()->isLoggedIn()) {
90
				$this->redirectConfig->redirectToLoginDestination($this);
91
			}
92
			$this->redirectConfig->redirectToApproveDestination($this);
93
94
		} catch (AbortException $e) {
95
			throw $e;
96
97
		} catch (OAuthServerException $e) {
98
			/** @var ApplicationPsr7ResponseInterface $response */
99
			$response = $e->generateHttpResponse($response);
100
			$this->sendResponse($response);
101
102
		} catch (\Throwable $e) {
103
			if ($this->logger) {
104
				$this->logger->error($e->getMessage(), ['exception' => $e]);
105
			}
106
			$body = $this->createStream();
107
			$body->write('Unknown error');
108
			$this->sendResponse($response->withStatus(IResponse::S500_INTERNAL_SERVER_ERROR)->withBody($body));
109
		}
110
	}
111
112
}
113