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:47
created

ApprovePresenterTrait::error()

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 1
c 0
b 0
f 0
nc 1
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace Lookyman\Nette\OAuth2\Server\UI;
6
7
use Lookyman\Nette\OAuth2\Server\Psr7\ApplicationPsr7ResponseInterface;
8
use Lookyman\Nette\OAuth2\Server\RedirectConfig;
9
use Lookyman\Nette\OAuth2\Server\Storage\IAuthorizationRequestSerializer;
10
use Lookyman\Nette\OAuth2\Server\User\UserEntity;
11
use Nette\Application\IResponse;
12
use Nette\Http\IResponse as HttpResponse;
13
use Nextras\Application\UI\SecuredLinksPresenterTrait;
14
15
trait ApprovePresenterTrait
16
{
17
	use SecuredLinksPresenterTrait;
18
19
	/**
20
	 * @var IApproveControlFactory
21
	 * @inject
22
	 */
23
	public $approveControlFactory;
24
25
	/**
26
	 * @var IAuthorizationRequestSerializer
27
	 * @inject
28
	 */
29
	public $authorizationRequestSerializer;
30
31
	/**
32
	 * @var RedirectConfig
33
	 * @inject
34
	 */
35
	public $redirectConfig;
36
37
	protected function createComponentApprove(): ApproveControl
38
	{
39
		if (!$this->getUser()->isLoggedIn()) {
40
			$this->redirectConfig->redirectToLoginDestination($this);
41
		}
42
43
		/** @var string $data */
44
		$data = $this->getSession(OAuth2Presenter::SESSION_NAMESPACE)->authorizationRequest;
45
		$authorizationRequest = $data ? $this->authorizationRequestSerializer->unserialize($data) : null;
46
47
		if ($authorizationRequest) {
48
			if (!$authorizationRequest->getUser()) {
49
				$authorizationRequest->setUser(new UserEntity($this->getUser()->getId()));
50
			}
51
			$control = $this->approveControlFactory->create($authorizationRequest);
52
			$control->onResponse[] = function (ApplicationPsr7ResponseInterface $response) {
53
				$this->sendResponse($response);
54
			};
55
			return $control;
56
		}
57
58
		$this->error(null, HttpResponse::S400_BAD_REQUEST);
59
	}
60
61
	/**
62
	 * @phpcsSuppress SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingParameterTypeHint
63
	 */
64
	abstract public function error($message = null, $code = HttpResponse::S404_NOT_FOUND);
65
66
	/**
67
	 * @phpcsSuppress SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingParameterTypeHint
68
	 */
69
	abstract public function getSession($namespace = null);
70
71
	abstract public function getUser();
72
73
	abstract public function sendResponse(IResponse $response);
74
75
}
76