protected function checkActiveSocServ() { $oAuthManager = new CSocServAuthManager(); $socNetServices = $oAuthManager->GetActiveAuthServices(array()); //check active google oauth service if (empty($socNetServices['LiveIDOAuth'])) { $this->sendJsonResponse(array('error' => GetMessage('WD_DOC_INSTALL_SOCSERV_SKYDRIVE'))); } }
/** * Execute this method for check potential possibility get access token. * @return bool * @throws \Bitrix\Main\LoaderException */ public function checkAccessibleTokenService() { if (!Loader::includeModule('socialservices')) { $this->errorCollection->add(array(new Error(Loc::getMessage('DISK_GOOGLE_HANDLER_ERROR_NOT_INSTALLED_SOCSERV'), self::ERROR_NOT_INSTALLED_SOCSERV))); return false; } $authManager = new \CSocServAuthManager(); $socNetServices = $authManager->getActiveAuthServices(array()); return !empty($socNetServices[\CSocServGoogleOAuth::ID]); }
public function Authorize() { $GLOBALS["APPLICATION"]->RestartBuffer(); $bSuccess = false; if(isset($_REQUEST["code"]) && $_REQUEST["code"] <> '') { if(CSocServAuthManager::CheckUniqueKey()) { $redirect_uri = CSocServUtil::GetCurUrl('auth_service_id='.self::ID, array("code")); $appID = self::GetOption("facebook_appid"); $appSecret = self::GetOption("facebook_appsecret"); $fb = new CFacebookInterface($appID, $appSecret, $_REQUEST["code"]); if($fb->GetAccessToken($redirect_uri) !== false) { $arFBUser = $fb->GetCurrentUser(); if(isset($arFBUser["id"])) { $arFields = array( 'EXTERNAL_AUTH_ID' => self::ID, 'XML_ID' => $arFBUser["id"], 'LOGIN' => "FB_".$arFBUser["email"], 'EMAIL' => $arFBUser["email"], 'NAME'=> $arFBUser["first_name"], 'LAST_NAME'=> $arFBUser["last_name"], ); if(isset($arFBUser['picture']['data']['url']) && self::CheckPhotoURI($arFBUser['picture']['data']['url'])) if ($arPic = CFile::MakeFileArray($arFBUser['picture']['data']['url'])) $arFields["PERSONAL_PHOTO"] = $arPic; if(isset($arFBUser['birthday'])) if ($date = MakeTimeStamp($arFBUser['birthday'], "MM/DD/YYYY")) $arFields["PERSONAL_BIRTHDAY"] = ConvertTimeStamp($date); if(isset($arFBUser['gender']) && $arFBUser['gender'] != '') { if ($arFBUser['gender'] == 'male') $arFields["PERSONAL_GENDER"] = 'M'; elseif ($arFBUser['gender'] == 'female') $arFields["PERSONAL_GENDER"] = 'F'; } $arFields["PERSONAL_WWW"] = "http://www.facebook.com/".$arFBUser["id"]; $bSuccess = $this->AuthorizeUser($arFields); } } } } $aRemove = array("logout", "auth_service_error", "auth_service_id", "code", "error_reason", "error", "error_description", "check_key"); $url = $GLOBALS['APPLICATION']->GetCurPageParam(($bSuccess? '':'auth_service_id='.self::ID.'&auth_service_error=1'), $aRemove); echo ' <script type="text/javascript"> if(window.opener) window.opener.location = \''.CUtil::JSEscape($url).'\'; window.close(); </script> '; die(); }
public function Authorize($identity = false, $var = false) { if ($var === false) { $var = 'OPENID_IDENTITY_OPENID'; } $step = COpenIDClient::GetOpenIDAuthStep($var); if ($step > 0) { $obOpenID = new COpenIDClient(); if ($step == 2) { return $obOpenID->Authorize(); } elseif ($step == 1) { if ($identity === false) { $identity = $_REQUEST['OPENID_IDENTITY_OPENID']; } CSocServAuthManager::SetUniqueKey(); $return_to = CSocServUtil::GetCurUrl("auth_service_id=" . urlencode($_REQUEST["auth_service_id"]) . "&check_key=" . $_SESSION["UNIQUE_KEY"], array("SEF_APPLICATION_CUR_PAGE_URL", "auth_service_error", "auth_service_id", "login")); if ($url = $obOpenID->GetRedirectUrl($identity, $return_to)) { LocalRedirect($url, true); } else { LocalRedirect(CSocServUtil::GetCurUrl("auth_service_id=" . urlencode($_REQUEST["auth_service_id"]) . "&auth_service_error=1")); } return false; } } return false; }
public function Authorize($identity=false, $var=false) { if($var === false) $var = 'OPENID_IDENTITY_OPENID'; $step = COpenIDClient::GetOpenIDAuthStep($var); if($step > 0) { $obOpenID = new COpenIDClient(); if($step == 2) { return $obOpenID->Authorize(); } elseif($step == 1) { if($identity === false) $identity = $_REQUEST['OPENID_IDENTITY_OPENID']; CSocServAuthManager::SetUniqueKey(); $return_to = CSocServUtil::GetCurUrl("auth_service_id=".urlencode($_REQUEST["auth_service_id"])."&check_key=".$_SESSION["UNIQUE_KEY"]); if($url = $obOpenID->GetRedirectUrl($identity, $return_to)) LocalRedirect($url, true); else return false; } } return false; }
public function Authorize() { $GLOBALS["APPLICATION"]->RestartBuffer(); $bSuccess = 1; if (isset($_REQUEST["code"]) && $_REQUEST["code"] != '') { if (CSocServAuthManager::CheckUniqueKey()) { if (IsModuleInstalled('bitrix24') && defined('BX24_HOST_NAME')) { $redirect_uri = self::CONTROLLER_URL . "/redirect.php?redirect_to=" . urlencode(CSocServUtil::GetCurUrl('auth_service_id=' . self::ID, array("code"))); } else { $redirect_uri = CSocServUtil::GetCurUrl('auth_service_id=' . self::ID, array("code")); } $appID = trim(self::GetOption("facebook_appid")); $appSecret = trim(self::GetOption("facebook_appsecret")); $fb = new CFacebookInterface($appID, $appSecret, $_REQUEST["code"]); if ($fb->GetAccessToken($redirect_uri) !== false) { $arFBUser = $fb->GetCurrentUser(); if (is_array($arFBUser) && isset($arFBUser["id"])) { $email = $arFBUser["email"] != '' ? $arFBUser["email"] : ''; $arFields = array('EXTERNAL_AUTH_ID' => self::ID, 'XML_ID' => $arFBUser["id"], 'LOGIN' => "FB_" . $arFBUser["id"], 'EMAIL' => $email, 'NAME' => $arFBUser["first_name"], 'LAST_NAME' => $arFBUser["last_name"]); if (isset($arFBUser['picture']['data']['url']) && self::CheckPhotoURI($arFBUser['picture']['data']['url'])) { if ($arPic = CFile::MakeFileArray($arFBUser['picture']['data']['url'])) { $arFields["PERSONAL_PHOTO"] = $arPic; } } if (isset($arFBUser['birthday'])) { if ($date = MakeTimeStamp($arFBUser['birthday'], "MM/DD/YYYY")) { $arFields["PERSONAL_BIRTHDAY"] = ConvertTimeStamp($date); } } if (isset($arFBUser['gender']) && $arFBUser['gender'] != '') { if ($arFBUser['gender'] == 'male') { $arFields["PERSONAL_GENDER"] = 'M'; } elseif ($arFBUser['gender'] == 'female') { $arFields["PERSONAL_GENDER"] = 'F'; } } $arFields["PERSONAL_WWW"] = "http://www.facebook.com/" . $arFBUser["id"]; if (strlen(SITE_ID) > 0) { $arFields["SITE_ID"] = SITE_ID; } $bSuccess = $this->AuthorizeUser($arFields); } } } } $aRemove = array("logout", "auth_service_error", "auth_service_id", "code", "error_reason", "error", "error_description", "check_key", "current_fieldset"); $url = $GLOBALS['APPLICATION']->GetCurPageParam($bSuccess === true ? '' : 'auth_service_id=' . self::ID . '&auth_service_error=' . $bSuccess, $aRemove); if (CModule::IncludeModule("socialnetwork") && strpos($url, "current_fieldset=") === false) { $url = preg_match("/\\?/", $url) ? $url . "¤t_fieldset=SOCSERV" : $url . "?current_fieldset=SOCSERV"; } echo ' <script type="text/javascript"> if(window.opener) window.opener.location = \'' . CUtil::JSEscape($url) . '\'; window.close(); </script> '; die; }
public function Authorize() { $GLOBALS["APPLICATION"]->RestartBuffer(); $bSuccess = 1; $appID = trim(self::GetOption("twitter_key")); $appSecret = trim(self::GetOption("twitter_secret")); if (!isset($_REQUEST["oauth_token"]) || $_REQUEST["oauth_token"] == '') { $tw = new CTwitterInterface($appID, $appSecret); $callback = CSocServUtil::GetCurUrl('auth_service_id=' . self::ID); //$callback = 'http://algerman.sam:6448/script.php?auth_service_id='.self::ID; if ($tw->GetRequestToken($callback)) { $tw->RedirectAuthUrl(); } } elseif (CSocServAuthManager::CheckUniqueKey()) { $tw = new CTwitterInterface($appID, $appSecret, $_REQUEST["oauth_token"], $_REQUEST["oauth_verifier"]); if (($arResult = $tw->GetAccessToken()) !== false && $arResult["user_id"] != '') { $twUser = $tw->GetUserInfo($arResult["user_id"]); $first_name = $last_name = ""; if ($twUser["name"] != '') { $aName = explode(" ", $twUser["name"]); $first_name = $aName[0]; if (isset($aName[1])) { $last_name = $aName[1]; } } $arFields = array('EXTERNAL_AUTH_ID' => self::ID, 'XML_ID' => $arResult["user_id"], 'LOGIN' => $arResult["screen_name"], 'NAME' => $first_name, 'LAST_NAME' => $last_name); if (isset($twUser["profile_image_url"]) && self::CheckPhotoURI($twUser["profile_image_url"])) { if ($arPic = CFile::MakeFileArray($twUser["profile_image_url"])) { $arFields["PERSONAL_PHOTO"] = $arPic; } } $arFields["PERSONAL_WWW"] = "https://twitter.com/" . $arResult["screen_name"]; if (strlen(SITE_ID) > 0) { $arFields["SITE_ID"] = SITE_ID; } if (COption::GetOptionString('socialservices', 'last_twit_id', '1') == 1) { if (isset($twUser["status"]["id_str"])) { COption::SetOptionString('socialservices', 'last_twit_id', $twUser["status"]["id_str"]); } } $bSuccess = $this->AuthorizeUser($arFields); } } $aRemove = array("logout", "auth_service_error", "auth_service_id", "oauth_token", "oauth_verifier", "check_key", "current_fieldset"); $url = $GLOBALS['APPLICATION']->GetCurPageParam($bSuccess === true ? '' : 'auth_service_id=' . self::ID . '&auth_service_error=' . $bSuccess, $aRemove); if (CModule::IncludeModule("socialnetwork")) { $url = preg_match("/\\?/", $url) ? $url . "¤t_fieldset=SOCSERV" : $url . "?current_fieldset=SOCSERV"; } echo ' <script type="text/javascript"> if(window.opener) window.opener.location = \'' . CUtil::JSEscape($url) . '\'; window.close(); </script> '; die; }
public function Authorize() { $GLOBALS["APPLICATION"]->RestartBuffer(); $bSuccess = false; $appID = self::GetOption("twitter_key"); $appSecret = self::GetOption("twitter_secret"); if(!isset($_REQUEST["oauth_token"]) || $_REQUEST["oauth_token"] == '') { $tw = new CTwitterInterface($appID, $appSecret); $callback = CSocServUtil::GetCurUrl('auth_service_id='.self::ID); if($tw->GetRequestToken($callback)) $tw->RedirectAuthUrl(); } elseif(CSocServAuthManager::CheckUniqueKey()) { $tw = new CTwitterInterface($appID, $appSecret, $_REQUEST["oauth_token"], $_REQUEST["oauth_verifier"]); if(($arResult = $tw->GetAccessToken()) !== false && $arResult["user_id"] <> '') { $twUser = $tw->GetUserInfo($arResult["user_id"]); $first_name = $last_name = ""; if($twUser["name"] <> '') { $aName = explode(" ", $twUser["name"]); $first_name = $aName[0]; if(isset($aName[1])) $last_name = $aName[1]; } $arFields = array( 'EXTERNAL_AUTH_ID' => self::ID, 'XML_ID' => $arResult["user_id"], 'LOGIN' => $arResult["screen_name"], 'NAME'=> $first_name, 'LAST_NAME'=> $last_name, ); $arFields["PERSONAL_WWW"] = "https://twitter.com/".$twUser["screen_name"]; $bSuccess = $this->AuthorizeUser($arFields); } } $aRemove = array("logout", "auth_service_error", "auth_service_id", "oauth_token", "oauth_verifier", "check_key"); $url = $GLOBALS['APPLICATION']->GetCurPageParam(($bSuccess? '':'auth_service_id='.self::ID.'&auth_service_error=1'), $aRemove); echo ' <script type="text/javascript"> if(window.opener) window.opener.location = \''.CUtil::JSEscape($url).'\'; window.close(); </script> '; die(); }
} } } } } if (defined("HTML_PAGES_FILE") && !defined("ERROR_404")) { $arResult["~USER_LOGIN"] = ""; } else { $arResult["~USER_LOGIN"] = $_COOKIE[COption::GetOptionString("main", "cookie_name", "BITRIX_SM") . "_LOGIN"]; } $arResult["USER_LOGIN"] = $arResult["LAST_LOGIN"] = htmlspecialcharsbx($arResult["~USER_LOGIN"]); $arResult["~LAST_LOGIN"] = $arResult["~USER_LOGIN"]; $arResult["AUTH_SERVICES"] = false; $arResult["CURRENT_SERVICE"] = false; if (!$USER->IsAuthorized() && CModule::IncludeModule("socialservices")) { $oAuthManager = new CSocServAuthManager(); $arServices = $oAuthManager->GetActiveAuthServices($arResult); if (!empty($arServices)) { $arResult["AUTH_SERVICES"] = $arServices; if (isset($_REQUEST["auth_service_id"]) && $_REQUEST["auth_service_id"] != '' && isset($arResult["AUTH_SERVICES"][$_REQUEST["auth_service_id"]])) { $arResult["CURRENT_SERVICE"] = $_REQUEST["auth_service_id"]; if (isset($_REQUEST["auth_service_error"]) && $_REQUEST["auth_service_error"] != '') { $arResult['ERROR_MESSAGE'] = $oAuthManager->GetError($arResult["CURRENT_SERVICE"], $_REQUEST["auth_service_error"]); } elseif (!$oAuthManager->Authorize($_REQUEST["auth_service_id"])) { $ex = $APPLICATION->GetException(); if ($ex) { $arResult['ERROR_MESSAGE'] = $ex->GetString(); } } } }
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 (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; } 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") && 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 = ' <script type="text/javascript"> ' . $location . ' </script> '; echo $JSScript; die; }
public function Authorize() { global $APPLICATION; $APPLICATION->RestartBuffer(); $bSuccess = false; $authError = SOCSERV_AUTHORISATION_ERROR; if (isset($_REQUEST["code"]) && $_REQUEST["code"] != '' && CSocServAuthManager::CheckUniqueKey()) { if (IsModuleInstalled('bitrix24') && defined('BX24_HOST_NAME')) { $redirect_uri = static::CONTROLLER_URL . "/redirect.php"; } else { $redirect_uri = CSocServUtil::ServerName() . "/bitrix/tools/oauth/google.php"; } $this->entityOAuth = $this->getEntityOAuth($_REQUEST['code']); if ($this->entityOAuth->GetAccessToken($redirect_uri) !== false) { $arGoogleUser = $this->entityOAuth->GetCurrentUser(); if (is_array($arGoogleUser)) { $first_name = ""; $last_name = ""; if (is_array($arGoogleUser['name'])) { $first_name = $arGoogleUser['name']['givenName']; $last_name = $arGoogleUser['name']['familyName']; } elseif ($arGoogleUser['name'] != '') { $aName = explode(" ", $arGoogleUser['name']); if ($arGoogleUser['given_name'] != '') { $first_name = $arGoogleUser['given_name']; } else { $first_name = $aName[0]; } if ($arGoogleUser['family_name'] != '') { $last_name = $arGoogleUser['family_name']; } elseif (isset($aName[1])) { $last_name = $aName[1]; } } $id = $arGoogleUser['id']; $email = $arGoogleUser['email']; if (strlen($arGoogleUser['email']) > 0) { $dbRes = \Bitrix\Main\UserTable::getList(array('filter' => array('=EXTERNAL_AUTH_ID' => 'socservices', '=XML_ID' => $email), 'select' => array('ID'), 'limit' => 1)); if ($dbRes->fetch()) { $id = $email; } } $arFields = array('EXTERNAL_AUTH_ID' => static::ID, 'XML_ID' => $id, 'LOGIN' => static::LOGIN_PREFIX . $id, 'EMAIL' => $email, 'NAME' => $first_name, 'LAST_NAME' => $last_name, 'OATOKEN' => $this->entityOAuth->getToken(), 'OATOKEN_EXPIRES' => $this->entityOAuth->getAccessTokenExpires(), 'REFRESH_TOKEN' => $this->entityOAuth->getRefreshToken()); if ($arGoogleUser['gender'] != '') { if ($arGoogleUser['gender'] == 'male') { $arFields["PERSONAL_GENDER"] = 'M'; } elseif ($arGoogleUser['gender'] == 'female') { $arFields["PERSONAL_GENDER"] = 'F'; } } if (isset($arGoogleUser['picture']) && static::CheckPhotoURI($arGoogleUser['picture'])) { $arGoogleUser['picture'] = preg_replace("/\\?.*\$/", '', $arGoogleUser['picture']); $arPic = CFile::MakeFileArray($arGoogleUser['picture']); if ($arPic) { $arFields["PERSONAL_PHOTO"] = $arPic; } } $arFields["PERSONAL_WWW"] = isset($arGoogleUser['link']) ? $arGoogleUser['link'] : $arGoogleUser['url']; if (strlen(SITE_ID) > 0) { $arFields["SITE_ID"] = SITE_ID; } $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"); $mode = 'opener'; if (isset($_REQUEST["state"])) { $arState = array(); parse_str($_REQUEST["state"], $arState); if (isset($arState['backurl']) || isset($arState['redirect_url'])) { $parseUrl = parse_url(!empty($arState['redirect_url']) ? $arState['redirect_url'] : $arState['backurl']); $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 (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 (CModule::IncludeModule("socialnetwork") && strpos($url, "current_fieldset=") === false) { $url = preg_match("/\\?/", $url) ? $url . "¤t_fieldset=SOCSERV" : $url . "?current_fieldset=SOCSERV"; } $url = CUtil::JSEscape($url); $location = $mode == "opener" ? 'if(window.opener) window.opener.location = \'' . $url . '\'; window.close();' : ' window.location = \'' . $url . '\';'; $JSScript = ' <script type="text/javascript"> ' . $location . ' </script> '; echo $JSScript; die; }
public function Authorize() { global $APPLICATION; $APPLICATION->RestartBuffer(); $bSuccess = SOCSERV_AUTHORISATION_ERROR; if((isset($_REQUEST["code"]) && $_REQUEST["code"] <> '') && CSocServAuthManager::CheckUniqueKey()) { if(IsModuleInstalled('freetrix24') && defined('BX24_HOST_NAME')) $redirect_uri = self::CONTROLLER_URL."/redirect.php"; else $redirect_uri = CSocServUtil::ServerName()."/freetrix/tools/oauth/google.php"; $appID = trim(self::GetOption("google_appid")); $appSecret = trim(self::GetOption("google_appsecret")); $gAuth = new CGoogleOAuthInterface($appID, $appSecret, $_REQUEST["code"]); $this->entityOAuth = $gAuth; if($gAuth->GetAccessToken($redirect_uri) !== false) { $arGoogleUser = $gAuth->GetCurrentUser(); if(is_array($arGoogleUser) && ($arGoogleUser['email'] <> '')) { $first_name = $last_name = $gender = ""; if($arGoogleUser['name'] <> '') { $aName = explode(" ", $arGoogleUser['name']); if($arGoogleUser['given_name'] <> '') $first_name = $arGoogleUser['given_name']; else $first_name = $aName[0]; if($arGoogleUser['family_name'] <> '') $last_name = $arGoogleUser['family_name']; elseif(isset($aName[1])) $last_name = $aName[1]; } $email = $arGoogleUser['email']; if($arGoogleUser['gender'] <> '') if($arGoogleUser['gender'] == 'male') $gender = 'M'; elseif($arGoogleUser['gender'] == 'female') $gender = 'F'; $arFields = array( 'EXTERNAL_AUTH_ID' => self::ID, 'XML_ID' => $email, 'LOGIN' => "G_".$email, 'EMAIL' => $email, 'NAME'=> $first_name, 'LAST_NAME'=> $last_name ); if($gender != "") $arFields['PERSONAL_GENDER'] = $gender; if(isset($arGoogleUser['picture']) && self::CheckPhotoURI($arGoogleUser['picture'])) if($arPic = CFile::MakeFileArray($arGoogleUser['picture'])) $arFields["PERSONAL_PHOTO"] = $arPic; $arFields["PERSONAL_WWW"] = $arGoogleUser['link']; if(isset($arGoogleUser['access_token'])) $arFields["OATOKEN"] = $arGoogleUser['access_token']; if(isset($arGoogleUser['refresh_token'])) $arFields["REFRESH_TOKEN"] = $arGoogleUser['refresh_token']; if(isset($arGoogleUser['expires_in'])) $arFields["OATOKEN_EXPIRES"] = $arGoogleUser['expires_in']; if(strlen(SITE_ID) > 0) $arFields["SITE_ID"] = SITE_ID; $bSuccess = $this->AuthorizeUser($arFields); } } } $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"); $mode = 'opener'; if(isset($_REQUEST["state"])) { $arState = array(); parse_str($_REQUEST["state"], $arState); if(isset($arState['backurl'])) { $parseUrl = parse_url($arState['backurl']); $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(isset($arState['mode'])) { $mode = $arState['mode']; } } if($bSuccess === SOCSERV_REGISTRATION_DENY) { $url = (preg_match("/\?/", $url)) ? $url.'&' : $url.'?'; $url .= 'auth_service_id='.self::ID.'&auth_service_error='.SOCSERV_REGISTRATION_DENY; } elseif($bSuccess !== true) $url = (isset($urlPath)) ? $urlPath.'?auth_service_id='.self::ID.'&auth_service_error='.$bSuccess : $APPLICATION->GetCurPageParam(('auth_service_id='.self::ID.'&auth_service_error='.$bSuccess), $aRemove); if(CModule::IncludeModule("socialnetwork") && strpos($url, "current_fieldset=") === false) $url = (preg_match("/\?/", $url)) ? $url."¤t_fieldset=SOCSERV" : $url."?current_fieldset=SOCSERV"; $url = CUtil::JSEscape($url); $location = ($mode == "opener") ? 'if(window.opener) window.opener.location = \''.$url.'\'; window.close();' : ' window.location = \''.$url.'\';'; $JSScript = ' <script type="text/javascript"> '.$location.' </script> '; echo $JSScript; die(); }
<? /* This is callback page for Google OAuth 2.0 authentication. Google redirects only to specific back url set in the OAuth application. The page opens in popup window after user authorized on Google. */ define("NOT_CHECK_PERMISSIONS", true); if(isset($_REQUEST["state"]) && is_string($_REQUEST["state"])) { $arState = array(); parse_str($_REQUEST["state"], $arState); if(isset($arState['site_id'])) { $site = substr(preg_replace("/[^a-z0-9_]/i", "", $arState['site_id']), 0, 2); define("SITE_ID", $site); } } require_once($_SERVER['DOCUMENT_ROOT']."/freetrix/modules/main/include/prolog_before.php"); if(CModule::IncludeModule("socialservices")) { $oAuthManager = new CSocServAuthManager(); $oAuthManager->Authorize("Freetrix24OAuth"); } require_once($_SERVER['DOCUMENT_ROOT']."/freetrix/modules/main/include/epilog_after.php"); ?>
function check_socnet() { if (!CModule::IncludeModule('socialservices')) return $this->Result(null, GetMessage("MAIN_SC_NO_SOCIAL_MODULE")); $oAuthManager = new CSocServAuthManager(); $arActiveSocServ = $oAuthManager->GetActiveAuthServices(array()); if (count($arActiveSocServ)) return true; return $this->Result(null, GetMessage("MAIN_SC_NO_SOCIAL_SERVICES")); }
public static function getAuthorizeLink($engine) { $interface = static::getEngine()->getInterface(); if (!$interface->checkAccessToken()) { if ($interface->getNewAccessToken()) { static::getEngine()->setAuthSettings($interface->getResult()); } } $checkKey = ""; if (Loader::includeModule("socialservices")) { $checkKey = \CSocServAuthManager::GetUniqueKey(); } return static::SERVICE_URL . static::REGISTER . "?action=authorize&engine=" . urlencode($engine) . "&client_id=" . urlencode(static::getEngine()->getClientId()) . "&auth=" . urlencode($interface->getToken()) . "&check_key=" . urlencode($checkKey); }
} } } $arResult["~LAST_LOGIN"] = $_COOKIE[COption::GetOptionString("main", "cookie_name", "BITRIX_SM") . "_LOGIN"]; $arResult["LAST_LOGIN"] = htmlspecialcharsbx($arResult["~LAST_LOGIN"]); $arResult["STORE_PASSWORD"] = COption::GetOptionString("main", "store_password", "Y") == "Y" ? "Y" : "N"; $arResult["NEW_USER_REGISTRATION"] = COption::GetOptionString("main", "new_user_registration", "N") == "Y" ? "Y" : "N"; $arResult["ALLOW_SOCSERV_AUTHORIZATION"] = COption::GetOptionString("main", "allow_socserv_authorization", "Y") != "N" ? "Y" : "N"; $arResult["AUTH_SERVICES"] = false; $arResult["CURRENT_SERVICE"] = false; $arResult["FOR_INTRANET"] = false; if (IsModuleInstalled("intranet") || IsModuleInstalled("rest")) { $arResult["FOR_INTRANET"] = true; } if (!$USER->IsAuthorized() && CModule::IncludeModule("socialservices") && $arResult["ALLOW_SOCSERV_AUTHORIZATION"] == 'Y') { $oAuthManager = new CSocServAuthManager(); $arServices = $oAuthManager->GetActiveAuthServices(array('BACKURL' => $arResult['~BACKURL'], 'FOR_INTRANET' => $arResult['FOR_INTRANET'])); if (!empty($arServices)) { $arResult["AUTH_SERVICES"] = $arServices; if (isset($_REQUEST["auth_service_id"]) && $_REQUEST["auth_service_id"] != '' && isset($arResult["AUTH_SERVICES"][$_REQUEST["auth_service_id"]])) { $arResult["CURRENT_SERVICE"] = $_REQUEST["auth_service_id"]; if (isset($_REQUEST["auth_service_error"]) && $_REQUEST["auth_service_error"] != '') { $arResult['ERROR_MESSAGE'] = $oAuthManager->GetError($arResult["CURRENT_SERVICE"], $_REQUEST["auth_service_error"]); } elseif (!$oAuthManager->Authorize($_REQUEST["auth_service_id"])) { $ex = $APPLICATION->GetException(); if ($ex) { $arResult['ERROR_MESSAGE'] = $ex->GetString(); } } } }
public function Authorize() { $GLOBALS["APPLICATION"]->RestartBuffer(); $bSuccess = 1; if((isset($_REQUEST["code"]) && $_REQUEST["code"] <> '') && CSocServAuthManager::CheckUniqueKey()) { $redirect_uri = CSocServUtil::ServerName()."/bitrix/tools/oauth/google.php"; $appID = trim(self::GetOption("google_appid")); $appSecret = trim(self::GetOption("google_appsecret")); $gAuth = new CGoogleOAuthInterface($appID, $appSecret, $_REQUEST["code"]); if($gAuth->GetAccessToken($redirect_uri) !== false) { $arGoogleUser = $gAuth->GetCurrentUser(); if($arGoogleUser['feed']['author']['0']['email']['$t'] <> '') { $first_name = $last_name = ""; if($arGoogleUser['feed']['author']['0']['name']['$t'] <> '') { $aName = explode(" ", $arGoogleUser['feed']['author']['0']['name']['$t']); $first_name = $aName[0]; if(isset($aName[1])) $last_name = $aName[1]; } $email = $arGoogleUser['feed']['author']['0']['email']['$t']; $arFields = array( 'EXTERNAL_AUTH_ID' => self::ID, 'XML_ID' => $email, 'LOGIN' => "G_".$email, 'EMAIL' => $email, 'NAME'=> $first_name, 'LAST_NAME'=> $last_name, ); $arFields["PERSONAL_WWW"] = "https://accounts.google.com"; $bSuccess = $this->AuthorizeUser($arFields); } } } $url = ($GLOBALS["APPLICATION"]->GetCurDir() == "/login/") ? "/auth/" : $GLOBALS["APPLICATION"]->GetCurDir(); if(isset($_REQUEST["state"])) { $arState = array(); parse_str($_REQUEST["state"], $arState); if(isset($arState['backurl'])) $url = parse_url($arState['backurl'], PHP_URL_PATH); } $aRemove = array("logout", "auth_service_error", "auth_service_id", "code", "error_reason", "error", "error_description", "check_key"); if(CModule::IncludeModule("socialnetwork")) $url = (preg_match("/\?/", $url)) ? $url."¤t_fieldset=SOCSERV" : $url."?current_fieldset=SOCSERV"; if($bSuccess !== true) $url = $GLOBALS['APPLICATION']->GetCurPageParam(('auth_service_id='.self::ID.'&auth_service_error='.$bSuccess), $aRemove); if($bSuccess === 2) $url = '/?auth_service_id='.self::ID.'&auth_service_error='.$bSuccess; echo ' <script type="text/javascript"> if(window.opener) window.opener.location = \''.CUtil::JSEscape($url).'\'; window.close(); </script> '; die(); }
public function Validate() { if (CSocServAuthManager::CheckUniqueKey()) { if ($arOpenidServerTags = $this->GetOpenIDServerTags($_GET['openid_identity'])) { $arParams = array('openid.assoc_handle' => $_GET['openid_assoc_handle'], 'openid.signed' => $_GET['openid_signed'], 'openid.sig' => $_GET['openid_sig']); $arSigned = explode(',', $_GET['openid_signed']); foreach ($arSigned as $s) { $arParams['openid.' . $s] = $_GET['openid_' . str_replace('.', '_', $s)]; } $arParams['openid.mode'] = 'check_authentication'; if (isset($_SESSION['BX_OPENID_RETURN_TO'])) { $arParams['openid.return_to'] = $_SESSION['BX_OPENID_RETURN_TO']; unset($_SESSION['BX_OPENID_RETURN_TO']); } $str = CHTTP::sPost($arOpenidServerTags['server'], $arParams, true); if (preg_match('/is_valid\\s*\\:\\s*/' . BX_UTF_PCRE_MODIFIER, $str)) { return array('server' => $arOpenidServerTags['server'], 'identity' => $_GET['openid_identity']); } else { $GLOBALS['APPLICATION']->ThrowException(GetMessage('OPENID_CLIENT_ERROR_AUTH')); } } } // self::CleanParam('ERROR'); $GLOBALS['APPLICATION']->ThrowException(GetMessage('OPENID_CLIENT_ERROR_AUTH')); return false; }
public static function SendSocialservicesMessages() { $oAuthManager = new CSocServAuthManager(); $arActiveSocServ = $oAuthManager->GetActiveAuthServices(array()); if (!(isset($arActiveSocServ["Twitter"]) && isset($arActiveSocServ["Twitter"]["__active"])) || !function_exists("hash_hmac")) { return false; } $ttl = 86400; $cache_id = 'socserv_mes_user'; $obCache = new CPHPCache(); $cache_dir = '/bx/socserv_mes_user'; $arSocServMessage = array(); if ($obCache->InitCache($ttl, $cache_id, $cache_dir)) { $arSocServMessage = $obCache->GetVars(); } else { $dbSocServMessage = CSocServMessage::GetList(array(), array('SUCCES_SENT' => 'N'), false, array("nTopCount" => 5), array("ID", "SOCSERV_USER_ID", "PROVIDER", "MESSAGE")); while ($arSocMessage = $dbSocServMessage->Fetch()) { $arSocServMessage[] = $arSocMessage; } if (empty($arSocServMessage)) { if ($obCache->StartDataCache()) { $obCache->EndDataCache($arSocServMessage); } } } if (is_array($arSocServMessage) && !empty($arSocServMessage)) { foreach ($arSocServMessage as $arSocMessage) { $arResult = CSocServAuthManager::SendUserMessage($arSocMessage['SOCSERV_USER_ID'], $arSocMessage['PROVIDER'], $arSocMessage['MESSAGE'], $arSocMessage['ID']); if ($arResult !== false && is_array($arResult) && !preg_match("/error/i", join(",", array_keys($arResult)))) { self::MarkMessageAsSent($arSocMessage['ID']); } } } return "CSocServAuthManager::SendSocialservicesMessages();"; }
<?php /* This is callback page for Dropbox OAuth 2.0 authentication. Dropbox redirects only to specific back url set in the OAuth application. The page opens in popup window after user authorized on Dropbox. */ define("NOT_CHECK_PERMISSIONS", true); require_once $_SERVER['DOCUMENT_ROOT'] . "/bitrix/modules/main/include/prolog_before.php"; if (CModule::IncludeModule("socialservices") && CSocServAuthManager::CheckUniqueKey()) { if (isset($_REQUEST["authresult"])) { $engine = $_REQUEST["engine"]; \Bitrix\Seo\Service::clearAuth($engine, true); ?> <script type="text/javascript"> opener.location.reload(); window.close(); </script> <?php } else { $result = array(); $state = $_REQUEST["state"]; if (isset($_REQUEST["code"]) && $_REQUEST["code"] != '') { $engine = \Bitrix\Seo\Service::getEngine(); $engine->getInterface()->setCode($_REQUEST["code"]); if ($engine->getInterface()->GetAccessToken() !== false) { $engine->setAuthSettings($engine->getInterface()->getResult()); $result["result"] = "ok"; } else { $result = $engine->getInterface()->getError(); }
<?php /* This is callback page for MyMailRu OAuth 2.0 authentication. MyMailRu redirects only to specific back url set in the OAuth application. The page opens in popup window after user authorized on MyMailRu. */ define("NOT_CHECK_PERMISSIONS", true); if (isset($_REQUEST["state"]) && is_string($_REQUEST["state"])) { $arState = array(); parse_str($_REQUEST["state"], $arState); if (isset($arState['site_id']) && is_string($arState['site_id'])) { $site = substr(preg_replace("/[^a-z0-9_]/i", "", $arState['site_id']), 0, 2); define("SITE_ID", $site); } } require_once $_SERVER['DOCUMENT_ROOT'] . "/bitrix/modules/main/include/prolog_before.php"; if (CModule::IncludeModule("socialservices")) { $oAuthManager = new CSocServAuthManager(); $oAuthManager->Authorize("Odnoklassniki"); } require_once $_SERVER['DOCUMENT_ROOT'] . "/bitrix/modules/main/include/epilog_after.php";
public function gadgetAuthorize() { global $APPLICATION; $APPLICATION->RestartBuffer(); if (isset($_REQUEST["code"]) && $_REQUEST["code"] != '' && CSocServAuthManager::CheckUniqueKey()) { CUserOptions::SetOption('socialservices', 'bitrix24_task_planer_gadget_code', $_REQUEST["code"]); } $url = CSocServUtil::ServerName() . BX_ROOT; $mode = 'opener'; $url = CUtil::JSEscape($url); $location = $mode == "opener" ? 'if(window.opener) window.opener.location = \'' . $url . '\'; window.close();' : ' window.location = \'' . $url . '\';'; $JSScript = ' <script type="text/javascript"> ' . $location . ' </script> '; echo $JSScript; die; }
<?php /* This is callback page for Bitrix24.Net OAuth 2.0 authentication. Bitrix24.Net redirects only to specific back url set in the OAuth application. The page opens in popup window after user authorized on Bitrix24.Net. */ define("NOT_CHECK_PERMISSIONS", true); if (isset($_REQUEST["state"]) && is_string($_REQUEST["state"])) { $arState = array(); parse_str($_REQUEST["state"], $arState); if (isset($arState['site_id']) && is_string($arState['site_id'])) { $site = substr(preg_replace("/[^a-z0-9_]/i", "", $arState['site_id']), 0, 2); define("SITE_ID", $site); } } require_once $_SERVER['DOCUMENT_ROOT'] . "/bitrix/modules/main/include/prolog_before.php"; if (CModule::IncludeModule("socialservices")) { $oAuthManager = new CSocServAuthManager(); $oAuthManager->Authorize("Bitrix24Net"); } require_once $_SERVER['DOCUMENT_ROOT'] . "/bitrix/modules/main/include/epilog_after.php";
public function Authorize() { $GLOBALS["APPLICATION"]->RestartBuffer(); $bSuccess = SOCSERV_AUTHORISATION_ERROR; if((isset($_REQUEST["code"]) && $_REQUEST["code"] <> '') && CSocServAuthManager::CheckUniqueKey()) { if(IsModuleInstalled('bitrix24') && defined('BX24_HOST_NAME')) $redirect_uri = self::CONTROLLER_URL."/redirect.php"; else $redirect_uri = CSocServUtil::ServerName().$GLOBALS['APPLICATION']->GetCurPage(true).'?auth_service_id='.self::ID; $appID = trim(self::GetOption("vkontakte_appid")); $appSecret = trim(self::GetOption("vkontakte_appsecret")); $gAuth = new CVKontakteOAuthInterface($appID, $appSecret, $_REQUEST["code"]); if($gAuth->GetAccessToken($redirect_uri) !== false) { $arVkUser = $gAuth->GetCurrentUser(); if(is_array($arVkUser) && ($arVkUser['response']['0']['uid'] <> '')) { $first_name = $last_name = $gender = ""; if($arVkUser['response']['0']['first_name'] <> '') { $first_name = $arVkUser['response']['0']['first_name']; } if($arVkUser['response']['0']['last_name'] <> '') { $last_name = $arVkUser['response']['0']['last_name']; } if(isset($arVkUser['response']['0']['sex']) && $arVkUser['response']['0']['sex'] != '') { if ($arVkUser['response']['0']['sex'] == '2') $gender = 'M'; elseif ($arVkUser['response']['0']['sex'] == '1') $gender = 'F'; } $arFields = array( 'EXTERNAL_AUTH_ID' => self::ID, 'XML_ID' => $arVkUser['response']['0']['uid'], 'LOGIN' => "VKuser".$arVkUser['response']['0']['uid'], 'NAME'=> $first_name, 'LAST_NAME'=> $last_name, 'PERSONAL_GENDER' => $gender, ); if(isset($arVkUser['response']['0']['photo_big']) && self::CheckPhotoURI($arVkUser['response']['0']['photo_big'])) if ($arPic = CFile::MakeFileArray($arVkUser['response']['0']['photo_big'])) $arFields["PERSONAL_PHOTO"] = $arPic; if(isset($arVkUser['response']['0']['bdate'])) if ($date = MakeTimeStamp($arVkUser['response']['0']['bdate'], "DD.MM.YYYY")) $arFields["PERSONAL_BIRTHDAY"] = ConvertTimeStamp($date); $arFields["PERSONAL_WWW"] = "http://vk.com/id".$arVkUser['response']['0']['uid']; if(strlen(SITE_ID) > 0) $arFields["SITE_ID"] = SITE_ID; $bSuccess = $this->AuthorizeUser($arFields); } } } $url = ($GLOBALS["APPLICATION"]->GetCurDir() == "/login/") ? "" : $GLOBALS["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"])) { $arState = array(); parse_str($_REQUEST["state"], $arState); if(isset($arState['backurl'])) { $parseUrl = parse_url($arState['backurl']); $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($bSuccess === SOCSERV_REGISTRATION_DENY) { $url = (preg_match("/\?/", $url)) ? $url.'&' : $url.'?'; $url .= 'auth_service_id='.self::ID.'&auth_service_error='.$bSuccess; } elseif($bSuccess !== true) $url = (isset($urlPath)) ? $urlPath.'?auth_service_id='.self::ID.'&auth_service_error='.$bSuccess : $GLOBALS['APPLICATION']->GetCurPageParam(('auth_service_id='.self::ID.'&auth_service_error='.$bSuccess), $aRemove); if(CModule::IncludeModule("socialnetwork") && strpos($url, "current_fieldset=") === false) $url = (preg_match("/\?/", $url)) ? $url."¤t_fieldset=SOCSERV" : $url."?current_fieldset=SOCSERV"; echo ' <script type="text/javascript"> if(window.opener) window.opener.location = \''.CUtil::JSEscape($url).'\'; window.close(); </script> '; die(); }
$module_id = "socialservices"; CModule::IncludeModule($module_id); $GLOBALS["APPLICATION"]->SetAdditionalCSS("/bitrix/js/socialservices/css/ss.css"); $arSites = array(); $arSiteList = array(''); $dbSites = CSite::GetList(($b="sort"), ($o="asc"), array("ACTIVE" => "Y")); while ($arSite = $dbSites->Fetch()) { $arSites[] = $arSite; $arSiteList[] = $arSite['ID']; } $oAuthManager = new CSocServAuthManager(); $arOptions = $oAuthManager->GetSettings(); $aTabs = array( array("DIV" => "edit1", "TAB" => GetMessage("MAIN_TAB_SET"), "ICON" => "", "TITLE" => GetMessage("MAIN_TAB_TITLE_SET")), ); $tabControl = new CAdminTabControl("tabControl", $aTabs); if($_SERVER["REQUEST_METHOD"] == "POST" && $_POST["Update"].$_POST["Apply"].$_POST["RestoreDefaults"] <> '' && check_bitrix_sessid()) { if($_POST["RestoreDefaults"] <> '') { COption::RemoveOption($module_id); } else
{ CUtil::JSPostUnescape(); if($_REQUEST['action'] == "getuserdata" || $_REQUEST['action'] == 'getsettings') { $serializedSocservUser = CUserOptions::GetOption("socialservices", "user_socserv_array", '', $userId); if(CheckSerializedData($serializedSocservUser)) $arResult['SOCSERVARRAY'] = unserialize($serializedSocservUser); if(!isset($arResult['SOCSERVARRAY']) || !is_array($arResult['SOCSERVARRAY'])) $arResult['SOCSERVARRAY'] = ''; if($_REQUEST['checkEnabled'] == 'true') $arResult['ENABLED'] = CUserOptions::GetOption("socialservices", "user_socserv_enable", "N", $userId); $arResult['STARTSEND'] = CUserOptions::GetOption("socialservices", "user_socserv_start_day", "N", $userId); $arResult['ENDSEND'] = CUserOptions::GetOption("socialservices", "user_socserv_end_day", "N", $userId); $arResult['STARTTEXT'] = CUserOptions::GetOption("socialservices", "user_socserv_start_text", GetMessage("JS_CORE_SS_WORKDAY_START"), $userId); $arResult['ENDTEXT'] = CUserOptions::GetOption("socialservices", "user_socserv_end_text", GetMessage("JS_CORE_SS_WORKDAY_END"), $userId); $arResult['SOCSERVARRAYALL'] = CSocServAuthManager::GetUserArrayForSendMessages($userId); $arResult['USER_ID'] = $userId; $tooltipPathToUser = COption::GetOptionString("main", "TOOLTIP_PATH_TO_USER", false, SITE_ID); if($tooltipPathToUser) $pathToUser = str_replace("#user_id#", $userId, $tooltipPathToUser)."edit/?current_fieldset=SOCSERV#soc-serv-title-id"; else $pathToUser = "******"; $arResult["SETUP_MESSAGE"] = GetMessage(("JS_CORE_SS_SETUP_ACCOUNT"), array("#class#" => "class=\"bx-ss-soc-serv-setup-link\"", "#link#" => $pathToUser)); if($_REQUEST['action'] == "getuserdata") { echo CUtil::PhpToJSObject($arResult); } else { $t = filemtime($_SERVER["DOCUMENT_ROOT"].BX_ROOT."/js/socialservices/ss_timeman.js");
public function Authorize() { $GLOBALS["APPLICATION"]->RestartBuffer(); $bSuccess = false; if((isset($_REQUEST["code"]) && $_REQUEST["code"] <> '') && CSocServAuthManager::CheckUniqueKey()) { $redirect_uri= CSocServUtil::GetCurUrl('auth_service_id='.self::ID, array("code")); $appID = trim(self::GetOption("liveid_appid")); $appSecret = trim(self::GetOption("liveid_appsecret")); $gAuth = new CLiveIDOAuthInterface($appID, $appSecret, $_REQUEST["code"]); if($gAuth->GetAccessToken($redirect_uri) !== false) { $arLiveIDUser = $gAuth->GetCurrentUser(); if ($arLiveIDUser['id'] <> '') { $email = $first_name = $last_name = ""; $login = "******".$arLiveIDUser['id']; $uId = $arLiveIDUser['id']; if($arLiveIDUser['first_name'] <> '') $first_name = $arLiveIDUser['first_name']; if($arLiveIDUser['last_name'] <> '') $last_name = $arLiveIDUser['last_name']; if($arLiveIDUser['emails']['preferred'] <> '') { $email = $arLiveIDUser['emails']['preferred']; $login = $arLiveIDUser['emails']['preferred']; $uId = $arLiveIDUser['emails']['preferred']; } $arFields = array( 'EXTERNAL_AUTH_ID' => self::ID, 'XML_ID' => $uId, 'LOGIN' => $login, 'EMAIL' => $email, 'NAME'=> $first_name, 'LAST_NAME'=> $last_name, ); $arFields["PERSONAL_WWW"] = $arLiveIDUser["link"]; $bSuccess = $this->AuthorizeUser($arFields); } } } $url = ($GLOBALS["APPLICATION"]->GetCurDir() == "/login/") ? "/auth/" : $GLOBALS["APPLICATION"]->GetCurDir(); if(isset($_REQUEST["state"])) { $arState = array(); parse_str($_REQUEST["state"], $arState); if(isset($arState['backurl'])) $url = parse_url($arState['backurl'], PHP_URL_PATH); } if($bSuccess !== true) $url .= (strpos($url, '?') === false? '?':'&').'auth_service_id='.self::ID.'&auth_service_error='.$bSuccess; echo ' <script type="text/javascript"> if(window.opener) window.opener.location = \''.CUtil::JSEscape($url).'\'; window.close(); </script> '; die(); }
<?php global $DBType; define("SOCSERV_AUTHORISATION_ERROR", 1); define("SOCSERV_REGISTRATION_DENY", 2); define("SOCSERV_DEFAULT_HTTP_TIMEOUT", 10); $arClasses = array("CSocServAuthManager" => "classes/general/authmanager.php", "CSocServAuthDB" => "classes/" . $DBType . "/authmanager.php", "CSocServUtil" => "classes/general/authmanager.php", "CSocServAuth" => "classes/general/authmanager.php", "CSocServOAuthTransport" => "classes/general/oauthtransport.php", "CBitrix24NetOAuthInterface" => "classes/general/bitrix24net.php", "CSocServBitrix24Net" => "classes/general/bitrix24net.php", "CBitrix24NetTransport" => "classes/general/bitrix24net.php", "CSocServFacebook" => "classes/general/facebook.php", "CFacebookInterface" => "classes/general/facebook.php", "CSocServMyMailRu" => "classes/general/mailru.php", "CSocServOpenID" => "classes/general/openid.php", "CSocServYandex" => "classes/general/openid.php", "CSocServMailRu" => "classes/general/openid.php", "CSocServLivejournal" => "classes/general/openid.php", "CSocServLiveinternet" => "classes/general/openid.php", "CSocServBlogger" => "classes/general/openid.php", "CSocServTwitter" => "classes/general/twitter.php", "CTwitterInterface" => "classes/general/twitter.php", "CSocServVKontakte" => "classes/general/vkontakte.php", "CSocServGoogleOAuth" => "classes/general/google.php", "CGoogleOAuthInterface" => "classes/general/google.php", "CSocServGooglePlusOAuth" => "classes/general/googleplus.php", "CGooglePlusOAuthInterface" => "classes/general/googleplus.php", "CSocServLiveIDOAuth" => "classes/general/liveidoauth.php", "CSocServOdnoklassniki" => "classes/general/odnoklassniki.php", "COpenIDClient" => "classes/general/openidclient.php", "CSocServMessage" => "classes/" . $DBType . "/authmanager.php", "CSocServBitrixOAuth" => "classes/general/bitrix24.php", "CBitrixOAuthInterface" => "classes/general/bitrix24.php", "CBitrixPHPAppTransport" => "classes/general/bitrix24.php", "CSocServYandexAuth" => "classes/general/yandex.php", "CYandexOAuthInterface" => "classes/general/yandex.php", "CSocServDropboxAuth" => "classes/general/dropbox.php", "CSocServBoxAuth" => "classes/general/box.php", "CBoxOAuthInterface" => "classes/general/box.php", "CBitrixSeoOAuthInterface" => "classes/general/bitrixseo.php", "CBitrixSeoTransport" => "classes/general/bitrixseo.php"); CModule::AddAutoloadClasses("socialservices", $arClasses); $arJSDescription = array('js' => '/bitrix/js/socialservices/ss_timeman.js', 'css' => '/bitrix/js/socialservices/css/ss.css', 'rel' => array('popup', 'ajax', 'fx', 'ls', 'date', 'json'), 'lang' => '/bitrix/modules/socialservices/lang/' . LANGUAGE_ID . '/js_socialservices.php'); if (IsModuleInstalled("timeman")) { $userSocServEnable = CSocServAuthManager::GetCachedUserOption("user_socserv_enable"); if ($userSocServEnable != '') { $arJSDescription['lang_additional'] = array('IS_ENABLED' => $userSocServEnable); } } CJSCore::RegisterExt('socserv_timeman', $arJSDescription); class CSocServEventHandlers { function OnFillSocNetLogEvents(&$arSocNetLogEvents) { $arSocNetLogEvents["twitter"] = array("ENTITIES" => array(SONET_SUBSCRIBE_ENTITY_USER => array("OPERATION" => "viewprofile"), SONET_SUBSCRIBE_ENTITY_GROUP => array("OPERATION" => "viewsystemevents")), "CLASS_FORMAT" => "CSocServEventHandlers", "METHOD_FORMAT" => "FormatEvent_Data", "FULL_SET" => array("data", "data_comment"), "COMMENT_EVENT" => array("EVENT_ID" => "data_comment", "CLASS_FORMAT" => "CSocServEventHandlers", "METHOD_FORMAT" => "FormatComment_Data")); } function FormatEvent_Data($arFields, $arParams, $bMail = false) { $arResult = array("EVENT" => $arFields, "URL" => ""); if (!CModule::IncludeModule("socialnetwork")) { return $arResult; } if (in_array($arFields["ENTITY_TYPE"], array(SONET_SUBSCRIBE_ENTITY_GROUP, SONET_SUBSCRIBE_ENTITY_USER))) { $arResult["ENTITY"] = CSocNetLogTools::FormatEvent_GetEntity($arFields, $arParams, $bMail); $rsRight = CSocNetLogRights::GetList(array(), array("LOG_ID" => $arFields["ID"]));
public function Authorize() { global $APPLICATION; $APPLICATION->RestartBuffer(); $bSuccess = SOCSERV_AUTHORISATION_ERROR; $bProcessState = false; if (isset($_REQUEST["code"]) && $_REQUEST["code"] != '' && CSocServAuthManager::CheckUniqueKey()) { $bProcessState = true; if (IsModuleInstalled('bitrix24') && defined('BX24_HOST_NAME')) { $redirect_uri = self::CONTROLLER_URL . "/redirect.php"; } else { $redirect_uri = CSocServUtil::ServerName() . "/bitrix/tools/oauth/odnoklassniki.php"; } $appID = trim(self::GetOption("odnoklassniki_appid")); $appSecret = trim(self::GetOption("odnoklassniki_appsecret")); $appKey = trim(self::GetOption("odnoklassniki_appkey")); $gAuth = new COdnoklassnikiInterface($appID, $appSecret, $appKey, $_REQUEST["code"]); if ($gAuth->GetAccessToken($redirect_uri) !== false) { $arOdnoklUser = $gAuth->GetCurrentUser(); if (is_array($arOdnoklUser) && $arOdnoklUser['uid'] != '') { $uid = $arOdnoklUser['uid']; $first_name = $last_name = $gender = ""; if ($arOdnoklUser['first_name'] != '') { $first_name = $arOdnoklUser['first_name']; } if ($arOdnoklUser['last_name'] != '') { $last_name = $arOdnoklUser['last_name']; } if (isset($arOdnoklUser['gender']) && $arOdnoklUser['gender'] != '') { if ($arOdnoklUser['gender'] == 'male') { $gender = 'M'; } elseif ($arOdnoklUser['gender'] == 'female') { $gender = 'F'; } } $arFields = array('EXTERNAL_AUTH_ID' => self::ID, 'XML_ID' => "OK" . $uid, 'LOGIN' => "OKuser" . $uid, 'NAME' => $first_name, 'LAST_NAME' => $last_name, 'PERSONAL_GENDER' => $gender); if (isset($arOdnoklUser['birthday'])) { if ($date = MakeTimeStamp($arOdnoklUser['birthday'], "YYYY-MM-DD")) { $arFields["PERSONAL_BIRTHDAY"] = ConvertTimeStamp($date); } } if (isset($arOdnoklUser['pic_2']) && self::CheckPhotoURI($arOdnoklUser['pic_2'])) { if ($arPic = CFile::MakeFileArray($arOdnoklUser['pic_2'] . '&name=/' . md5($arOdnoklUser['pic_2']) . '.jpg')) { $arFields["PERSONAL_PHOTO"] = $arPic; } } $arFields["PERSONAL_WWW"] = "http://odnoklassniki.ru/profile/" . $uid; if (strlen(SITE_ID) > 0) { $arFields["SITE_ID"] = SITE_ID; } $bSuccess = $this->AuthorizeUser($arFields); } } } if (!$bProcessState) { unset($_REQUEST["state"]); } $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"); $mode = 'opener'; if (isset($_REQUEST["state"])) { $arState = array(); parse_str($_REQUEST["state"], $arState); if (isset($arState['backurl']) || isset($arState['redirect_url'])) { $parseUrl = parse_url(!empty($arState['redirect_url']) ? $arState['redirect_url'] : $arState['backurl']); $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 (isset($arState['mode'])) { $mode = $arState['mode']; } } if ($bSuccess === SOCSERV_REGISTRATION_DENY) { $url = preg_match("/\\?/", $url) ? $url . '&' : $url . '?'; $url .= 'auth_service_id=' . self::ID . '&auth_service_error=' . SOCSERV_REGISTRATION_DENY; } elseif ($bSuccess !== true) { $url = isset($parseUrl) ? $urlPath . '?auth_service_id=' . self::ID . '&auth_service_error=' . $bSuccess : $APPLICATION->GetCurPageParam('auth_service_id=' . self::ID . '&auth_service_error=' . $bSuccess, $aRemove); } if (CModule::IncludeModule("socialnetwork") && strpos($url, "current_fieldset=") === false) { $url = preg_match("/\\?/", $url) ? $url . "¤t_fieldset=SOCSERV" : $url . "?current_fieldset=SOCSERV"; } $url = CUtil::JSEscape($url); $location = $mode == "opener" ? 'if(window.opener) window.opener.location = \'' . $url . '\'; window.close();' : ' window.location = \'' . $url . '\';'; $JSScript = ' <script type="text/javascript"> ' . $location . ' </script> '; echo $JSScript; die; }
public function Authorize() { global $APPLICATION; $APPLICATION->RestartBuffer(); $authError = SOCSERV_AUTHORISATION_ERROR; if (isset($_REQUEST["code"]) && $_REQUEST["code"] != '' && CSocServAuthManager::CheckUniqueKey()) { $redirect_uri = CSocServUtil::ServerName() . '/bitrix/tools/oauth/bitrix24net.php'; if ($this->getEntityOAuth($_REQUEST["code"])->GetAccessToken($redirect_uri) !== false) { $arB24NetUser = $this->entityOAuth->GetCurrentUser(); if ($arB24NetUser) { if (isset($_REQUEST['checkword']) && $arB24NetUser['PROFILE_ID'] > 0) { $profileId = $arB24NetUser['PROFILE_ID']; $checkword = trim($_REQUEST['checkword']); $dbRes = CUser::getById($profileId); $arUser = $dbRes->fetch(); if ($arUser && !$arUser['LAST_LOGIN']) { if ($arUser['CONFIRM_CODE'] == $checkword) { $arUserFields = array('XML_ID' => $arB24NetUser['ID'], 'EXTERNAL_AUTH_ID' => 'socservices'); if ($arUser['NAME'] == '' && $arUser['LAST_NAME'] == '') { $arUserFields['NAME'] = $arB24NetUser['NAME']; $arUserFields['LAST_NAME'] = $arB24NetUser['LAST_NAME']; if (strlen($arB24NetUser['PERSONAL_PHOTO']) > 0 && self::CheckPhotoURI($arB24NetUser['PERSONAL_PHOTO'])) { $arUserFields['PERSONAL_PHOTO'] = CFile::MakeFileArray($arB24NetUser['PERSONAL_PHOTO']); } } $obUser = new CUser(); if ($obUser->update($profileId, $arUserFields)) { foreach (GetModuleEvents("main", "OnUserInitialize", true) as $arEvent) { ExecuteModuleEventEx($arEvent, array($profileId, $arUserFields)); } } } } } $arFields = array('EXTERNAL_AUTH_ID' => self::ID, 'XML_ID' => $arB24NetUser["ID"], 'LOGIN' => "B24_" . $arB24NetUser["ID"], 'NAME' => $arB24NetUser["NAME"], 'LAST_NAME' => $arB24NetUser["LAST_NAME"], 'EMAIL' => $arB24NetUser["EMAIL"], 'PERSONAL_WWW' => $arB24NetUser["PROFILE"], 'OATOKEN' => $this->entityOAuth->getToken(), 'REFRESH_TOKEN' => $this->entityOAuth->getRefreshToken(), 'OATOKEN_EXPIRES' => $this->entityOAuth->getAccessTokenExpires()); if (IsModuleInstalled('bitrix24')) { $arFields['LOGIN'] = $arFields['EMAIL']; } if (strlen(SITE_ID) > 0) { $arFields["SITE_ID"] = SITE_ID; } $authError = $this->AuthorizeUser($arFields); } } } $bSuccess = $authError === true; $aRemove = array("logout", "auth_service_error", "auth_service_id", "code", "error_reason", "error", "error_description", "check_key", "current_fieldset", "checkword"); $url = $APPLICATION->GetCurDir() == "/login/" ? "" : $APPLICATION->GetCurDir(); $mode = 'page'; if (isset($_REQUEST["state"])) { $arState = array(); parse_str($_REQUEST["state"], $arState); if (isset($arState['backurl']) || isset($arState['redirect_url'])) { $parseUrl = parse_url(isset($arState['redirect_url']) ? $arState['redirect_url'] : $arState['backurl']); $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 (isset($arState['mode'])) { $mode = $arState['mode']; } } if (strlen($url) <= 0 || preg_match("'^(http://|https://|ftp://|//)'i", $url)) { $url = CSocServUtil::ServerName() . '/'; } $url = CUtil::JSEscape($url); if ($bSuccess) { unset($_SESSION['B24_NETWORK_REDIRECT_TRY']); } else { if (IsModuleInstalled('bitrix24')) { if (isset($_SESSION['B24_NETWORK_REDIRECT_TRY'])) { unset($_SESSION['B24_NETWORK_REDIRECT_TRY']); $url = self::getUrl(); $url .= (strpos($url, '?') >= 0 ? '&' : '?') . 'skip_redirect=1'; } else { $_SESSION['B24_NETWORK_REDIRECT_TRY'] = true; $url = '/'; } } else { 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"; } $location = $mode == "popup" ? 'if(window.opener) window.opener.location = \'' . $url . '\'; window.close();' : 'window.location = \'' . $url . '\';'; ?> <script type="text/javascript"> <?php echo $location; ?> </script> <?php die; }