• Модуль: calendar
  • Путь к файлу: ~/bitrix/modules/calendar/classes/general/calendar_sync.php
  • Класс: CCalendarSync
  • Вызов: CCalendarSync::GetGoogleAuthLink
static function GetGoogleAuthLink($userId, $type): string
{
	$isCaldavEnabled = CCalendar::IsCalDAVEnabled() && $type === 'user';
	$isGoogleApiEnabled = CCalendar::isGoogleApiEnabled() && $type === 'user';
	$googleAuthLink = '';

	if (
		Loader::includeModule('socialservices')
		&& $isGoogleApiEnabled && $isCaldavEnabled
	)
	{
		$curPath = '#googleAuthSuccess';

		if (CSocServGoogleProxyOAuth::isProxyAuth())
		{
			$client = new CSocServGoogleProxyOAuth($userId);
		}
		else
		{
			$client = new CSocServGoogleOAuth($userId);
		}

		$client->getEntityOAuth()->addScope([
			'https://www.googleapis.com/auth/calendar',
			'https://www.googleapis.com/auth/calendar.readonly'
		]);
		/** @var GoogleHelper $googleHelper */
		$googleHelper = ServiceLocator::getInstance()->get('calendar.service.google.helper');

		return $client->getUrl(
			'opener',
			null,
			[
				'BACKURL' => $curPath,
				'APIKEY' => $googleHelper->getApiKey()
			]
		);
	}

	return $googleAuthLink;
}