Esempio n. 1
0
 public function SendFeed($socServUserId, $message, $messageId)
 {
     $isSetOauthKeys = true;
     if (!$this->access_token || !$this->userId) {
         $isSetOauthKeys = self::SetOauthKeys($socServUserId);
     }
     if ($isSetOauthKeys === false) {
         CSocServMessage::Delete($messageId);
         return false;
     }
     $message = CharsetConverter::ConvertCharset($message, LANG_CHARSET, "utf-8");
     $arPost = array("access_token" => $this->access_token, "message" => $message);
     $result = @CHTTP::sPostHeader($this::GRAPH_URL . "/" . $this->userId . "/feed", $arPost, array(), $this->httpTimeout);
     if ($result !== false) {
         if (!defined("BX_UTF")) {
             $result = CharsetConverter::ConvertCharset($result, "utf-8", LANG_CHARSET);
         }
         return CUtil::JsObjectToPhp($result);
     } else {
         return false;
     }
 }
Esempio n. 2
0
 private function RefreshToken($socServUserId)
 {
     $result = CHTTP::sPostHeader(self::TOKEN_URL, array("refresh_token" => $this->refresh_token, "client_id" => $this->appID, "client_secret" => $this->appSecret, "grant_type" => "refresh_token"), array(), $this->httpTimeout);
     $arResult = CUtil::JsObjectToPhp($result);
     if (isset($arResult["access_token"]) && $arResult["access_token"] != '') {
         $this->access_token = $arResult["access_token"];
         CSocServAuthDB::Update($socServUserId, array("OATOKEN" => $arResult["access_token"]));
         return true;
     }
     return false;
 }
Esempio n. 3
0
 public function getNewAccessToken($refreshToken = false, $userId = 0, $save = false)
 {
     if ($this->appID == false || $this->appSecret == false) {
         return false;
     }
     if ($refreshToken == false) {
         $refreshToken = $this->refresh_token;
     }
     $result = CHTTP::sPostHeader(static::TOKEN_URL, array("refresh_token" => $refreshToken, "client_id" => $this->appID, "client_secret" => $this->appSecret, "grant_type" => "refresh_token"), array(), $this->httpTimeout);
     $this->arResult = CUtil::JsObjectToPhp($result);
     if (isset($this->arResult["access_token"]) && $this->arResult["access_token"] != '') {
         $this->access_token = $this->arResult["access_token"];
         $this->accessTokenExpires = $this->arResult["expires_in"] + time();
         if ($save && intval($userId) > 0) {
             $dbSocservUser = CSocServAuthDB::GetList(array(), array('USER_ID' => intval($userId), "EXTERNAL_AUTH_ID" => static::SERVICE_ID), false, false, array("ID"));
             if ($arOauth = $dbSocservUser->Fetch()) {
                 CSocServAuthDB::Update($arOauth["ID"], array("OATOKEN" => $this->access_token, "OATOKEN_EXPIRES" => $this->accessTokenExpires));
             }
         }
         return true;
     }
     return false;
 }
Esempio n. 4
0
	public function GetAccessToken()
	{
		if(($tokens = $this->getStorageTokens()) && is_array($tokens))
		{
			$this->access_token = $tokens["OATOKEN"];
			if($this->checkAccessToken())
			{
				return true;
			}
			elseif(isset($tokens["REFRESH_TOKEN"]))
			{
				if($this->getNewAccessToken($tokens["REFRESH_TOKEN"]))
				{
					return true;
				}
			}
		}

		if($this->code === false)
			return false;

		$result = CHTTP::sPostHeader(self::TOKEN_URL, array(
			"grant_type"=>"authorization_code",
			"code"=>$this->code,
			"client_id" => $this->appID,
		), array(
			"Authorization" => "Basic ".base64_encode($this->appID.':'.$this->appSecret)
		), $this->httpTimeout);

		echo $result;

		$this->arResult = CUtil::JsObjectToPhp($result);

		if(isset($this->arResult["access_token"]) && $this->arResult["access_token"] <> '')
		{
			// yandex doesn't send refresh tokens but I leave it here in case they will
			if(isset($this->arResult["refresh_token"]) && $this->arResult["refresh_token"] <> '')
			{
				$this->refresh_token = $this->arResult["refresh_token"];
			}
			$this->access_token = $this->arResult["access_token"];
			$this->accessTokenExpires = $this->arResult["expires_in"] + time();
			return true;
		}
		return false;
	}
