- Модуль: disk
- Путь к файлу: ~/bitrix/modules/disk/lib/document/myofficehandler.php
- Класс: BitrixDiskDocumentMyOfficeHandler
- Вызов: MyOfficeHandler::queryAccessToken
public function queryAccessToken()
{
list($login, $password) = self::getPredefinedUser($this->userId);
if (!$login)
{
return $this;
}
$http = new HttpClient(array(
'redirect' => false,
'socketTimeout' => 10,
'streamTimeout' => 30,
'version' => HttpClient::HTTP_1_1,
));
$http->setHeader('Content-Type', 'application/json; charset=UTF-8');
$postFields = Json::encode(array(
'login' => $login,
'password' => $password,
));
if ($http->post('https://auth.myoffice.ru/login', $postFields) === false)
{
$errorString = implode('; ', array_keys($http->getError()));
$this->errorCollection[] = new Error(
$errorString, self::ERROR_CODE_INVALID_CREDENTIALS
);
return $this;
}
if(!$this->checkHttpResponse($http))
{
return $this;
}
$token = Json::decode($http->getResult());
if($token === null)
{
$this->errorCollection[] = new Error(
'Could not decode response as json', self::ERROR_BAD_JSON
);
return $this;
}
$this->accessToken = $token['token'];
return $this;
}