- Модуль: socialservices
- Путь к файлу: ~/bitrix/modules/socialservices/classes/general/apple.php
- Класс: CSocServApple
- Вызов: CSocServApple::Authorize
public function Authorize(): void
{
global $APPLICATION;
$APPLICATION->RestartBuffer();
$authError = SOCSERV_AUTHORISATION_ERROR;
if (
isset($_REQUEST['code']) && $_REQUEST['code'] <> ''
&& self::CheckUniqueKey()
)
{
if (defined('BX24_HOST_NAME') && IsModuleInstalled('bitrix24'))
{
$redirect_uri = static::CONTROLLER_URL . '/redirect.php';
}
else
{
$redirect_uri = $this->getEntityOAuth()->GetRedirectURI();
}
$entityOAuth = $this->getEntityOAuth($_REQUEST['code']);
if ($entityOAuth->GetAccessToken($redirect_uri) !== false)
{
$arUser = $entityOAuth->getCurrentUser();
if (is_array($arUser) && isset($arUser["email"]))
{
$arFields = $this->prepareUser($arUser);
$authError = $this->AuthorizeUser($arFields);
}
}
}
$bSuccess = $authError === true;
$url = ($APPLICATION->GetCurDir() == "/login/") ? "" : $APPLICATION->GetCurDir();
$aRemove = array("logout", "auth_service_error", "auth_service_id", "code", "error_reason", "error", "error_description", "check_key", "current_fieldset");
if (isset($_REQUEST["state"]) && $bSuccess)
{
$arState = array();
parse_str(html_entity_decode($_REQUEST["state"]), $arState);
if (isset($arState['backurl']) || isset($arState['redirect_url']))
{
$url = !empty($arState['redirect_url']) ? $arState['redirect_url'] : $arState['backurl'];
if (substr($url, 0, 1) !== "#")
{
$parseUrl = parse_url($url);
$urlPath = $parseUrl["path"];
$arUrlQuery = explode('&', $parseUrl["query"]);
foreach ($arUrlQuery as $key => $value)
{
foreach ($aRemove as $param)
{
if (strpos($value, $param . "=") === 0)
{
unset($arUrlQuery[$key]);
break;
}
}
}
$url = (!empty($arUrlQuery)) ? $urlPath . '?' . implode("&", $arUrlQuery) : $urlPath;
}
}
}
if ($authError === SOCSERV_REGISTRATION_DENY)
{
$url = (preg_match("/?/", $url)) ? $url . '&' : $url . '?';
$url .= 'auth_service_id=' . self::ID . '&auth_service_error=' . $authError;
}
elseif ($bSuccess !== true)
{
$url = (isset($urlPath)) ? $urlPath . '?auth_service_id=' . self::ID . '&auth_service_error=' . $authError : $GLOBALS['APPLICATION']->GetCurPageParam(('auth_service_id=' . self::ID . '&auth_service_error=' . $authError), $aRemove);
}
if (CModule::IncludeModule("socialnetwork") && strpos($url, "current_fieldset=") === false)
{
$url .= ((strpos($url, "?") === false) ? '?' : '&') . "current_fieldset=SOCSERV";
}
LocalRedirect($url);
}