Esempio n. 5
0
	public function GetAccessToken($redirect_uri)
	{
		if($this->code === false)
			return false;

		$result = CHTTP::sPostHeader(self::TOKEN_URL, array(
			"client_id"=>$this->appID,
			"client_secret"=>$this->appSecret,
			"code"=>$this->code,
			"redirect_uri"=>$redirect_uri,
		), array(), $this->httpTimeout);

		$arResult = CUtil::JsObjectToPhp($result);

		if((isset($arResult["access_token"]) && $arResult["access_token"] <> '') && isset($arResult["user_id"]) && $arResult["user_id"] <> '')
		{
			$this->access_token = $arResult["access_token"];
			$this->userID = $arResult["user_id"];
			$_SESSION["OAUTH_DATA"] = array("OATOKEN" => $this->access_token);
			return true;
		}
		return false;
	}
Esempio n. 6
0
 public function SendTwit($socServUserId, $message, $messageId)
 {
     $isSetOauthKeys = true;
     if (!$this->token || !$this->tokenSecret) {
         $isSetOauthKeys = self::SetOauthKeys($socServUserId);
     }
     if ($isSetOauthKeys === false) {
         CSocServMessage::Delete($messageId);
         return false;
     }
     if (strlen($message) > 139) {
         $message = substr($message, 0, 137) . "...";
     }
     if (!defined("BX_UTF")) {
         $message = CharsetConverter::ConvertCharset($message, LANG_CHARSET, "utf-8");
     }
     $arParams = array_merge($this->GetDefParams(), array("oauth_token" => $this->token, "status" => $message));
     $arParams["oauth_signature"] = urlencode($this->BuildSignature($this->GetSignatureString($arParams, $this::POST_URL)));
     $arHeaders = array("Authorization" => 'OAuth oauth_consumer_key="' . $arParams["oauth_consumer_key"] . '", oauth_nonce="' . $arParams["oauth_nonce"] . '", oauth_signature="' . $arParams["oauth_signature"] . '", oauth_signature_method="HMAC-SHA1", oauth_timestamp="' . $arParams["oauth_timestamp"] . '", oauth_token="' . $this->token . '", oauth_version="1.0"');
     $arPost = array("status" => $message);
     $result = @CHTTP::sPostHeader($this::POST_URL, $arPost, $arHeaders, $this->httpTimeout);
     if ($result !== false) {
         if (!defined("BX_UTF")) {
             $result = CharsetConverter::ConvertCharset($result, "utf-8", LANG_CHARSET);
         }
         return CUtil::JsObjectToPhp($result);
     } else {
         return false;
     }
 }
Esempio n. 7
0
 public function GetAccessToken($redirect_uri)
 {
     $token = $this->getStorageTokens();
     if (is_array($token)) {
         $this->access_token = $token["OATOKEN"];
         return true;
     }
     if ($this->code === false) {
         return false;
     }
     $query = array("client_id" => $this->appID, "client_secret" => $this->appSecret, "code" => $this->code, "redirect_uri" => $redirect_uri);
     $result = CHTTP::sPostHeader(self::TOKEN_URL, $query, array(), $this->httpTimeout);
     $arResult = CUtil::JsObjectToPhp($result);
     if (isset($arResult["access_token"]) && $arResult["access_token"] != '' && isset($arResult["user_id"]) && $arResult["user_id"] != '') {
         $this->access_token = $arResult["access_token"];
         $this->userID = $arResult["user_id"];
         $this->userEmail = $arResult["email"];
         $_SESSION["OAUTH_DATA"] = array("OATOKEN" => $this->access_token);
         return true;
     }
     return false;
 }
Esempio n. 8
0
 public function GetAccessToken($redirect_uri)
 {
     if ($this->code === false) {
         return false;
     }
     $result = CHTTP::sPostHeader(self::TOKEN_URL, array("code" => $this->code, "client_id" => $this->appID, "client_secret" => $this->appSecret, "redirect_uri" => $redirect_uri, "grant_type" => "authorization_code"), array(), $this->httpTimeout);
     $arResult = CUtil::JsObjectToPhp($result);
     if (isset($arResult["access_token"]) && $arResult["access_token"] != '') {
         $this->access_token = $arResult["access_token"];
         return true;
     }
     return false;
 }