• Модуль: socialservices
  • Путь к файлу: ~/bitrix/modules/socialservices/classes/general/google.php
  • Класс: CGoogleOAuthInterface
  • Вызов: CGoogleOAuthInterface::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;
	}

	$this->arResult = $this->getDecodedJson(static::TOKEN_URL, [
		"client_id" => $this->appID,
		"refresh_token"=>$refreshToken,
		"grant_type"=>"refresh_token",
		"client_secret" => $this->appSecret,
	]);

	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(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;
}