- Модуль: calendar
- Путь к файлу: ~/bitrix/modules/calendar/lib/sync/office365/office365context.php
- Класс: BitrixCalendarSyncOffice365Office365Context
- Вызов: Office365Context::prepareHttpClient
private function prepareHttpClient(): HttpClient
{
if (!Loader::includeModule('socialservices'))
{
throw new LoaderException('Module socialservices is required.');
}
$httpClient = new HttpClient();
$oAuthEntity = $this->prepareAuthEntity($this->owner->getId());
if ($oAuthEntity->GetAccessToken())
{
$httpClient->setHeader('Authorization', 'Bearer ' . $oAuthEntity->getToken());
$httpClient->setHeader('Content-Type', 'application/json');
$httpClient->setHeader('Prefer', 'odata.maxpagesize=' . $this->getMaxPageSize());
$httpClient->setRedirect(false);
}
elseif ($checkUser = $oAuthEntity->GetCurrentUser())
{
if (!empty($checkUser['access_token']))
{
$httpClient->setHeader('Authorization', 'Bearer ' . $checkUser['access_token']);
$httpClient->setHeader('Content-Type', 'application/json');
$httpClient->setHeader('Prefer', 'odata.maxpagesize=' . $this->getMaxPageSize());
$httpClient->setRedirect(false);
}
else
{
throw new AuthException('Access token not received', 401);
}
}
else
{
// TODO: maybe move it to the exception handler.
// Now it's impossible, because there are many points of call this class
(new BitrixCalendarCoreMappersConnection())->update(
$this->getConnection()->setDeleted(true)
);
throw new RemoteAccountException('Office365 account not found', 403);
}
return $httpClient;
}