- Модуль: socialservices
- Путь к файлу: ~/bitrix/modules/socialservices/classes/general/mailru2.php
- Класс: CMailRu2Interface
- Вызов: CMailRu2Interface::getNewAccessToken
public function getNewAccessToken($refreshToken = false, $userId = 0, $save = false)
{
if ($this->appID == false || $this->appSecret == false)
{
return false;
}
if ($refreshToken == false)
{
$refreshToken = $this->refresh_token;
}
$http = new HttpClient(array(
'socketTimeout' => $this->httpTimeout,
'streamTimeout' => $this->httpTimeout,
));
$http->setHeader('User-Agent', 'Bitrix');
$result = $http->post(static::TOKEN_URL, array(
'refresh_token' => $refreshToken,
'client_id' => $this->appID,
'client_secret' => $this->appSecret,
'grant_type' => 'refresh_token',
));
try
{
$arResult = Json::decode($result);
}
catch (BitrixMainArgumentException $e)
{
$arResult = array();
}
if (!empty($arResult['access_token']))
{
$this->access_token = $arResult['access_token'];
$this->accessTokenExpires = $arResult['expires_in'] + time();
if ($save && intval($userId) > 0)
{
$dbSocservUser = BitrixSocialservicesUserTable::getList(array(
'filter' => array(
'=EXTERNAL_AUTH_ID' => static::SERVICE_ID,
'=USER_ID' => $userId,
),
'select' => array('ID')
));
if ($arOauth = $dbSocservUser->fetch())
{
BitrixSocialservicesUserTable::update($arOauth['ID'], array(
'OATOKEN' => $this->access_token,
'OATOKEN_EXPIRES' => $this->accessTokenExpires)
);
}
}
return true;
}
return false;
}