• Модуль: mail
  • Путь к файлу: ~/bitrix/modules/mail/lib/helper/oauth.php
  • Класс: BitrixMailHelperOAuth
  • Вызов: OAuth::getStoredToken
public function getStoredToken($uid = null)
{
	$token = null;

	if (!empty($uid))
	{
		$this->storedUid = $uid;
	}

	$item = $this->fetchStoredToken();

	if (!empty($item))
	{
		$this->oauthEntity->setToken($token = $item['TOKEN']);
		$this->oauthEntity->setRefreshToken($item['REFRESH_TOKEN']);

		if (empty($token) || $item['TOKEN_EXPIRES'] > 0 && $item['TOKEN_EXPIRES'] < time())
		{
			$this->oauthEntity->setToken(null);

			if (!empty($item['REFRESH_TOKEN']))
			{
				if ($this->oauthEntity->getNewAccessToken($item['REFRESH_TOKEN']))
				{
					$tokenData = $this->oauthEntity->getTokenData();

					MailInternalsOAuthTable::update(
						$item['ID'],
						array(
							'TOKEN' => $tokenData['access_token'],
							'REFRESH_TOKEN' => $tokenData['refresh_token'],
							'TOKEN_EXPIRES' => $tokenData['expires_in'],
						)
					);
				}
			}

			$token = $this->oauthEntity->getToken();
		}
	}

	return $token;
}