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() { $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; }