• Модуль: calendar
  • Путь к файлу: ~/bitrix/modules/calendar/lib/sync/google/manager.php
  • Класс: BitrixCalendarSyncGoogleManager
  • Вызов: Manager::prepareAuthEntity
private function prepareAuthEntity(int $userId): CGoogleOAuthInterface|CGoogleProxyOAuthInterface
{
	if (CSocServGoogleProxyOAuth::isProxyAuth())
	{
		$oAuth = new CSocServGoogleProxyOAuth($userId);
	}
	else
	{
		$oAuth = new CSocServGoogleOAuth($userId);
	}
	
	$oAuthEntity = $oAuth->getEntityOAuth();
	$oAuthEntity->addScope(Helper::NEED_SCOPE);
	$oAuthEntity->setUser($userId);
	
	$tokens = $this->getStorageToken($userId);
	if ($tokens)
	{
		$oAuthEntity->setToken($tokens['OATOKEN']);
		$oAuthEntity->setAccessTokenExpires($tokens['OATOKEN_EXPIRES']);
		$oAuthEntity->setRefreshToken($tokens['REFRESH_TOKEN']);
	}
	
	if (!$oAuthEntity->checkAccessToken())
	{
		$oAuthEntity->getNewAccessToken(
			$oAuthEntity->getRefreshToken(),
			$userId,
			true,
		);
	}
	
	return $oAuthEntity;
}