26 private $eventManager;
38 $this->request = $request;
39 $this->engine = $engine;
40 $this->eventManager = $eventManager;
41 $this->application = $application;
44 private function verifyRequest() :
Result
48 $authToken = $this->request->getHeader(
'Authorization');
51 $authToken = \Bitrix\Main\Context::getCurrent()->getServer()->get(
'REMOTE_USER');
55 $result->addError(
new Error(
'wrong request'));
59 $authToken = substr($authToken, strlen(
'Bearer '));
60 $engineClientSecret = $this->engine->getClientSecret();
61 $authTokenSalt = mb_substr($authToken, 0, 8);
62 $isAllowedToken = $authToken === $authTokenSalt . md5($authTokenSalt . $engineClientSecret);
65 $result->addError(
new Error(
'Invalid client credentials'));
72 private function run() : Json
74 $result = $this->verifyRequest();
76 if (!$result->isSuccess())
78 return $this->buildErrorResponse(
79 $result->getErrorCollection()->current()
83 $this->eventManager->send(
84 new Event(
'seo',
'OnCatalogWebhook', [
'payload' => $this->request->toArray(),])
87 return $this->buildResponse();
93 $response = $this->run();
94 $this->application->end(200, $response);
97 private function buildErrorResponse(
Error $error):
Json
108 private function buildResponse():
Json