- Модуль: socialservices
- Путь к файлу: ~/bitrix/modules/socialservices/classes/general/vkontakte.php
- Класс: CVKontakteOAuthInterface
- Вызов: CVKontakteOAuthInterface::GetAccessToken
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,
);
$h = new BitrixMainWebHttpClient(array(
"socketTimeout" => $this->httpTimeout,
"streamTimeout" => $this->httpTimeout,
));
$result = $h->post(self::TOKEN_URL, $query);
try
{
$arResult = BitrixMainWebJson::decode($result);
} catch (BitrixMainArgumentException $e)
{
$arResult = array();
}
foreach ($arResult as $key => $value)
{
if (mb_strpos($key, 'access_token_') === 0)
{
$this->access_token = $value;
$this->userID = null;
$this->userEmail = null;
$_SESSION["OAUTH_DATA"] = array("OATOKEN" => $this->access_token);
return true;
}
}
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;
}