/**
  * @throws AbortException
  */
 public function actionAuthorize()
 {
     if (!$this->getHttpRequest()->isMethod(IRequest::GET)) {
         $body = $this->createStream();
         $body->write('Method not allowed');
         $this->sendResponse($this->createResponse()->withStatus(IResponse::S405_METHOD_NOT_ALLOWED)->withBody($body));
     }
     $response = $this->createResponse();
     try {
         $this->getSession(self::SESSION_NAMESPACE)->authorizationRequest = $this->authorizationRequestSerializer->serialize($this->authorizationServer->validateAuthorizationRequest($this->createServerRequest()));
         if (!$this->getUser()->isLoggedIn()) {
             $this->redirect(...$this->redirectConfig->getLoginDestination());
         }
         $this->redirect(...$this->redirectConfig->getApproveDestination());
     } catch (AbortException $e) {
         throw $e;
     } catch (OAuthServerException $e) {
         $this->sendResponse($e->generateHttpResponse($response));
     } catch (\Exception $e) {
         if ($this->logger) {
             $this->logger->error($e->getMessage(), ['exception' => $e]);
         }
         $body = $this->createStream();
         $body->write('Unknown error');
         $this->sendResponse($response->withStatus(IResponse::S500_INTERNAL_SERVER_ERROR)->withBody($body));
     }
 }
 /**
  * @return ApproveControl
  * @throws AbortException
  * @throws BadRequestException
  */
 protected function createComponentApprove() : ApproveControl
 {
     if (!$this->getUser()->isLoggedIn()) {
         $this->redirect(...$this->redirectConfig->getLoginDestination());
     }
     /** @var string $data */
     $data = $this->getSession(OAuth2Presenter::SESSION_NAMESPACE)->authorizationRequest;
     $authorizationRequest = $data ? $this->authorizationRequestSerializer->unserialize($data) : null;
     if ($authorizationRequest) {
         if (!$authorizationRequest->getUser()) {
             $authorizationRequest->setUser(new UserEntity($this->getUser()->getId()));
         }
         $control = $this->approveControlFactory->create($authorizationRequest);
         $control->onResponse[] = function (ApplicationPsr7ResponseInterface $response) {
             $this->sendResponse($response);
         };
         return $control;
     }
     $this->error(null, HttpResponse::S400_BAD_REQUEST);
 }