- Модуль: socialservices
- Путь к файлу: ~/bitrix/modules/socialservices/classes/general/googleproxy.php
- Класс: CGoogleProxyOAuthInterface
- Вызов: CGoogleProxyOAuthInterface::getNewAccessToken
public function getNewAccessToken($refreshToken = false, $userId = 0, $save = false)
{
if($this->appID === false)
{
return false;
}
if($refreshToken === false)
{
$refreshToken = $this->refresh_token;
}
$params = array_merge(
$this->getLicenseParams(),
[
"client_id" => $this->appID,
"refresh_token"=>$refreshToken,
"grant_type"=>"refresh_token",
]
);
$http = new HttpClient(
array("socketTimeout" => $this->httpTimeout)
);
$result = $http->post(static::TOKEN_URL, $params);
try
{
$this->arResult = BitrixMainWebJson::decode($result);
}
catch(BitrixMainArgumentException $e)
{
$this->arResult = [];
}
if (isset($this->arResult["access_token"]) && $this->arResult["access_token"] <> '')
{
$this->access_token = $this->arResult["access_token"];
$this->accessTokenExpires = $this->arResult["expires_in"] + time();
if ($save && intval($userId) > 0)
{
$dbSocservUser = BitrixSocialservicesUserTable::getList([
'filter' => [
'=EXTERNAL_AUTH_ID' => static::SERVICE_ID,
'=USER_ID' => $userId,
],
'select' => ["ID"]
]);
if($arOauth = $dbSocservUser->Fetch())
{
BitrixSocialservicesUserTable::update($arOauth["ID"], [
"OATOKEN" => $this->access_token,
"OATOKEN_EXPIRES" => $this->accessTokenExpires
]
);
}
}
return true;
}
return false;
}