- Модуль: socialservices
- Путь к файлу: ~/bitrix/modules/socialservices/classes/general/box.php
- Класс: CSocServBoxAuth
- Вызов: CSocServBoxAuth::Authorize
public function Authorize()
{
global $APPLICATION;
$APPLICATION->RestartBuffer();
$bSuccess = false;
$bProcessState = false;
$authError = SOCSERV_AUTHORISATION_ERROR;
if(
isset($_REQUEST["code"]) && $_REQUEST["code"] <> '' && CSocServAuthManager::CheckUniqueKey()
)
{
$bProcessState = true;
$this->entityOAuth = $this->getEntityOAuth($_REQUEST['code']);
if(IsModuleInstalled('bitrix24') && defined('BX24_HOST_NAME'))
{
$redirect_uri = static::CONTROLLER_URL."/redirect.php";
}
else
{
$redirect_uri = $this->getEntityOAuth()->GetRedirectURI();
}
if($this->entityOAuth->GetAccessToken($redirect_uri) !== false)
{
$boxUser = $this->entityOAuth->GetCurrentUser();
if(is_array($boxUser))
{
$arFields = self::prepareUser($boxUser);
$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(!$bProcessState)
{
unset($_REQUEST["state"]);
}
$mode = 'opener';
$addParams = true;
if(isset($_REQUEST["state"]))
{
$arState = array();
parse_str($_REQUEST["state"], $arState);
if(isset($arState['backurl']) || isset($arState['redirect_url']))
{
$url = !empty($arState['redirect_url']) ? $arState['redirect_url'] : $arState['backurl'];
if(mb_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(mb_strpos($value, $param."=") === 0)
{
unset($arUrlQuery[$key]);
break;
}
}
}
$url = (!empty($arUrlQuery)) ? $urlPath.'?'.implode("&", $arUrlQuery) : $urlPath;
}
else
{
$addParams = false;
}
}
if(isset($arState['mode']))
{
$mode = $arState['mode'];
}
}
if($authError === SOCSERV_REGISTRATION_DENY)
{
$url = (preg_match("/?/", $url)) ? $url.'&' : $url.'?';
$url .= 'auth_service_id='.static::ID.'&auth_service_error='.SOCSERV_REGISTRATION_DENY;
}
elseif($bSuccess !== true)
{
$url = (isset($urlPath)) ? $urlPath.'?auth_service_id='.static::ID.'&auth_service_error='.$authError : $APPLICATION->GetCurPageParam(('auth_service_id='.static::ID.'&auth_service_error='.$authError), $aRemove);
}
if($addParams && CModule::IncludeModule("socialnetwork") && mb_strpos($url, "current_fieldset=") === false)
{
$url = (preg_match("/?/", $url)) ? $url."¤t_fieldset=SOCSERV" : $url."?current_fieldset=SOCSERV";
}
$url = CUtil::JSEscape($url);
if($addParams)
{
$location = ($mode == "opener") ? 'if(window.opener) window.opener.location = ''.$url.''; window.close();' : ' window.location = ''.$url.'';';
}
else
{
//fix for chrome
$location = ($mode == "opener") ? 'if(window.opener) window.opener.location = window.opener.location.href + ''.$url.''; window.close();' : ' window.location = window.location.href + ''.$url.'';';
}
$JSScript = '
';
echo $JSScript;
CMain::FinalActions();
}